diff options
author | Melanie Thielker | 2009-05-14 06:18:18 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-05-14 06:18:18 +0000 |
commit | d843b897b20601f0ba32a6f88da31cf5ea88c2ba (patch) | |
tree | b311ceed8ede25cd68edc6522e17e72343137fe1 /OpenSim/Region/CoreModules/ServiceConnectors | |
parent | Small fix uncommenting something that got commented too much. (diff) | |
download | opensim-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/CoreModules/ServiceConnectors')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs | 193 |
1 files changed, 9 insertions, 184 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 @@ | |||
28 | using log4net; | 28 | using log4net; |
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.IO; | ||
32 | using System.Reflection; | 31 | using System.Reflection; |
33 | using Nini.Config; | 32 | using Nini.Config; |
34 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Servers.HttpServer; | 34 | using OpenSim.Servers.Connectors; |
36 | using OpenSim.Region.Framework.Interfaces; | 35 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
38 | using OpenSim.Services.Interfaces; | 37 | using OpenSim.Services.Interfaces; |
39 | using OpenSim.Framework.Communications; | ||
40 | 38 | ||
41 | namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset | 39 | namespace 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 | } |