aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
diff options
context:
space:
mode:
authordiva2009-06-14 19:44:56 +0000
committerdiva2009-06-14 19:44:56 +0000
commit6abffedab5646c0c9d76a308cb9d7a722613fe14 (patch)
tree01f56713f19ed6157f496fd7ff86086e63e18d55 /OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
parentThank you kindly, M1sha, for a patch that improves the treePopulator module: (diff)
downloadopensim-SC_OLD-6abffedab5646c0c9d76a308cb9d7a722613fe14.zip
opensim-SC_OLD-6abffedab5646c0c9d76a308cb9d7a722613fe14.tar.gz
opensim-SC_OLD-6abffedab5646c0c9d76a308cb9d7a722613fe14.tar.bz2
opensim-SC_OLD-6abffedab5646c0c9d76a308cb9d7a722613fe14.tar.xz
Renamed Region/CoreModules/ServiceConnectors to Region/CoreModules/ServiceConnectorsOut. No functional changes.
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs343
1 files changed, 343 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
new file mode 100644
index 0000000..a9e9dc2
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
@@ -0,0 +1,343 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using log4net;
29using Nini.Config;
30using System;
31using System.Collections.Generic;
32using System.Reflection;
33using OpenSim.Framework;
34using OpenSim.Server.Base;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Services.Interfaces;
38using OpenMetaverse;
39
40namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
41{
42 public class HGAssetBroker :
43 ISharedRegionModule, IAssetService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 private IImprovedAssetCache m_Cache = null;
50 private IAssetService m_GridService;
51 private IAssetService m_HGService;
52
53 private bool m_Enabled = false;
54
55 public string Name
56 {
57 get { return "HGAssetBroker"; }
58 }
59
60 public void Initialise(IConfigSource source)
61 {
62 IConfig moduleConfig = source.Configs["Modules"];
63 if (moduleConfig != null)
64 {
65 string name = moduleConfig.GetString("AssetServices", "");
66 if (name == Name)
67 {
68 IConfig assetConfig = source.Configs["AssetService"];
69 if (assetConfig == null)
70 {
71 m_log.Error("[HG ASSET CONNECTOR]: AssetService missing from OpenSim.ini");
72 return;
73 }
74
75 string localDll = assetConfig.GetString("LocalGridAssetService",
76 String.Empty);
77 string HGDll = assetConfig.GetString("HypergridAssetService",
78 String.Empty);
79
80 if (localDll == String.Empty)
81 {
82 m_log.Error("[HG ASSET CONNECTOR]: No LocalGridAssetService named in section AssetService");
83 return;
84 }
85
86 if (HGDll == String.Empty)
87 {
88 m_log.Error("[HG ASSET CONNECTOR]: No HypergridAssetService named in section AssetService");
89 return;
90 }
91
92 Object[] args = new Object[] { source };
93 m_GridService =
94 ServerUtils.LoadPlugin<IAssetService>(localDll,
95 args);
96
97 m_HGService =
98 ServerUtils.LoadPlugin<IAssetService>(HGDll,
99 args);
100
101 if (m_GridService == null)
102 {
103 m_log.Error("[HG ASSET CONNECTOR]: Can't load local asset service");
104 return;
105 }
106 if (m_HGService == null)
107 {
108 m_log.Error("[HG ASSET CONNECTOR]: Can't load hypergrid asset service");
109 return;
110 }
111
112 m_Enabled = true;
113 m_log.Info("[HG ASSET CONNECTOR]: HG asset broker enabled");
114 }
115 }
116 }
117
118 public void PostInitialise()
119 {
120 }
121
122 public void Close()
123 {
124 }
125
126 public void AddRegion(Scene scene)
127 {
128 if (!m_Enabled)
129 return;
130
131 scene.RegisterModuleInterface<IAssetService>(this);
132 }
133
134 public void RemoveRegion(Scene scene)
135 {
136 }
137
138 public void RegionLoaded(Scene scene)
139 {
140 if (!m_Enabled)
141 return;
142
143 if (m_Cache == null)
144 {
145 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
146
147 if (!(m_Cache is ISharedRegionModule))
148 m_Cache = null;
149 }
150
151 m_log.InfoFormat("[HG ASSET CONNECTOR]: Enabled hypergrid asset broker for region {0}", scene.RegionInfo.RegionName);
152
153 if (m_Cache != null)
154 {
155 m_log.InfoFormat("[HG ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
156 }
157 }
158
159 private bool IsHG(string id)
160 {
161 Uri assetUri;
162
163 if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) &&
164 assetUri.Scheme == Uri.UriSchemeHttp)
165 return true;
166
167 return false;
168 }
169
170 public AssetBase Get(string id)
171 {
172 //m_log.DebugFormat("[HG ASSET CONNECTOR]: Get {0}", id);
173 AssetBase asset = null;
174
175 if (m_Cache != null)
176 {
177 asset = m_Cache.Get(id);
178
179 if (asset != null)
180 return asset;
181 }
182
183 if (IsHG(id))
184 {
185 asset = m_HGService.Get(id);
186 if (asset != null)
187 {
188 // Now store it locally
189 // For now, let me just do it for textures and scripts
190 if (((AssetType)asset.Type == AssetType.Texture) ||
191 ((AssetType)asset.Type == AssetType.LSLBytecode) ||
192 ((AssetType)asset.Type == AssetType.LSLText))
193 {
194 m_GridService.Store(asset);
195 }
196 }
197 }
198 else
199 asset = m_GridService.Get(id);
200
201 if (asset != null)
202 {
203 if (m_Cache != null)
204 m_Cache.Cache(asset);
205 }
206
207 return asset;
208 }
209
210 public AssetMetadata GetMetadata(string id)
211 {
212 AssetBase asset = null;
213
214 if (m_Cache != null)
215 {
216 if (m_Cache != null)
217 m_Cache.Get(id);
218
219 if (asset != null)
220 return asset.Metadata;
221 }
222
223 AssetMetadata metadata;
224
225 if (IsHG(id))
226 metadata = m_HGService.GetMetadata(id);
227 else
228 metadata = m_GridService.GetMetadata(id);
229
230 return metadata;
231 }
232
233 public byte[] GetData(string id)
234 {
235 AssetBase asset = null;
236
237 if (m_Cache != null)
238 {
239 if (m_Cache != null)
240 m_Cache.Get(id);
241
242 if (asset != null)
243 return asset.Data;
244 }
245
246 if (IsHG(id))
247 asset = m_HGService.Get(id);
248 else
249 asset = m_GridService.Get(id);
250
251 if (asset != null)
252 {
253 if (m_Cache != null)
254 m_Cache.Cache(asset);
255 return asset.Data;
256 }
257
258 return null;
259 }
260
261 public bool Get(string id, Object sender, AssetRetrieved handler)
262 {
263 AssetBase asset = null;
264
265 if (m_Cache != null)
266 asset = m_Cache.Get(id);
267
268 if (asset != null)
269 {
270 handler.BeginInvoke(id, sender, asset, null, null);
271 return true;
272 }
273
274 if (IsHG(id))
275 {
276 return m_HGService.Get(id, sender, delegate (string assetID, Object s, AssetBase a)
277 {
278 if (a != null && m_Cache != null)
279 m_Cache.Cache(a);
280 handler(assetID, s, a);
281 });
282 }
283 else
284 {
285 return m_GridService.Get(id, sender, delegate (string assetID, Object s, AssetBase a)
286 {
287 if (a != null && m_Cache != null)
288 m_Cache.Cache(a);
289 handler(assetID, s, a);
290 });
291 }
292 }
293
294 public string Store(AssetBase asset)
295 {
296 bool isHG = IsHG(asset.ID);
297
298 if ((m_Cache != null) && !isHG)
299 // Don't store it in the cache if the asset is to
300 // be sent to the other grid, because this is already
301 // a copy of the local asset.
302 m_Cache.Cache(asset);
303
304 if (asset.Temporary || asset.Local)
305 return asset.ID;
306
307 if (IsHG(asset.ID))
308 return m_HGService.Store(asset);
309 else
310 return m_GridService.Store(asset);
311 }
312
313 public bool UpdateContent(string id, byte[] data)
314 {
315 AssetBase asset = null;
316
317 if (m_Cache != null)
318 asset = m_Cache.Get(id);
319
320 if (asset != null)
321 {
322 asset.Data = data;
323 m_Cache.Cache(asset);
324 }
325
326 if (IsHG(id))
327 return m_HGService.UpdateContent(id, data);
328 else
329 return m_GridService.UpdateContent(id, data);
330 }
331
332 public bool Delete(string id)
333 {
334 if (m_Cache != null)
335 m_Cache.Expire(id);
336
337 if (IsHG(id))
338 return m_HGService.Delete(id);
339 else
340 return m_GridService.Delete(id);
341 }
342 }
343}