aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-14 06:18:18 +0000
committerMelanie Thielker2009-05-14 06:18:18 +0000
commitd843b897b20601f0ba32a6f88da31cf5ea88c2ba (patch)
treeb311ceed8ede25cd68edc6522e17e72343137fe1 /OpenSim/Region
parentSmall fix uncommenting something that got commented too much. (diff)
downloadopensim-SC_OLD-d843b897b20601f0ba32a6f88da31cf5ea88c2ba.zip
opensim-SC_OLD-d843b897b20601f0ba32a6f88da31cf5ea88c2ba.tar.gz
opensim-SC_OLD-d843b897b20601f0ba32a6f88da31cf5ea88c2ba.tar.bz2
opensim-SC_OLD-d843b897b20601f0ba32a6f88da31cf5ea88c2ba.tar.xz
Move the connector for the new asset server to a connectors project. Inherit
the region module version from this. This enables inter-server connections to reuse connetor code from region modules.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs193
-rw-r--r--OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs39
2 files changed, 9 insertions, 223 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
index 4e8b5d6..ec982e5 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
@@ -28,35 +28,32 @@
28using log4net; 28using log4net;
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO;
32using System.Reflection; 31using System.Reflection;
33using Nini.Config; 32using Nini.Config;
34using OpenSim.Framework; 33using OpenSim.Framework;
35using OpenSim.Framework.Servers.HttpServer; 34using OpenSim.Servers.Connectors;
36using OpenSim.Region.Framework.Interfaces; 35using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
39using OpenSim.Framework.Communications;
40 38
41namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset 39namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
42{ 40{
43 public class RemoteAssetServicesConnector : 41 public class RemoteAssetServicesConnector :
44 ISharedRegionModule, IAssetService 42 AssetServicesConnector, ISharedRegionModule, IAssetService
45 { 43 {
46 private static readonly ILog m_log = 44 private static readonly ILog m_log =
47 LogManager.GetLogger( 45 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType); 46 MethodBase.GetCurrentMethod().DeclaringType);
49 47
50 private bool m_Enabled = false; 48 private bool m_Enabled = false;
51 private string m_ServerURI = String.Empty; 49 private IImprovedAssetCache m_Cache;
52 private IImprovedAssetCache m_Cache = null;
53 50
54 public string Name 51 public string Name
55 { 52 {
56 get { return "RemoteAssetServicesConnector"; } 53 get { return "RemoteAssetServicesConnector"; }
57 } 54 }
58 55
59 public void Initialise(IConfigSource source) 56 public override void Initialise(IConfigSource source)
60 { 57 {
61 IConfig moduleConfig = source.Configs["Modules"]; 58 IConfig moduleConfig = source.Configs["Modules"];
62 if (moduleConfig != null) 59 if (moduleConfig != null)
@@ -71,16 +68,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
71 return; 68 return;
72 } 69 }
73 70
74 string serviceURI = assetConfig.GetString("AssetServerURI",
75 String.Empty);
76
77 if (serviceURI == String.Empty)
78 {
79 m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService");
80 return;
81 }
82 m_Enabled = true; 71 m_Enabled = true;
83 m_ServerURI = serviceURI; 72
73 base.Initialise(source);
84 74
85 m_log.Info("[ASSET CONNECTOR]: Remote assets enabled"); 75 m_log.Info("[ASSET CONNECTOR]: Remote assets enabled");
86 } 76 }
@@ -121,6 +111,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
121 // 111 //
122 if (!(m_Cache is ISharedRegionModule)) 112 if (!(m_Cache is ISharedRegionModule))
123 m_Cache = null; 113 m_Cache = null;
114 else
115 SetCache(m_Cache);
116
124 } 117 }
125 118
126 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled remote assets for region {0}", scene.RegionInfo.RegionName); 119 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled remote assets for region {0}", scene.RegionInfo.RegionName);
@@ -130,173 +123,5 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
130 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); 123 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
131 } 124 }
132 } 125 }
133
134 public AssetBase Get(string id)
135 {
136 string uri = m_ServerURI + "/assets/" + id;
137
138 AssetBase asset = null;
139 if (m_Cache != null)
140 asset = m_Cache.Get(id);
141
142 if (asset == null)
143 {
144 asset = SynchronousRestObjectRequester.
145 MakeRequest<int, AssetBase>("GET", uri, 0);
146
147 if (m_Cache != null)
148 m_Cache.Cache(asset);
149 }
150 return asset;
151 }
152
153 public AssetMetadata GetMetadata(string id)
154 {
155 if (m_Cache != null)
156 {
157 AssetBase fullAsset = m_Cache.Get(id);
158
159 if (fullAsset != null)
160 return fullAsset.Metadata;
161 }
162
163 string uri = m_ServerURI + "/assets/" + id + "/metadata";
164
165 AssetMetadata asset = SynchronousRestObjectRequester.
166 MakeRequest<int, AssetMetadata>("GET", uri, 0);
167 return asset;
168 }
169
170 public byte[] GetData(string id)
171 {
172 if (m_Cache != null)
173 {
174 AssetBase fullAsset = m_Cache.Get(id);
175
176 if (fullAsset != null)
177 return fullAsset.Data;
178 }
179
180 RestClient rc = new RestClient(m_ServerURI);
181 rc.AddResourcePath("assets");
182 rc.AddResourcePath(id);
183 rc.AddResourcePath("data");
184
185 rc.RequestMethod = "GET";
186
187 Stream s = rc.Request();
188
189 if (s == null)
190 return null;
191
192 if (s.Length > 0)
193 {
194 byte[] ret = new byte[s.Length];
195 s.Read(ret, 0, (int)s.Length);
196
197 return ret;
198 }
199
200 return null;
201 }
202
203 public bool Get(string id, Object sender, AssetRetrieved handler)
204 {
205 string uri = m_ServerURI + "/assets/" + id;
206
207 AssetBase asset = null;
208 if (m_Cache != null)
209 asset = m_Cache.Get(id);
210
211 if (asset == null)
212 {
213 AsynchronousRestObjectRequester.
214 MakeRequest<int, AssetBase>("GET", uri, 0,
215 delegate(AssetBase a)
216 {
217 if (m_Cache != null)
218 m_Cache.Cache(a);
219 handler(id, sender, a);
220 });
221
222 }
223 else
224 {
225 handler(id, sender, asset);
226 }
227
228 return true;
229 }
230
231 public string Store(AssetBase asset)
232 {
233 if (asset.Temporary || asset.Local)
234 {
235 if (m_Cache != null)
236 m_Cache.Cache(asset);
237
238 return asset.ID;
239 }
240
241 string uri = m_ServerURI + "/assets/";
242
243 string newID = SynchronousRestObjectRequester.
244 MakeRequest<AssetBase, string>("POST", uri, asset);
245
246 if (newID != String.Empty)
247 {
248 asset.ID = newID;
249
250 if (m_Cache != null)
251 m_Cache.Cache(asset);
252 }
253 return newID;
254 }
255
256 public bool UpdateContent(string id, byte[] data)
257 {
258 AssetBase asset = null;
259
260 if (m_Cache != null)
261 asset = m_Cache.Get(id);
262
263 if (asset == null)
264 {
265 AssetMetadata metadata = GetMetadata(id);
266 if (metadata == null)
267 return false;
268
269 asset = new AssetBase();
270 asset.Metadata = metadata;
271 }
272 asset.Data = data;
273
274 string uri = m_ServerURI + "/assets/" + id;
275
276 if (SynchronousRestObjectRequester.
277 MakeRequest<AssetBase, bool>("POST", uri, asset))
278 {
279 if (m_Cache != null)
280 m_Cache.Cache(asset);
281
282 return true;
283 }
284 return false;
285 }
286
287 public bool Delete(string id)
288 {
289 string uri = m_ServerURI + "/assets/" + id;
290
291 if (SynchronousRestObjectRequester.
292 MakeRequest<int, bool>("DELETE", uri, 0))
293 {
294 if (m_Cache != null)
295 m_Cache.Expire(id);
296
297 return true;
298 }
299 return false;
300 }
301 } 126 }
302} 127}
diff --git a/OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs b/OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs
deleted file mode 100644
index b213284..0000000
--- a/OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs
+++ /dev/null
@@ -1,39 +0,0 @@
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 OpenSim.Framework;
29
30namespace OpenSim.Region.Framework.Interfaces
31{
32 public interface IImprovedAssetCache
33 {
34 void Cache(AssetBase asset);
35 AssetBase Get(string id);
36 void Expire(string id);
37 void Clear();
38 }
39}