diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset')
3 files changed, 726 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 | |||
28 | using log4net; | ||
29 | using Nini.Config; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace 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 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs new file mode 100644 index 0000000..13c4b52 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs | |||
@@ -0,0 +1,256 @@ | |||
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 | |||
28 | using log4net; | ||
29 | using Nini.Config; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | |||
39 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | ||
40 | { | ||
41 | public class LocalAssetServicesConnector : | ||
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 | |||
50 | private IAssetService m_AssetService; | ||
51 | |||
52 | private bool m_Enabled = false; | ||
53 | |||
54 | public string Name | ||
55 | { | ||
56 | get { return "LocalAssetServicesConnector"; } | ||
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 OpenSim.ini"); | ||
71 | return; | ||
72 | } | ||
73 | |||
74 | string serviceDll = assetConfig.GetString("LocalServiceModule", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceDll == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[ASSET CONNECTOR]: No LocalServiceModule named in section AssetService"); | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | Object[] args = new Object[] { source }; | ||
84 | m_AssetService = | ||
85 | ServerUtils.LoadPlugin<IAssetService>(serviceDll, | ||
86 | args); | ||
87 | |||
88 | if (m_AssetService == null) | ||
89 | { | ||
90 | m_log.Error("[ASSET CONNECTOR]: Can't load asset service"); | ||
91 | return; | ||
92 | } | ||
93 | m_Enabled = true; | ||
94 | m_log.Info("[ASSET CONNECTOR]: Local asset connector enabled"); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public void PostInitialise() | ||
100 | { | ||
101 | } | ||
102 | |||
103 | public void Close() | ||
104 | { | ||
105 | } | ||
106 | |||
107 | public void AddRegion(Scene scene) | ||
108 | { | ||
109 | if (!m_Enabled) | ||
110 | return; | ||
111 | |||
112 | scene.RegisterModuleInterface<IAssetService>(this); | ||
113 | } | ||
114 | |||
115 | public void RemoveRegion(Scene scene) | ||
116 | { | ||
117 | } | ||
118 | |||
119 | public void RegionLoaded(Scene scene) | ||
120 | { | ||
121 | if (!m_Enabled) | ||
122 | return; | ||
123 | |||
124 | if (m_Cache == null) | ||
125 | { | ||
126 | m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>(); | ||
127 | |||
128 | if (!(m_Cache is ISharedRegionModule)) | ||
129 | m_Cache = null; | ||
130 | } | ||
131 | |||
132 | m_log.InfoFormat("[ASSET CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName); | ||
133 | |||
134 | if (m_Cache != null) | ||
135 | { | ||
136 | m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | // Short-circuit directly to storage layer | ||
141 | // | ||
142 | scene.UnregisterModuleInterface<IAssetService>(this); | ||
143 | scene.RegisterModuleInterface<IAssetService>(m_AssetService); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | public AssetBase Get(string id) | ||
148 | { | ||
149 | AssetBase asset = null; | ||
150 | if (m_Cache != null) | ||
151 | asset = m_Cache.Get(id); | ||
152 | |||
153 | if (asset == null) | ||
154 | { | ||
155 | asset = m_AssetService.Get(id); | ||
156 | if ((m_Cache != null) && (asset != null)) | ||
157 | m_Cache.Cache(asset); | ||
158 | } | ||
159 | return asset; | ||
160 | } | ||
161 | |||
162 | public AssetMetadata GetMetadata(string id) | ||
163 | { | ||
164 | AssetBase asset = null; | ||
165 | if (m_Cache != null) | ||
166 | asset = m_Cache.Get(id); | ||
167 | |||
168 | if (asset != null) | ||
169 | return asset.Metadata; | ||
170 | |||
171 | asset = m_AssetService.Get(id); | ||
172 | if (asset != null) | ||
173 | { | ||
174 | if (m_Cache != null) | ||
175 | m_Cache.Cache(asset); | ||
176 | return asset.Metadata; | ||
177 | } | ||
178 | |||
179 | return null; | ||
180 | } | ||
181 | |||
182 | public byte[] GetData(string id) | ||
183 | { | ||
184 | AssetBase asset = m_Cache.Get(id); | ||
185 | |||
186 | if (asset != null) | ||
187 | return asset.Data; | ||
188 | |||
189 | asset = m_AssetService.Get(id); | ||
190 | if (asset != null) | ||
191 | { | ||
192 | if (m_Cache != null) | ||
193 | m_Cache.Cache(asset); | ||
194 | return asset.Data; | ||
195 | } | ||
196 | |||
197 | return null; | ||
198 | } | ||
199 | |||
200 | public bool Get(string id, Object sender, AssetRetrieved handler) | ||
201 | { | ||
202 | AssetBase asset = null; | ||
203 | |||
204 | if (m_Cache != null) | ||
205 | m_Cache.Get(id); | ||
206 | |||
207 | if (asset != null) | ||
208 | { | ||
209 | handler.BeginInvoke(id, sender, asset, null, null); | ||
210 | return true; | ||
211 | } | ||
212 | |||
213 | return m_AssetService.Get(id, sender, delegate (string assetID, Object s, AssetBase a) | ||
214 | { | ||
215 | if ((a != null) && (m_Cache != null)) | ||
216 | m_Cache.Cache(a); | ||
217 | |||
218 | handler.BeginInvoke(assetID, s, a, null, null); | ||
219 | }); | ||
220 | } | ||
221 | |||
222 | public string Store(AssetBase asset) | ||
223 | { | ||
224 | if (m_Cache != null) | ||
225 | m_Cache.Cache(asset); | ||
226 | |||
227 | if (asset.Temporary || asset.Local) | ||
228 | return asset.ID; | ||
229 | |||
230 | return m_AssetService.Store(asset); | ||
231 | } | ||
232 | |||
233 | public bool UpdateContent(string id, byte[] data) | ||
234 | { | ||
235 | AssetBase asset = null; | ||
236 | if (m_Cache != null) | ||
237 | m_Cache.Get(id); | ||
238 | if (asset != null) | ||
239 | { | ||
240 | asset.Data = data; | ||
241 | if (m_Cache != null) | ||
242 | m_Cache.Cache(asset); | ||
243 | } | ||
244 | |||
245 | return m_AssetService.UpdateContent(id, data); | ||
246 | } | ||
247 | |||
248 | public bool Delete(string id) | ||
249 | { | ||
250 | if (m_Cache != null) | ||
251 | m_Cache.Expire(id); | ||
252 | |||
253 | return m_AssetService.Delete(id); | ||
254 | } | ||
255 | } | ||
256 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs new file mode 100644 index 0000000..e554c68 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs | |||
@@ -0,0 +1,127 @@ | |||
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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Services.Connectors; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | |||
39 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | ||
40 | { | ||
41 | public class RemoteAssetServicesConnector : | ||
42 | AssetServicesConnector, ISharedRegionModule, IAssetService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private bool m_Enabled = false; | ||
49 | private IImprovedAssetCache m_Cache; | ||
50 | |||
51 | public string Name | ||
52 | { | ||
53 | get { return "RemoteAssetServicesConnector"; } | ||
54 | } | ||
55 | |||
56 | public override void Initialise(IConfigSource source) | ||
57 | { | ||
58 | IConfig moduleConfig = source.Configs["Modules"]; | ||
59 | if (moduleConfig != null) | ||
60 | { | ||
61 | string name = moduleConfig.GetString("AssetServices", ""); | ||
62 | if (name == Name) | ||
63 | { | ||
64 | IConfig assetConfig = source.Configs["AssetService"]; | ||
65 | if (assetConfig == null) | ||
66 | { | ||
67 | m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini"); | ||
68 | return; | ||
69 | } | ||
70 | |||
71 | m_Enabled = true; | ||
72 | |||
73 | base.Initialise(source); | ||
74 | |||
75 | m_log.Info("[ASSET CONNECTOR]: Remote assets enabled"); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | public void PostInitialise() | ||
81 | { | ||
82 | } | ||
83 | |||
84 | public void Close() | ||
85 | { | ||
86 | } | ||
87 | |||
88 | public void AddRegion(Scene scene) | ||
89 | { | ||
90 | if (!m_Enabled) | ||
91 | return; | ||
92 | |||
93 | scene.RegisterModuleInterface<IAssetService>(this); | ||
94 | } | ||
95 | |||
96 | public void RemoveRegion(Scene scene) | ||
97 | { | ||
98 | } | ||
99 | |||
100 | public void RegionLoaded(Scene scene) | ||
101 | { | ||
102 | if (!m_Enabled) | ||
103 | return; | ||
104 | |||
105 | if (m_Cache == null) | ||
106 | { | ||
107 | m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>(); | ||
108 | |||
109 | // Since we are a shared module and scene data is not | ||
110 | // available for every method, the cache must be shared, too | ||
111 | // | ||
112 | if (!(m_Cache is ISharedRegionModule)) | ||
113 | m_Cache = null; | ||
114 | else | ||
115 | SetCache(m_Cache); | ||
116 | |||
117 | } | ||
118 | |||
119 | m_log.InfoFormat("[ASSET CONNECTOR]: Enabled remote assets for region {0}", scene.RegionInfo.RegionName); | ||
120 | |||
121 | if (m_Cache != null) | ||
122 | { | ||
123 | m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||