aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs56
1 files changed, 48 insertions, 8 deletions
diff --git a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
index 565e4f2..2bfa597 100644
--- a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs
@@ -51,6 +51,13 @@ namespace OpenSim.Services.Connectors
51 private int m_retryCounter; 51 private int m_retryCounter;
52 private Dictionary<int, List<AssetBase>> m_retryQueue = new Dictionary<int, List<AssetBase>>(); 52 private Dictionary<int, List<AssetBase>> m_retryQueue = new Dictionary<int, List<AssetBase>>();
53 private Timer m_retryTimer; 53 private Timer m_retryTimer;
54 private delegate void AssetRetrievedEx(AssetBase asset);
55
56 // Keeps track of concurrent requests for the same asset, so that it's only loaded once.
57 // Maps: Asset ID -> Handlers which will be called when the asset has been loaded
58 private Dictionary<string, AssetRetrievedEx> m_AssetHandlers = new Dictionary<string, AssetRetrievedEx>();
59
60
54 public AssetServicesConnector() 61 public AssetServicesConnector()
55 { 62 {
56 } 63 }
@@ -230,23 +237,56 @@ namespace OpenSim.Services.Connectors
230 237
231 if (asset == null || asset.Data == null || asset.Data.Length == 0) 238 if (asset == null || asset.Data == null || asset.Data.Length == 0)
232 { 239 {
233 bool result = false; 240 lock (m_AssetHandlers)
241 {
242 AssetRetrievedEx handlerEx = new AssetRetrievedEx(delegate(AssetBase _asset) { handler(id, sender, _asset); });
243
244 AssetRetrievedEx handlers;
245 if (m_AssetHandlers.TryGetValue(id, out handlers))
246 {
247 // Someone else is already loading this asset. It will notify our handler when done.
248 handlers += handlerEx;
249 return true;
250 }
251
252 // Load the asset ourselves
253 handlers += handlerEx;
254 m_AssetHandlers.Add(id, handlers);
255 }
234 256
235 AsynchronousRestObjectRequester. 257 bool success = false;
236 MakeRequest<int, AssetBase>("GET", uri, 0, 258 try
259 {
260 AsynchronousRestObjectRequester.MakeRequest<int, AssetBase>("GET", uri, 0,
237 delegate(AssetBase a) 261 delegate(AssetBase a)
238 { 262 {
239 if (m_Cache != null) 263 if (m_Cache != null)
240 m_Cache.Cache(a); 264 m_Cache.Cache(a);
241 handler(id, sender, a);
242 result = true;
243 });
244 265
245 return result; 266 AssetRetrievedEx handlers;
267 lock (m_AssetHandlers)
268 {
269 handlers = m_AssetHandlers[id];
270 m_AssetHandlers.Remove(id);
271 }
272 handlers.Invoke(a);
273 });
274
275 success = true;
276 }
277 finally
278 {
279 if (!success)
280 {
281 lock (m_AssetHandlers)
282 {
283 m_AssetHandlers.Remove(id);
284 }
285 }
286 }
246 } 287 }
247 else 288 else
248 { 289 {
249 //Util.FireAndForget(delegate { handler(id, sender, asset); });
250 handler(id, sender, asset); 290 handler(id, sender, asset);
251 } 291 }
252 292