diff options
author | lbsa71 | 2007-10-19 07:46:03 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-19 07:46:03 +0000 |
commit | 46700d3b7d5bd71d880b3cc0dd0e2d6edd701195 (patch) | |
tree | 7f2d7a8c71e288daaa2b9b6f4d6ed35b0ef54d21 /OpenSim/Framework/Communications/Cache/AssetServer.cs | |
parent | Fix for assetserver crashing (Thank you Chi11ken) (diff) | |
download | opensim-SC_OLD-46700d3b7d5bd71d880b3cc0dd0e2d6edd701195.zip opensim-SC_OLD-46700d3b7d5bd71d880b3cc0dd0e2d6edd701195.tar.gz opensim-SC_OLD-46700d3b7d5bd71d880b3cc0dd0e2d6edd701195.tar.bz2 opensim-SC_OLD-46700d3b7d5bd71d880b3cc0dd0e2d6edd701195.tar.xz |
* Total refactoring of Asset Server for massive win
* There is now a AssetServerBase
* lolcat in ur assets
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetServer.cs')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/AssetServer.cs | 501 |
1 files changed, 134 insertions, 367 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs index e5329ec..a374df2 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs | |||
@@ -24,370 +24,137 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.Collections.Generic; |
30 | using System.Threading; | 30 | using System.IO; |
31 | using Db4objects.Db4o; | 31 | using System.Threading; |
32 | using Db4objects.Db4o.Query; | 32 | using Db4objects.Db4o; |
33 | using libsecondlife; | 33 | using Db4objects.Db4o.Query; |
34 | using Nini.Config; | 34 | using libsecondlife; |
35 | using OpenSim.Framework.Console; | 35 | using Nini.Config; |
36 | using OpenSim.Framework.Interfaces; | 36 | using OpenSim.Framework.Communications.Cache; |
37 | using OpenSim.Framework.Types; | 37 | using OpenSim.Framework.Console; |
38 | using OpenSim.Framework.Utilities; | 38 | using OpenSim.Framework.Interfaces; |
39 | 39 | using OpenSim.Framework.Types; | |
40 | namespace OpenSim.Framework.Communications.Caches | 40 | using OpenSim.Framework.Utilities; |
41 | { | 41 | |
42 | 42 | namespace OpenSim.Framework.Communications.Cache | |
43 | public class LocalAssetServer : IAssetServer | 43 | { |
44 | { | 44 | public class LocalAssetServer : AssetServerBase |
45 | private IAssetReceiver _receiver; | 45 | { |
46 | private BlockingQueue<ARequest> _assetRequests; | 46 | private IObjectContainer db; |
47 | private IObjectContainer db; | 47 | |
48 | private Thread _localAssetServerThread; | 48 | public LocalAssetServer() |
49 | 49 | { | |
50 | public LocalAssetServer() | 50 | bool yapfile; |
51 | { | 51 | yapfile = File.Exists(Path.Combine(Util.dataDir(), "regionassets.yap")); |
52 | System.Console.WriteLine("Starting Db4o asset storage system"); | 52 | |
53 | bool yapfile; | 53 | db = Db4oFactory.OpenFile(Path.Combine(Util.dataDir(), "regionassets.yap")); |
54 | this._assetRequests = new BlockingQueue<ARequest>(); | 54 | MainLog.Instance.Verbose("Db4 Asset database creation"); |
55 | yapfile = File.Exists(Path.Combine(Util.dataDir(), "regionassets.yap")); | 55 | |
56 | 56 | if (!yapfile) | |
57 | MainLog.Instance.Verbose("Local Asset Server class created"); | 57 | { |
58 | db = Db4oFactory.OpenFile(Path.Combine(Util.dataDir(), "regionassets.yap")); | 58 | SetUpAssetDatabase(); |
59 | MainLog.Instance.Verbose("Db4 Asset database creation"); | 59 | } |
60 | 60 | ||
61 | if (!yapfile) | 61 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); |
62 | { | 62 | this._localAssetServerThread.IsBackground = true; |
63 | this.SetUpAssetDatabase(); | 63 | this._localAssetServerThread.Start(); |
64 | } | 64 | |
65 | 65 | } | |
66 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); | 66 | |
67 | this._localAssetServerThread.IsBackground = true; | 67 | public void CreateAndCommitAsset(AssetBase asset) |
68 | this._localAssetServerThread.Start(); | 68 | { |
69 | 69 | AssetStorage store = new AssetStorage(); | |
70 | } | 70 | store.Data = asset.Data; |
71 | 71 | store.Name = asset.Name; | |
72 | public void SetReceiver(IAssetReceiver receiver) | 72 | store.UUID = asset.FullID; |
73 | { | 73 | db.Set(store); |
74 | this._receiver = receiver; | 74 | db.Commit(); |
75 | } | 75 | } |
76 | 76 | ||
77 | public void FetchAsset(LLUUID assetID, bool isTexture) | 77 | override public void Close() |
78 | { | 78 | { |
79 | ARequest req = new ARequest(); | 79 | if (db != null) |
80 | req.AssetID = assetID; | 80 | { |
81 | req.IsTexture = isTexture; | 81 | MainLog.Instance.Verbose("Closing local asset server database"); |
82 | this._assetRequests.Enqueue(req); | 82 | db.Close(); |
83 | } | 83 | } |
84 | 84 | } | |
85 | public void UpdateAsset(AssetBase asset) | 85 | |
86 | { | 86 | private void RunRequests() |
87 | 87 | { | |
88 | } | 88 | while (true) |
89 | 89 | { | |
90 | public void CreateAsset(AssetBase asset) | 90 | byte[] idata = null; |
91 | { | 91 | bool found = false; |
92 | AssetStorage store = new AssetStorage(); | 92 | AssetStorage foundAsset = null; |
93 | store.Data = asset.Data; | 93 | ARequest req = this._assetRequests.Dequeue(); |
94 | store.Name = asset.Name; | 94 | IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); |
95 | store.UUID = asset.FullID; | 95 | if (result.Count > 0) |
96 | db.Set(store); | 96 | { |
97 | db.Commit(); | 97 | foundAsset = (AssetStorage)result.Next(); |
98 | } | 98 | found = true; |
99 | 99 | } | |
100 | public void SetServerInfo(string ServerUrl, string ServerKey) | 100 | |
101 | { | 101 | AssetBase asset = new AssetBase(); |
102 | 102 | if (found) | |
103 | } | 103 | { |
104 | public void Close() | 104 | asset.FullID = foundAsset.UUID; |
105 | { | 105 | asset.Type = foundAsset.Type; |
106 | if (db != null) | 106 | asset.InvType = foundAsset.Type; |
107 | { | 107 | asset.Name = foundAsset.Name; |
108 | MainLog.Instance.Verbose("Closing local asset server database"); | 108 | idata = foundAsset.Data; |
109 | db.Close(); | 109 | asset.Data = idata; |
110 | } | 110 | _receiver.AssetReceived(asset, req.IsTexture); |
111 | } | 111 | } |
112 | 112 | else | |
113 | private void RunRequests() | 113 | { |
114 | { | 114 | //asset.FullID = ; |
115 | while (true) | 115 | _receiver.AssetNotFound(req.AssetID); |
116 | { | 116 | } |
117 | byte[] idata = null; | 117 | |
118 | bool found = false; | 118 | } |
119 | AssetStorage foundAsset = null; | 119 | |
120 | ARequest req = this._assetRequests.Dequeue(); | 120 | } |
121 | IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); | 121 | |
122 | if (result.Count > 0) | 122 | override protected void StoreAsset(AssetBase asset) |
123 | { | 123 | { |
124 | foundAsset = (AssetStorage)result.Next(); | 124 | AssetStorage store = new AssetStorage(); |
125 | found = true; | 125 | store.Data = asset.Data; |
126 | } | 126 | store.Name = asset.Name; |
127 | 127 | store.UUID = asset.FullID; | |
128 | AssetBase asset = new AssetBase(); | 128 | db.Set(store); |
129 | if (found) | 129 | |
130 | { | 130 | CommitAssets(); |
131 | asset.FullID = foundAsset.UUID; | 131 | } |
132 | asset.Type = foundAsset.Type; | 132 | |
133 | asset.InvType = foundAsset.Type; | 133 | protected override void CommitAssets() |
134 | asset.Name = foundAsset.Name; | 134 | { |
135 | idata = foundAsset.Data; | 135 | db.Commit(); |
136 | asset.Data = idata; | 136 | } |
137 | _receiver.AssetReceived(asset, req.IsTexture); | 137 | |
138 | } | 138 | private void SetUpAssetDatabase() |
139 | else | 139 | { |
140 | { | 140 | MainLog.Instance.Verbose("LOCAL ASSET SERVER", "Setting up asset database"); |
141 | //asset.FullID = ; | 141 | |
142 | _receiver.AssetNotFound(req.AssetID); | 142 | ForEachDefaultAsset(this, StoreAsset); |
143 | } | 143 | ForEachXmlAsset(this, StoreAsset); |
144 | 144 | } | |
145 | } | 145 | } |
146 | 146 | ||
147 | } | 147 | public class AssetUUIDQuery : Predicate |
148 | 148 | { | |
149 | private void SetUpAssetDatabase() | 149 | private LLUUID _findID; |
150 | { | 150 | |
151 | MainLog.Instance.Verbose("Setting up asset database"); | 151 | public AssetUUIDQuery(LLUUID find) |
152 | 152 | { | |
153 | AssetBase Image = new AssetBase(); | 153 | _findID = find; |
154 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); | 154 | } |
155 | Image.Name = "Bricks"; | 155 | public bool Match(AssetStorage asset) |
156 | this.LoadAsset(Image, true, "bricks.jp2"); | 156 | { |
157 | AssetStorage store = new AssetStorage(); | 157 | return (asset.UUID == _findID); |
158 | store.Data = Image.Data; | 158 | } |
159 | store.Name = Image.Name; | 159 | } |
160 | store.UUID = Image.FullID; | 160 | } \ No newline at end of file |
161 | db.Set(store); | ||
162 | db.Commit(); | ||
163 | |||
164 | Image = new AssetBase(); | ||
165 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); | ||
166 | Image.Name = "Plywood"; | ||
167 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
168 | store = new AssetStorage(); | ||
169 | store.Data = Image.Data; | ||
170 | store.Name = Image.Name; | ||
171 | store.UUID = Image.FullID; | ||
172 | db.Set(store); | ||
173 | db.Commit(); | ||
174 | |||
175 | Image = new AssetBase(); | ||
176 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); | ||
177 | Image.Name = "Rocks"; | ||
178 | this.LoadAsset(Image, true, "rocks.jp2"); | ||
179 | store = new AssetStorage(); | ||
180 | store.Data = Image.Data; | ||
181 | store.Name = Image.Name; | ||
182 | store.UUID = Image.FullID; | ||
183 | db.Set(store); | ||
184 | db.Commit(); | ||
185 | |||
186 | Image = new AssetBase(); | ||
187 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); | ||
188 | Image.Name = "Granite"; | ||
189 | this.LoadAsset(Image, true, "granite.jp2"); | ||
190 | store = new AssetStorage(); | ||
191 | store.Data = Image.Data; | ||
192 | store.Name = Image.Name; | ||
193 | store.UUID = Image.FullID; | ||
194 | db.Set(store); | ||
195 | db.Commit(); | ||
196 | |||
197 | Image = new AssetBase(); | ||
198 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); | ||
199 | Image.Name = "Hardwood"; | ||
200 | this.LoadAsset(Image, true, "hardwood.jp2"); | ||
201 | store = new AssetStorage(); | ||
202 | store.Data = Image.Data; | ||
203 | store.Name = Image.Name; | ||
204 | store.UUID = Image.FullID; | ||
205 | db.Set(store); | ||
206 | db.Commit(); | ||
207 | |||
208 | Image = new AssetBase(); | ||
209 | Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); | ||
210 | Image.Name = "Prim Base Texture"; | ||
211 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
212 | store = new AssetStorage(); | ||
213 | store.Data = Image.Data; | ||
214 | store.Name = Image.Name; | ||
215 | store.UUID = Image.FullID; | ||
216 | db.Set(store); | ||
217 | db.Commit(); | ||
218 | |||
219 | Image = new AssetBase(); | ||
220 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); | ||
221 | Image.Name = "Map Base Texture"; | ||
222 | this.LoadAsset(Image, true, "map_base.jp2"); | ||
223 | store = new AssetStorage(); | ||
224 | store.Data = Image.Data; | ||
225 | store.Name = Image.Name; | ||
226 | store.UUID = Image.FullID; | ||
227 | db.Set(store); | ||
228 | db.Commit(); | ||
229 | |||
230 | Image = new AssetBase(); | ||
231 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); | ||
232 | Image.Name = "Map Texture"; | ||
233 | this.LoadAsset(Image, true, "map1.jp2"); | ||
234 | store = new AssetStorage(); | ||
235 | store.Data = Image.Data; | ||
236 | store.Name = Image.Name; | ||
237 | store.UUID = Image.FullID; | ||
238 | db.Set(store); | ||
239 | db.Commit(); | ||
240 | |||
241 | Image = new AssetBase(); | ||
242 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); | ||
243 | Image.Name = "Female Body Texture"; | ||
244 | this.LoadAsset(Image, true, "femalebody.jp2"); | ||
245 | store = new AssetStorage(); | ||
246 | store.Data = Image.Data; | ||
247 | store.Name = Image.Name; | ||
248 | store.UUID = Image.FullID; | ||
249 | db.Set(store); | ||
250 | db.Commit(); | ||
251 | |||
252 | Image = new AssetBase(); | ||
253 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); | ||
254 | Image.Name = "Female Bottom Texture"; | ||
255 | this.LoadAsset(Image, true, "femalebottom.jp2"); | ||
256 | store = new AssetStorage(); | ||
257 | store.Data = Image.Data; | ||
258 | store.Name = Image.Name; | ||
259 | store.UUID = Image.FullID; | ||
260 | db.Set(store); | ||
261 | db.Commit(); | ||
262 | |||
263 | Image = new AssetBase(); | ||
264 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); | ||
265 | Image.Name = "Female Face Texture"; | ||
266 | this.LoadAsset(Image, true, "femaleface.jp2"); | ||
267 | store = new AssetStorage(); | ||
268 | store.Data = Image.Data; | ||
269 | store.Name = Image.Name; | ||
270 | store.UUID = Image.FullID; | ||
271 | db.Set(store); | ||
272 | db.Commit(); | ||
273 | |||
274 | Image = new AssetBase(); | ||
275 | Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | ||
276 | Image.Name = "Skin"; | ||
277 | Image.Type = 13; | ||
278 | Image.InvType = 13; | ||
279 | this.LoadAsset(Image, false, "base_skin.dat"); | ||
280 | store = new AssetStorage(); | ||
281 | store.Data = Image.Data; | ||
282 | store.Name = Image.Name; | ||
283 | store.UUID = Image.FullID; | ||
284 | db.Set(store); | ||
285 | db.Commit(); | ||
286 | |||
287 | |||
288 | Image = new AssetBase(); | ||
289 | Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
290 | Image.Name = "Shape"; | ||
291 | Image.Type = 13; | ||
292 | Image.InvType = 13; | ||
293 | this.LoadAsset(Image, false, "base_shape.dat"); | ||
294 | store = new AssetStorage(); | ||
295 | store.Data = Image.Data; | ||
296 | store.Name = Image.Name; | ||
297 | store.UUID = Image.FullID; | ||
298 | db.Set(store); | ||
299 | db.Commit(); | ||
300 | |||
301 | Image = new AssetBase(); | ||
302 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); | ||
303 | Image.Name = "Shirt"; | ||
304 | Image.Type = 5; | ||
305 | Image.InvType = 18; | ||
306 | this.LoadAsset(Image, false, "newshirt.dat"); | ||
307 | store = new AssetStorage(); | ||
308 | store.Data = Image.Data; | ||
309 | store.Name = Image.Name; | ||
310 | store.UUID = Image.FullID; | ||
311 | db.Set(store); | ||
312 | db.Commit(); | ||
313 | |||
314 | Image = new AssetBase(); | ||
315 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); | ||
316 | Image.Name = "Shirt"; | ||
317 | Image.Type = 5; | ||
318 | Image.InvType = 18; | ||
319 | this.LoadAsset(Image, false, "newpants.dat"); | ||
320 | store = new AssetStorage(); | ||
321 | store.Data = Image.Data; | ||
322 | store.Name = Image.Name; | ||
323 | store.UUID = Image.FullID; | ||
324 | db.Set(store); | ||
325 | db.Commit(); | ||
326 | |||
327 | string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); | ||
328 | if (File.Exists(filePath)) | ||
329 | { | ||
330 | XmlConfigSource source = new XmlConfigSource(filePath); | ||
331 | ReadAssetDetails(source); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | protected void ReadAssetDetails(IConfigSource source) | ||
336 | { | ||
337 | AssetBase newAsset = null; | ||
338 | for (int i = 0; i < source.Configs.Count; i++) | ||
339 | { | ||
340 | newAsset = new AssetBase(); | ||
341 | newAsset.FullID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated())); | ||
342 | newAsset.Name = source.Configs[i].GetString("name", ""); | ||
343 | newAsset.Type = (sbyte)source.Configs[i].GetInt("assetType", 0); | ||
344 | newAsset.InvType = (sbyte)source.Configs[i].GetInt("inventoryType", 0); | ||
345 | string fileName = source.Configs[i].GetString("fileName", ""); | ||
346 | if (fileName != "") | ||
347 | { | ||
348 | this.LoadAsset(newAsset, false, fileName); | ||
349 | AssetStorage store = new AssetStorage(); | ||
350 | store.Data = newAsset.Data; | ||
351 | store.Name = newAsset.Name; | ||
352 | store.UUID = newAsset.FullID; | ||
353 | db.Set(store); | ||
354 | db.Commit(); | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | |||
359 | private void LoadAsset(AssetBase info, bool image, string filename) | ||
360 | { | ||
361 | //should request Asset from storage manager | ||
362 | //but for now read from file | ||
363 | |||
364 | string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; | ||
365 | string fileName = Path.Combine(dataPath, filename); | ||
366 | FileInfo fInfo = new FileInfo(fileName); | ||
367 | long numBytes = fInfo.Length; | ||
368 | FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); | ||
369 | byte[] idata = new byte[numBytes]; | ||
370 | BinaryReader br = new BinaryReader(fStream); | ||
371 | idata = br.ReadBytes((int)numBytes); | ||
372 | br.Close(); | ||
373 | fStream.Close(); | ||
374 | info.Data = idata; | ||
375 | //info.loaded=true; | ||
376 | } | ||
377 | } | ||
378 | public class AssetUUIDQuery : Predicate | ||
379 | { | ||
380 | private LLUUID _findID; | ||
381 | |||
382 | public AssetUUIDQuery(LLUUID find) | ||
383 | { | ||
384 | _findID = find; | ||
385 | } | ||
386 | public bool Match(AssetStorage asset) | ||
387 | { | ||
388 | return (asset.UUID == _findID); | ||
389 | } | ||
390 | } | ||
391 | |||
392 | } | ||
393 | |||