aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
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
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')
-rw-r--r--OpenSim/Framework/IImprovedAssetCache.cs (renamed from OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs)2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs193
-rw-r--r--OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs252
3 files changed, 262 insertions, 185 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs b/OpenSim/Framework/IImprovedAssetCache.cs
index b213284..e1e9b5f 100644
--- a/OpenSim/Region/Framework/Interfaces/IImprovedAssetCache.cs
+++ b/OpenSim/Framework/IImprovedAssetCache.cs
@@ -27,7 +27,7 @@
27 27
28using OpenSim.Framework; 28using OpenSim.Framework;
29 29
30namespace OpenSim.Region.Framework.Interfaces 30namespace OpenSim.Framework
31{ 31{
32 public interface IImprovedAssetCache 32 public interface IImprovedAssetCache
33 { 33 {
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/Servers/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs
new file mode 100644
index 0000000..efd5eea
--- /dev/null
+++ b/OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs
@@ -0,0 +1,252 @@
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 System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38
39namespace OpenSim.Servers.Connectors
40{
41 public class AssetServicesConnector : IAssetService
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 private string m_ServerURI = String.Empty;
48 private IImprovedAssetCache m_Cache = null;
49
50 public AssetServicesConnector()
51 {
52 }
53
54 public AssetServicesConnector(IConfigSource source)
55 {
56 Initialise(source);
57 }
58
59 public virtual void Initialise(IConfigSource source)
60 {
61 IConfig assetConfig = source.Configs["AssetService"];
62 if (assetConfig == null)
63 {
64 m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini");
65 throw new Exception("Asset connector init error");
66 }
67
68 string serviceURI = assetConfig.GetString("AssetServerURI",
69 String.Empty);
70
71 if (serviceURI == String.Empty)
72 {
73 m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService");
74 throw new Exception("Asset connector init error");
75 }
76 m_ServerURI = serviceURI;
77 }
78
79 protected void SetCache(IImprovedAssetCache cache)
80 {
81 m_Cache = cache;
82 }
83
84 public AssetBase Get(string id)
85 {
86 string uri = m_ServerURI + "/assets/" + id;
87
88 AssetBase asset = null;
89 if (m_Cache != null)
90 asset = m_Cache.Get(id);
91
92 if (asset == null)
93 {
94 asset = SynchronousRestObjectRequester.
95 MakeRequest<int, AssetBase>("GET", uri, 0);
96
97 if (m_Cache != null)
98 m_Cache.Cache(asset);
99 }
100 return asset;
101 }
102
103 public AssetMetadata GetMetadata(string id)
104 {
105 if (m_Cache != null)
106 {
107 AssetBase fullAsset = m_Cache.Get(id);
108
109 if (fullAsset != null)
110 return fullAsset.Metadata;
111 }
112
113 string uri = m_ServerURI + "/assets/" + id + "/metadata";
114
115 AssetMetadata asset = SynchronousRestObjectRequester.
116 MakeRequest<int, AssetMetadata>("GET", uri, 0);
117 return asset;
118 }
119
120 public byte[] GetData(string id)
121 {
122 if (m_Cache != null)
123 {
124 AssetBase fullAsset = m_Cache.Get(id);
125
126 if (fullAsset != null)
127 return fullAsset.Data;
128 }
129
130 RestClient rc = new RestClient(m_ServerURI);
131 rc.AddResourcePath("assets");
132 rc.AddResourcePath(id);
133 rc.AddResourcePath("data");
134
135 rc.RequestMethod = "GET";
136
137 Stream s = rc.Request();
138
139 if (s == null)
140 return null;
141
142 if (s.Length > 0)
143 {
144 byte[] ret = new byte[s.Length];
145 s.Read(ret, 0, (int)s.Length);
146
147 return ret;
148 }
149
150 return null;
151 }
152
153 public bool Get(string id, Object sender, AssetRetrieved handler)
154 {
155 string uri = m_ServerURI + "/assets/" + id;
156
157 AssetBase asset = null;
158 if (m_Cache != null)
159 asset = m_Cache.Get(id);
160
161 if (asset == null)
162 {
163 AsynchronousRestObjectRequester.
164 MakeRequest<int, AssetBase>("GET", uri, 0,
165 delegate(AssetBase a)
166 {
167 if (m_Cache != null)
168 m_Cache.Cache(a);
169 handler(id, sender, a);
170 });
171
172 }
173 else
174 {
175 handler(id, sender, asset);
176 }
177
178 return true;
179 }
180
181 public string Store(AssetBase asset)
182 {
183 if (asset.Temporary || asset.Local)
184 {
185 if (m_Cache != null)
186 m_Cache.Cache(asset);
187
188 return asset.ID;
189 }
190
191 string uri = m_ServerURI + "/assets/";
192
193 string newID = SynchronousRestObjectRequester.
194 MakeRequest<AssetBase, string>("POST", uri, asset);
195
196 if (newID != String.Empty)
197 {
198 asset.ID = newID;
199
200 if (m_Cache != null)
201 m_Cache.Cache(asset);
202 }
203 return newID;
204 }
205
206 public bool UpdateContent(string id, byte[] data)
207 {
208 AssetBase asset = null;
209
210 if (m_Cache != null)
211 asset = m_Cache.Get(id);
212
213 if (asset == null)
214 {
215 AssetMetadata metadata = GetMetadata(id);
216 if (metadata == null)
217 return false;
218
219 asset = new AssetBase();
220 asset.Metadata = metadata;
221 }
222 asset.Data = data;
223
224 string uri = m_ServerURI + "/assets/" + id;
225
226 if (SynchronousRestObjectRequester.
227 MakeRequest<AssetBase, bool>("POST", uri, asset))
228 {
229 if (m_Cache != null)
230 m_Cache.Cache(asset);
231
232 return true;
233 }
234 return false;
235 }
236
237 public bool Delete(string id)
238 {
239 string uri = m_ServerURI + "/assets/" + id;
240
241 if (SynchronousRestObjectRequester.
242 MakeRequest<int, bool>("DELETE", uri, 0))
243 {
244 if (m_Cache != null)
245 m_Cache.Expire(id);
246
247 return true;
248 }
249 return false;
250 }
251 }
252}