aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-11 02:59:26 +0000
committerMelanie Thielker2009-05-11 02:59:26 +0000
commit461e213a39f907dda30f5f1b8437178bc99ef55f (patch)
treeff0994bd8cfce33bc5928aaddc37ef9df9aba7ed /OpenSim
parentAdd the HG asset module skeleton (diff)
downloadopensim-SC-461e213a39f907dda30f5f1b8437178bc99ef55f.zip
opensim-SC-461e213a39f907dda30f5f1b8437178bc99ef55f.tar.gz
opensim-SC-461e213a39f907dda30f5f1b8437178bc99ef55f.tar.bz2
opensim-SC-461e213a39f907dda30f5f1b8437178bc99ef55f.tar.xz
Plumb the HG asset broker. More naming changes to clarify things. Lots more
config options.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml1
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetBroker.cs320
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs4
-rw-r--r--OpenSim/Services/AssetService/AssetService.cs2
-rw-r--r--OpenSim/Services/AssetService/HGAssetService.cs (renamed from OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetServiceConnector.cs)74
5 files changed, 333 insertions, 68 deletions
diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
index b3a9c98..43c5a58 100644
--- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
+++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
@@ -15,6 +15,7 @@
15 <RegionModule id="RemoteUserServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectors.User.RemoteUserServicesConnector" /> 15 <RegionModule id="RemoteUserServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectors.User.RemoteUserServicesConnector" />
16 <RegionModule id="LocalAssetServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectors.Asset.LocalAssetServicesConnector" /> 16 <RegionModule id="LocalAssetServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectors.Asset.LocalAssetServicesConnector" />
17 <RegionModule id="RemoteAssetServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectors.Asset.RemoteAssetServicesConnector" /> 17 <RegionModule id="RemoteAssetServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectors.Asset.RemoteAssetServicesConnector" />
18 <RegionModule id="HGAssetBroker" type="OpenSim.Region.CoreModules.ServiceConnectors.Asset.HGAssetBroker" />
18 </Extension> 19 </Extension>
19 20
20 <Extension path = "/OpenSim/WindModule"> 21 <Extension path = "/OpenSim/WindModule">
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetBroker.cs
new file mode 100644
index 0000000..37589fa
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetBroker.cs
@@ -0,0 +1,320 @@
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 OpenSim 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.Servers.Base;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Services.Interfaces;
38
39namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
40{
41 public class HGAssetBroker :
42 ISharedRegionModule, IAssetService
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47
48 private IImprovedAssetCache m_Cache = null;
49 private IAssetService m_LocalService;
50 private IAssetService m_HGService;
51
52 private bool m_Enabled = false;
53
54 public string Name
55 {
56 get { return "HGAssetBroker"; }
57 }
58
59 public void Initialise(IConfigSource source)
60 {
61 IConfig moduleConfig = source.Configs["Modules"];
62 if (moduleConfig != null)
63 {
64 string name = moduleConfig.GetString("AssetServices", "");
65 if (name == Name)
66 {
67 IConfig assetConfig = source.Configs["AssetService"];
68 if (assetConfig == null)
69 {
70 m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini");
71 return;
72 }
73
74 string localDll = assetConfig.GetString("LocalModule",
75 String.Empty);
76 string HGDll = assetConfig.GetString("HypergridModule",
77 String.Empty);
78
79 if (localDll == String.Empty)
80 {
81 m_log.Error("[ASSET CONNECTOR]: No LocalModule named in section AssetService");
82 return;
83 }
84
85 if (HGDll == String.Empty)
86 {
87 m_log.Error("[ASSET CONNECTOR]: No HypergridModule named in section AssetService");
88 return;
89 }
90
91 Object[] args = new Object[] { source };
92 m_LocalService =
93 ServerUtils.LoadPlugin<IAssetService>(localDll,
94 args);
95
96 m_HGService =
97 ServerUtils.LoadPlugin<IAssetService>(HGDll,
98 args);
99
100 if (m_LocalService == null)
101 {
102 m_log.Error("[ASSET CONNECTOR]: Can't load local asset service");
103 return;
104 }
105 if (m_HGService == null)
106 {
107 m_log.Error("[ASSET CONNECTOR]: Can't load hypergrid asset service");
108 return;
109 }
110
111 m_Enabled = true;
112 m_log.Info("[ASSET CONNECTOR]: HG asset broker enabled");
113 }
114 }
115 }
116
117 public void PostInitialise()
118 {
119 }
120
121 public void Close()
122 {
123 }
124
125 public void AddRegion(Scene scene)
126 {
127 if (!m_Enabled)
128 return;
129
130 scene.RegisterModuleInterface<IAssetService>(this);
131 }
132
133 public void RemoveRegion(Scene scene)
134 {
135 }
136
137 public void RegionLoaded(Scene scene)
138 {
139 if (!m_Enabled)
140 return;
141
142 if (m_Cache == null)
143 {
144 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
145
146 if (!(m_Cache is ISharedRegionModule))
147 m_Cache = null;
148 }
149
150 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled hypergrid asset broker for region {0}", scene.RegionInfo.RegionName);
151
152 if (m_Cache != null)
153 {
154 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
155 }
156 }
157
158 private bool IsHG(string id)
159 {
160 Uri assetUri;
161
162 if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) &&
163 assetUri.Scheme == Uri.UriSchemeHttp)
164 return true;
165
166 return false;
167 }
168
169 public AssetBase Get(string id)
170 {
171 AssetBase asset = null;
172
173 if (m_Cache != null)
174 {
175 m_Cache.Get(id);
176
177 if (asset != null)
178 return asset;
179 }
180
181 if (IsHG(id))
182 asset = m_HGService.Get(id);
183 else
184 asset = m_LocalService.Get(id);
185
186 if (asset != null)
187 {
188 if (m_Cache != null)
189 m_Cache.Cache(asset);
190 }
191
192 return asset;
193 }
194
195 public AssetMetadata GetMetadata(string id)
196 {
197 AssetBase asset = null;
198
199 if (m_Cache != null)
200 {
201 if (m_Cache != null)
202 m_Cache.Get(id);
203
204 if (asset != null)
205 return asset.Metadata;
206 }
207
208 AssetMetadata metadata;
209
210 if (IsHG(id))
211 metadata = m_HGService.GetMetadata(id);
212 else
213 metadata = m_LocalService.GetMetadata(id);
214
215 return metadata;
216 }
217
218 public byte[] GetData(string id)
219 {
220 AssetBase asset = null;
221
222 if (m_Cache != null)
223 {
224 if (m_Cache != null)
225 m_Cache.Get(id);
226
227 if (asset != null)
228 return asset.Data;
229 }
230
231 if (IsHG(id))
232 asset = m_HGService.Get(id);
233 else
234 asset = m_LocalService.Get(id);
235
236 if (asset != null)
237 {
238 if (m_Cache != null)
239 m_Cache.Cache(asset);
240 return asset.Data;
241 }
242
243 return null;
244 }
245
246 public bool Get(string id, Object sender, AssetRetrieved handler)
247 {
248 AssetBase asset = null;
249
250 if (m_Cache != null)
251 asset = m_Cache.Get(id);
252
253 if (asset != null)
254 {
255 handler(id, sender, asset);
256 return true;
257 }
258
259 if (IsHG(id))
260 {
261 return m_HGService.Get(id, sender, delegate (string assetID, Object s, AssetBase a)
262 {
263 if (a != null && m_Cache != null)
264 m_Cache.Cache(a);
265 handler(assetID, s, a);
266 });
267 }
268 else
269 {
270 return m_LocalService.Get(id, sender, delegate (string assetID, Object s, AssetBase a)
271 {
272 if (a != null && m_Cache != null)
273 m_Cache.Cache(a);
274 handler(assetID, s, a);
275 });
276 }
277 }
278
279 public string Store(AssetBase asset)
280 {
281 if (m_Cache != null)
282 m_Cache.Cache(asset);
283
284 if (IsHG(asset.ID))
285 return m_HGService.Store(asset);
286 else
287 return m_LocalService.Store(asset);
288 }
289
290 public bool UpdateContent(string id, byte[] data)
291 {
292 AssetBase asset = null;
293
294 if (m_Cache != null)
295 asset = m_Cache.Get(id);
296
297 if (asset != null)
298 {
299 asset.Data = data;
300 m_Cache.Cache(asset);
301 }
302
303 if (IsHG(id))
304 return m_HGService.UpdateContent(id, data);
305 else
306 return m_LocalService.UpdateContent(id, data);
307 }
308
309 public bool Delete(string id)
310 {
311 if (m_Cache != null)
312 m_Cache.Expire(id);
313
314 if (IsHG(id))
315 return m_HGService.Delete(id);
316 else
317 return m_LocalService.Delete(id);
318 }
319 }
320}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
index 6f0a7f8..1aaf552 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
@@ -71,12 +71,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
71 return; 71 return;
72 } 72 }
73 73
74 string serviceDll = assetConfig.GetString("Module", 74 string serviceDll = assetConfig.GetString("LocalServiceModule",
75 String.Empty); 75 String.Empty);
76 76
77 if (serviceDll == String.Empty) 77 if (serviceDll == String.Empty)
78 { 78 {
79 m_log.Error("[ASSET CONNECTOR]: No ServiceDll named in section AssetService"); 79 m_log.Error("[ASSET CONNECTOR]: No LocalServiceModule named in section AssetService");
80 return; 80 return;
81 } 81 }
82 82
diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs
index 1e038d4..bc6d752 100644
--- a/OpenSim/Services/AssetService/AssetService.cs
+++ b/OpenSim/Services/AssetService/AssetService.cs
@@ -59,6 +59,8 @@ namespace OpenSim.Services.AssetService
59 { 59 {
60 Store(a); 60 Store(a);
61 }); 61 });
62
63 m_log.Info("[ASSET CONNECTOR]: Local asset service enabled");
62 } 64 }
63 } 65 }
64 66
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetServiceConnector.cs b/OpenSim/Services/AssetService/HGAssetService.cs
index 58cc134..7415427 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/HGAssetServiceConnector.cs
+++ b/OpenSim/Services/AssetService/HGAssetService.cs
@@ -28,91 +28,33 @@
28using log4net; 28using log4net;
29using Nini.Config; 29using Nini.Config;
30using System; 30using System;
31using System.Collections.Generic;
32using System.Reflection; 31using System.Reflection;
33using OpenSim.Framework; 32using OpenSim.Framework;
34using OpenSim.Servers.Base;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Services.Interfaces; 33using OpenSim.Services.Interfaces;
38 34
39namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset 35namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
40{ 36{
41 public class HGAssetServicesConnector : 37 public class HGAssetService : IAssetService
42 ISharedRegionModule, IAssetService
43 { 38 {
44 private static readonly ILog m_log = 39 private static readonly ILog m_log =
45 LogManager.GetLogger( 40 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType); 41 MethodBase.GetCurrentMethod().DeclaringType);
47 42
48 private IImprovedAssetCache m_Cache = null; 43 public HGAssetService(IConfigSource source)
49
50 private bool m_Enabled = false;
51
52 public string Name
53 {
54 get { return "HGAssetServicesConnector"; }
55 }
56
57 public void Initialise(IConfigSource source)
58 { 44 {
59 IConfig moduleConfig = source.Configs["Modules"]; 45 IConfig moduleConfig = source.Configs["Modules"];
60 if (moduleConfig != null) 46 if (moduleConfig != null)
61 { 47 {
62 string name = moduleConfig.GetString("AssetServices", ""); 48 string name = moduleConfig.GetString("AssetServices", "");
63 if (name == Name)
64 {
65 IConfig assetConfig = source.Configs["AssetService"];
66 if (assetConfig == null)
67 {
68 m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini");
69 return;
70 }
71 49
72 m_Enabled = true; 50 IConfig assetConfig = source.Configs["AssetService"];
73 m_log.Info("[ASSET CONNECTOR]: HG asset connector enabled"); 51 if (assetConfig == null)
52 {
53 m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini");
54 return;
74 } 55 }
75 }
76 }
77
78 public void PostInitialise()
79 {
80 }
81
82 public void Close()
83 {
84 }
85 56
86 public void AddRegion(Scene scene) 57 m_log.Info("[ASSET CONNECTOR]: HG asset service enabled");
87 {
88 if (!m_Enabled)
89 return;
90
91 scene.RegisterModuleInterface<IAssetService>(this);
92 }
93
94 public void RemoveRegion(Scene scene)
95 {
96 }
97
98 public void RegionLoaded(Scene scene)
99 {
100 if (!m_Enabled)
101 return;
102
103 if (m_Cache == null)
104 {
105 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
106
107 if (!(m_Cache is ISharedRegionModule))
108 m_Cache = null;
109 }
110
111 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName);
112
113 if (m_Cache != null)
114 {
115 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
116 } 58 }
117 } 59 }
118 60