aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs118
1 files changed, 78 insertions, 40 deletions
diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
index 2b2f11f..bd43552 100644
--- a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
+++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs
@@ -33,13 +33,12 @@ using System.Reflection;
33using Nini.Config; 33using Nini.Config;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Framework.Communications;
37using OpenSim.Services.Interfaces; 36using OpenSim.Services.Interfaces;
38using OpenMetaverse; 37using OpenMetaverse;
39 38
40namespace OpenSim.Services.Connectors 39namespace OpenSim.Services.Connectors
41{ 40{
42 public class AssetServicesConnector : IAssetService 41 public class AssetServicesConnector : BaseServiceConnector, IAssetService
43 { 42 {
44 private static readonly ILog m_log = 43 private static readonly ILog m_log =
45 LogManager.GetLogger( 44 LogManager.GetLogger(
@@ -55,6 +54,11 @@ namespace OpenSim.Services.Connectors
55 // Maps: Asset ID -> Handlers which will be called when the asset has been loaded 54 // Maps: Asset ID -> Handlers which will be called when the asset has been loaded
56 private Dictionary<string, AssetRetrievedEx> m_AssetHandlers = new Dictionary<string, AssetRetrievedEx>(); 55 private Dictionary<string, AssetRetrievedEx> m_AssetHandlers = new Dictionary<string, AssetRetrievedEx>();
57 56
57 public int MaxAssetRequestConcurrency
58 {
59 get { return m_maxAssetRequestConcurrency; }
60 set { m_maxAssetRequestConcurrency = value; }
61 }
58 62
59 public AssetServicesConnector() 63 public AssetServicesConnector()
60 { 64 {
@@ -66,6 +70,7 @@ namespace OpenSim.Services.Connectors
66 } 70 }
67 71
68 public AssetServicesConnector(IConfigSource source) 72 public AssetServicesConnector(IConfigSource source)
73 : base(source, "AssetService")
69 { 74 {
70 Initialise(source); 75 Initialise(source);
71 } 76 }
@@ -112,8 +117,16 @@ namespace OpenSim.Services.Connectors
112 117
113 if (asset == null) 118 if (asset == null)
114 { 119 {
115 asset = SynchronousRestObjectRequester. 120 // XXX: Commented out for now since this has either never been properly operational or not for some time
116 MakeRequest<int, AssetBase>("GET", uri, 0, m_maxAssetRequestConcurrency); 121 // as m_maxAssetRequestConcurrency was being passed as the timeout, not a concurrency limiting option.
122 // Wasn't noticed before because timeout wasn't actually used.
123 // Not attempting concurrency setting for now as this omission was discovered in release candidate
124 // phase for OpenSimulator 0.8. Need to revisit afterwards.
125// asset
126// = SynchronousRestObjectRequester.MakeRequest<int, AssetBase>(
127// "GET", uri, 0, m_maxAssetRequestConcurrency);
128
129 asset = SynchronousRestObjectRequester.MakeRequest<int, AssetBase>("GET", uri, 0, m_Auth);
117 130
118 if (m_Cache != null) 131 if (m_Cache != null)
119 m_Cache.Cache(asset); 132 m_Cache.Cache(asset);
@@ -143,8 +156,7 @@ namespace OpenSim.Services.Connectors
143 156
144 string uri = m_ServerURI + "/assets/" + id + "/metadata"; 157 string uri = m_ServerURI + "/assets/" + id + "/metadata";
145 158
146 AssetMetadata asset = SynchronousRestObjectRequester. 159 AssetMetadata asset = SynchronousRestObjectRequester.MakeRequest<int, AssetMetadata>("GET", uri, 0, m_Auth);
147 MakeRequest<int, AssetMetadata>("GET", uri, 0);
148 return asset; 160 return asset;
149 } 161 }
150 162
@@ -158,27 +170,29 @@ namespace OpenSim.Services.Connectors
158 return fullAsset.Data; 170 return fullAsset.Data;
159 } 171 }
160 172
161 RestClient rc = new RestClient(m_ServerURI); 173 using (RestClient rc = new RestClient(m_ServerURI))
162 rc.AddResourcePath("assets"); 174 {
163 rc.AddResourcePath(id); 175 rc.AddResourcePath("assets");
164 rc.AddResourcePath("data"); 176 rc.AddResourcePath(id);
177 rc.AddResourcePath("data");
165 178
166 rc.RequestMethod = "GET"; 179 rc.RequestMethod = "GET";
167 180
168 Stream s = rc.Request(); 181 Stream s = rc.Request(m_Auth);
169 182
170 if (s == null) 183 if (s == null)
171 return null; 184 return null;
172 185
173 if (s.Length > 0) 186 if (s.Length > 0)
174 { 187 {
175 byte[] ret = new byte[s.Length]; 188 byte[] ret = new byte[s.Length];
176 s.Read(ret, 0, (int)s.Length); 189 s.Read(ret, 0, (int)s.Length);
177 190
178 return ret; 191 return ret;
179 } 192 }
180 193
181 return null; 194 return null;
195 }
182 } 196 }
183 197
184 public bool Get(string id, Object sender, AssetRetrieved handler) 198 public bool Get(string id, Object sender, AssetRetrieved handler)
@@ -216,7 +230,7 @@ namespace OpenSim.Services.Connectors
216 AsynchronousRestObjectRequester.MakeRequest<int, AssetBase>("GET", uri, 0, 230 AsynchronousRestObjectRequester.MakeRequest<int, AssetBase>("GET", uri, 0,
217 delegate(AssetBase a) 231 delegate(AssetBase a)
218 { 232 {
219 if (m_Cache != null) 233 if (a != null && m_Cache != null)
220 m_Cache.Cache(a); 234 m_Cache.Cache(a);
221 235
222 AssetRetrievedEx handlers; 236 AssetRetrievedEx handlers;
@@ -226,7 +240,7 @@ namespace OpenSim.Services.Connectors
226 m_AssetHandlers.Remove(id); 240 m_AssetHandlers.Remove(id);
227 } 241 }
228 handlers.Invoke(a); 242 handlers.Invoke(a);
229 }, m_maxAssetRequestConcurrency); 243 }, m_maxAssetRequestConcurrency, m_Auth);
230 244
231 success = true; 245 success = true;
232 } 246 }
@@ -249,9 +263,30 @@ namespace OpenSim.Services.Connectors
249 return true; 263 return true;
250 } 264 }
251 265
266 public virtual bool[] AssetsExist(string[] ids)
267 {
268 string uri = m_ServerURI + "/get_assets_exist";
269
270 bool[] exist = null;
271 try
272 {
273 exist = SynchronousRestObjectRequester.MakeRequest<string[], bool[]>("POST", uri, ids, m_Auth);
274 }
275 catch (Exception)
276 {
277 // This is most likely to happen because the server doesn't support this function,
278 // so just silently return "doesn't exist" for all the assets.
279 }
280
281 if (exist == null)
282 exist = new bool[ids.Length];
283
284 return exist;
285 }
286
252 public string Store(AssetBase asset) 287 public string Store(AssetBase asset)
253 { 288 {
254 if (asset.Temporary || asset.Local) 289 if (asset.Local)
255 { 290 {
256 if (m_Cache != null) 291 if (m_Cache != null)
257 m_Cache.Cache(asset); 292 m_Cache.Cache(asset);
@@ -261,27 +296,32 @@ namespace OpenSim.Services.Connectors
261 296
262 string uri = m_ServerURI + "/assets/"; 297 string uri = m_ServerURI + "/assets/";
263 298
264 string newID = string.Empty; 299 string newID;
265 try 300 try
266 { 301 {
267 newID = SynchronousRestObjectRequester. 302 newID = SynchronousRestObjectRequester.MakeRequest<AssetBase, string>("POST", uri, asset, m_Auth);
268 MakeRequest<AssetBase, string>("POST", uri, asset);
269 } 303 }
270 catch (Exception e) 304 catch (Exception e)
271 { 305 {
272 m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message); 306 m_log.Warn(string.Format("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1} ", asset.ID, e.Message), e);
307 return string.Empty;
273 } 308 }
274 309
275 if (newID != String.Empty) 310 // TEMPORARY: SRAS returns 'null' when it's asked to store existing assets
311 if (newID == null)
276 { 312 {
277 // Placing this here, so that this work with old asset servers that don't send any reply back 313 m_log.DebugFormat("[ASSET CONNECTOR]: Storing of asset {0} returned null; assuming the asset already exists", asset.ID);
278 // SynchronousRestObjectRequester returns somethins that is not an empty string 314 return asset.ID;
279 if (newID != null)
280 asset.ID = newID;
281
282 if (m_Cache != null)
283 m_Cache.Cache(asset);
284 } 315 }
316
317 if (string.IsNullOrEmpty(newID))
318 return string.Empty;
319
320 asset.ID = newID;
321
322 if (m_Cache != null)
323 m_Cache.Cache(asset);
324
285 return newID; 325 return newID;
286 } 326 }
287 327
@@ -305,8 +345,7 @@ namespace OpenSim.Services.Connectors
305 345
306 string uri = m_ServerURI + "/assets/" + id; 346 string uri = m_ServerURI + "/assets/" + id;
307 347
308 if (SynchronousRestObjectRequester. 348 if (SynchronousRestObjectRequester.MakeRequest<AssetBase, bool>("POST", uri, asset, m_Auth))
309 MakeRequest<AssetBase, bool>("POST", uri, asset))
310 { 349 {
311 if (m_Cache != null) 350 if (m_Cache != null)
312 m_Cache.Cache(asset); 351 m_Cache.Cache(asset);
@@ -320,8 +359,7 @@ namespace OpenSim.Services.Connectors
320 { 359 {
321 string uri = m_ServerURI + "/assets/" + id; 360 string uri = m_ServerURI + "/assets/" + id;
322 361
323 if (SynchronousRestObjectRequester. 362 if (SynchronousRestObjectRequester.MakeRequest<int, bool>("DELETE", uri, 0, m_Auth))
324 MakeRequest<int, bool>("DELETE", uri, 0))
325 { 363 {
326 if (m_Cache != null) 364 if (m_Cache != null)
327 m_Cache.Expire(id); 365 m_Cache.Expire(id);