aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/AssetServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetServer.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServer.cs312
1 files changed, 156 insertions, 156 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs
index b17f65a..22bdc5c 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServer.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs
@@ -1,157 +1,157 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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*/
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Threading; 31using System.Threading;
32using Db4objects.Db4o; 32using Db4objects.Db4o;
33using Db4objects.Db4o.Query; 33using Db4objects.Db4o.Query;
34using libsecondlife; 34using libsecondlife;
35using Nini.Config; 35using Nini.Config;
36using OpenSim.Framework.Communications.Cache; 36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Framework.Console; 37using OpenSim.Framework.Console;
38using OpenSim.Framework.Interfaces; 38using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Types; 39using OpenSim.Framework.Types;
40using OpenSim.Framework.Utilities; 40using OpenSim.Framework.Utilities;
41 41
42namespace OpenSim.Framework.Communications.Cache 42namespace OpenSim.Framework.Communications.Cache
43{ 43{
44 public class LocalAssetServer : AssetServerBase 44 public class LocalAssetServer : AssetServerBase
45 { 45 {
46 private IObjectContainer db; 46 private IObjectContainer db;
47 47
48 public LocalAssetServer() 48 public LocalAssetServer()
49 { 49 {
50 bool yapfile; 50 bool yapfile;
51 yapfile = File.Exists(Path.Combine(Util.dataDir(), "regionassets.yap")); 51 yapfile = File.Exists(Path.Combine(Util.dataDir(), "regionassets.yap"));
52 52
53 db = Db4oFactory.OpenFile(Path.Combine(Util.dataDir(), "regionassets.yap")); 53 db = Db4oFactory.OpenFile(Path.Combine(Util.dataDir(), "regionassets.yap"));
54 MainLog.Instance.Verbose("Db4 Asset database creation"); 54 MainLog.Instance.Verbose("Db4 Asset database creation");
55 55
56 if (!yapfile) 56 if (!yapfile)
57 { 57 {
58 SetUpAssetDatabase(); 58 SetUpAssetDatabase();
59 } 59 }
60 } 60 }
61 61
62 public void CreateAndCommitAsset(AssetBase asset) 62 public void CreateAndCommitAsset(AssetBase asset)
63 { 63 {
64 AssetStorage store = new AssetStorage(); 64 AssetStorage store = new AssetStorage();
65 store.Data = asset.Data; 65 store.Data = asset.Data;
66 store.Name = asset.Name; 66 store.Name = asset.Name;
67 store.UUID = asset.FullID; 67 store.UUID = asset.FullID;
68 db.Set(store); 68 db.Set(store);
69 db.Commit(); 69 db.Commit();
70 } 70 }
71 71
72 override public void Close() 72 override public void Close()
73 { 73 {
74 base.Close(); 74 base.Close();
75 75
76 if (db != null) 76 if (db != null)
77 { 77 {
78 MainLog.Instance.Verbose("Closing local asset server database"); 78 MainLog.Instance.Verbose("Closing local asset server database");
79 db.Close(); 79 db.Close();
80 } 80 }
81 } 81 }
82 82
83 override protected void RunRequests() 83 override protected void RunRequests()
84 { 84 {
85 while (true) 85 while (true)
86 { 86 {
87 byte[] idata = null; 87 byte[] idata = null;
88 bool found = false; 88 bool found = false;
89 AssetStorage foundAsset = null; 89 AssetStorage foundAsset = null;
90 ARequest req = this._assetRequests.Dequeue(); 90 ARequest req = this._assetRequests.Dequeue();
91 IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); 91 IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID));
92 if (result.Count > 0) 92 if (result.Count > 0)
93 { 93 {
94 foundAsset = (AssetStorage)result.Next(); 94 foundAsset = (AssetStorage)result.Next();
95 found = true; 95 found = true;
96 } 96 }
97 97
98 AssetBase asset = new AssetBase(); 98 AssetBase asset = new AssetBase();
99 if (found) 99 if (found)
100 { 100 {
101 asset.FullID = foundAsset.UUID; 101 asset.FullID = foundAsset.UUID;
102 asset.Type = foundAsset.Type; 102 asset.Type = foundAsset.Type;
103 asset.InvType = foundAsset.Type; 103 asset.InvType = foundAsset.Type;
104 asset.Name = foundAsset.Name; 104 asset.Name = foundAsset.Name;
105 idata = foundAsset.Data; 105 idata = foundAsset.Data;
106 asset.Data = idata; 106 asset.Data = idata;
107 _receiver.AssetReceived(asset, req.IsTexture); 107 _receiver.AssetReceived(asset, req.IsTexture);
108 } 108 }
109 else 109 else
110 { 110 {
111 //asset.FullID = ; 111 //asset.FullID = ;
112 _receiver.AssetNotFound(req.AssetID); 112 _receiver.AssetNotFound(req.AssetID);
113 } 113 }
114 114
115 } 115 }
116 116
117 } 117 }
118 118
119 override protected void StoreAsset(AssetBase asset) 119 override protected void StoreAsset(AssetBase asset)
120 { 120 {
121 AssetStorage store = new AssetStorage(); 121 AssetStorage store = new AssetStorage();
122 store.Data = asset.Data; 122 store.Data = asset.Data;
123 store.Name = asset.Name; 123 store.Name = asset.Name;
124 store.UUID = asset.FullID; 124 store.UUID = asset.FullID;
125 db.Set(store); 125 db.Set(store);
126 126
127 CommitAssets(); 127 CommitAssets();
128 } 128 }
129 129
130 protected override void CommitAssets() 130 protected override void CommitAssets()
131 { 131 {
132 db.Commit(); 132 db.Commit();
133 } 133 }
134 134
135 protected virtual void SetUpAssetDatabase() 135 protected virtual void SetUpAssetDatabase()
136 { 136 {
137 MainLog.Instance.Verbose("LOCAL ASSET SERVER", "Setting up asset database"); 137 MainLog.Instance.Verbose("LOCAL ASSET SERVER", "Setting up asset database");
138 138
139 ForEachDefaultAsset(StoreAsset); 139 ForEachDefaultAsset(StoreAsset);
140 ForEachXmlAsset(StoreAsset); 140 ForEachXmlAsset(StoreAsset);
141 } 141 }
142 } 142 }
143 143
144 public class AssetUUIDQuery : Predicate 144 public class AssetUUIDQuery : Predicate
145 { 145 {
146 private LLUUID _findID; 146 private LLUUID _findID;
147 147
148 public AssetUUIDQuery(LLUUID find) 148 public AssetUUIDQuery(LLUUID find)
149 { 149 {
150 _findID = find; 150 _findID = find;
151 } 151 }
152 public bool Match(AssetStorage asset) 152 public bool Match(AssetStorage asset)
153 { 153 {
154 return (asset.UUID == _findID); 154 return (asset.UUID == _findID);
155 } 155 }
156 } 156 }
157} \ No newline at end of file 157} \ No newline at end of file