diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 612137171a..11852eb749 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1471,6 +1471,8 @@ namespace OpenSim.Framework.Servers.HttpServer else responseString = (string)responsedata["str_response_string"]; contentType = (string)responsedata["content_type"]; + if (responseString == null) + responseString = String.Empty; } catch { diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs index daf38bc1cd..9d6d9ad69c 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs @@ -27,6 +27,7 @@ using log4net; using System; +using System.Threading; using System.Collections.Generic; using System.IO; using System.Reflection; @@ -50,7 +51,7 @@ namespace OpenSim.Services.Connectors private IImprovedAssetCache m_Cache = null; private int m_retryCounter; private Dictionary> m_retryQueue = new Dictionary>(); - private Timer m_retryTimer; + private System.Timers.Timer m_retryTimer; private delegate void AssetRetrievedEx(AssetBase asset); // Keeps track of concurrent requests for the same asset, so that it's only loaded once. @@ -61,6 +62,8 @@ namespace OpenSim.Services.Connectors private Dictionary m_UriMap = new Dictionary(); + private Thread[] m_fetchThreads; + public AssetServicesConnector() { } @@ -96,7 +99,7 @@ namespace OpenSim.Services.Connectors } - m_retryTimer = new Timer(); + m_retryTimer = new System.Timers.Timer(); m_retryTimer.Elapsed += new ElapsedEventHandler(retryCheck); m_retryTimer.Interval = 60000; @@ -112,6 +115,14 @@ namespace OpenSim.Services.Connectors m_UriMap[prefix] = groupHost; //m_log.DebugFormat("[ASSET]: Using {0} for prefix {1}", groupHost, prefix); } + + m_fetchThreads = new Thread[2]; + + for (int i = 0 ; i < 2 ; i++) + { + m_fetchThreads[i] = new Thread(AssetRequestProcessor); + m_fetchThreads[i].Start(); + } } private string MapServer(string id) @@ -261,6 +272,66 @@ namespace OpenSim.Services.Connectors return null; } + private class QueuedAssetRequest + { + public string uri; + public string id; + } + + private OpenMetaverse.BlockingQueue m_requestQueue = + new OpenMetaverse.BlockingQueue(); + + private void AssetRequestProcessor() + { + QueuedAssetRequest r; + + while (true) + { + r = m_requestQueue.Dequeue(); + + string uri = r.uri; + string id = r.id; + + bool success = false; + try + { + AsynchronousRestObjectRequester.MakeRequest("GET", uri, 0, + delegate(AssetBase a) + { + if (m_Cache != null) + m_Cache.Cache(a); + + List handlers; + lock (m_AssetHandlers) + { + handlers = m_AssetHandlers[id]; + m_AssetHandlers.Remove(id); + } + foreach (AssetRetrievedEx h in handlers) + h.Invoke(a); + if (handlers != null) + handlers.Clear(); + }, 30); + + success = true; + } + finally + { + if (!success) + { + List handlers; + lock (m_AssetHandlers) + { + handlers = m_AssetHandlers[id]; + m_AssetHandlers.Remove(id); + } + if (handlers != null) + handlers.Clear(); + } + } + } + } + public bool Get(string id, Object sender, AssetRetrieved handler) { string uri = MapServer(id) + "/assets/" + id; @@ -293,52 +364,11 @@ namespace OpenSim.Services.Connectors m_AssetHandlers.Add(id, handlers); } - bool success = false; - try - { - AsynchronousRestObjectRequester.MakeRequest("GET", uri, 0, - delegate(AssetBase a) - { - if (m_Cache != null) - m_Cache.Cache(a); -/* - AssetRetrievedEx handlers; - lock (m_AssetHandlers) - { - handlers = m_AssetHandlers[id]; - m_AssetHandlers.Remove(id); - } + QueuedAssetRequest request = new QueuedAssetRequest(); + request.id = id; + request.uri = uri; - handlers.Invoke(a); -*/ - List handlers; - lock (m_AssetHandlers) - { - handlers = m_AssetHandlers[id]; - m_AssetHandlers.Remove(id); - } - foreach (AssetRetrievedEx h in handlers) - h.Invoke(a); - if (handlers != null) - handlers.Clear(); - }, 30); - - success = true; - } - finally - { - if (!success) - { - List handlers; - lock (m_AssetHandlers) - { - handlers = m_AssetHandlers[id]; - m_AssetHandlers.Remove(id); - } - if (handlers != null) - handlers.Clear(); - } - } + m_requestQueue.Enqueue(request); } else {