From 1894157dd3608a15c3336efc2d58eee0de092610 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 14 Apr 2009 17:15:09 +0000 Subject: [PATCH] * Explicitly start the asset server thread so that unit tests can run single rather than multi-threaded (which may be behind the occasional test freezes) --- .../Communications/Cache/AssetServerBase.cs | 39 +++++++++---------- .../Cache/CryptoGridAssetClient.cs | 5 --- .../Communications/Cache/GridAssetClient.cs | 5 --- .../Communications/Cache/SQLAssetServer.cs | 5 --- .../Tests/Cache/AssetCacheTests.cs | 4 +- OpenSim/Framework/IAssetServer.cs | 12 +++++- OpenSim/Region/Application/OpenSimBase.cs | 2 + .../Common/Mock/TestCommunicationsManager.cs | 1 + 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs index 1d0c030cd0..343667af52 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs @@ -42,7 +42,7 @@ namespace OpenSim.Framework.Communications.Cache = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected IAssetReceiver m_receiver; - protected BlockingQueue m_assetRequests; + protected BlockingQueue m_assetRequests = new BlockingQueue(); protected Thread m_localAssetServerThread; protected IAssetDataPlugin m_assetProvider; @@ -109,6 +109,22 @@ namespace OpenSim.Framework.Communications.Cache // Temporarily hardcoded - should be a plugin protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); + public virtual void Start() + { + m_log.Debug("[ASSET SERVER]: Starting asset server"); + + m_localAssetServerThread = new Thread(RunRequests); + m_localAssetServerThread.Name = "LocalAssetServerThread"; + m_localAssetServerThread.IsBackground = true; + m_localAssetServerThread.Start(); + ThreadTracker.Add(m_localAssetServerThread); + } + + public virtual void Stop() + { + m_localAssetServerThread.Abort(); + } + public abstract void StoreAsset(AssetBase asset); /// @@ -121,8 +137,8 @@ namespace OpenSim.Framework.Communications.Cache /// Thrown if the request failed for some other reason than that the /// asset cannot be found. /// - protected abstract AssetBase GetAsset(AssetRequest req); - + protected abstract AssetBase GetAsset(AssetRequest req); + /// /// Process an asset request. This method will call GetAsset(AssetRequest req) /// on the subclass. @@ -169,18 +185,6 @@ namespace OpenSim.Framework.Communications.Cache assetLoader.ForEachDefaultXmlAsset(pAssetSetsXml, StoreAsset); } - public AssetServerBase() - { - m_log.Info("[ASSET SERVER]: Starting asset storage system"); - m_assetRequests = new BlockingQueue(); - - m_localAssetServerThread = new Thread(RunRequests); - m_localAssetServerThread.Name = "LocalAssetServerThread"; - m_localAssetServerThread.IsBackground = true; - m_localAssetServerThread.Start(); - ThreadTracker.Add(m_localAssetServerThread); - } - private void RunRequests() { while (true) // Since it's a 'blocking queue' @@ -222,11 +226,6 @@ namespace OpenSim.Framework.Communications.Cache m_assetProvider.UpdateAsset(asset); } - public virtual void Close() - { - m_localAssetServerThread.Abort(); - } - public void SetServerInfo(string ServerUrl, string ServerKey) { } diff --git a/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs b/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs index f1c19fa5a5..6e4dd1c3d8 100644 --- a/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs @@ -554,11 +554,6 @@ namespace OpenSim.Framework.Communications.Cache } } - public override void Close() - { - throw new Exception("The method or operation is not implemented."); - } - #endregion } } diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs index 7131cb5d5f..c7d4c99898 100644 --- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs @@ -135,11 +135,6 @@ namespace OpenSim.Framework.Communications.Cache } } - public override void Close() - { - throw new Exception("The method or operation is not implemented."); - } - #endregion } } diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs index 41a9561292..227744dd91 100644 --- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs @@ -100,11 +100,6 @@ namespace OpenSim.Framework.Communications.Cache } } - public override void Close() - { - base.Close(); - } - protected override AssetBase GetAsset(AssetRequest req) { return m_assetProvider.FetchAsset(req.AssetID); diff --git a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs index 9d9810b5cc..264bfe14bc 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs @@ -62,7 +62,9 @@ namespace OpenSim.Framework.Communications.Tests TestAssetDataPlugin assetPlugin = new TestAssetDataPlugin(); assetPlugin.CreateAsset(asset); - IAssetCache assetCache = new AssetCache(new SQLAssetServer(assetPlugin)); + IAssetServer assetServer = new SQLAssetServer(assetPlugin); + IAssetCache assetCache = new AssetCache(assetServer); + assetServer.Start(); lock (this) { diff --git a/OpenSim/Framework/IAssetServer.cs b/OpenSim/Framework/IAssetServer.cs index f76d12560a..0a08ff6f6f 100644 --- a/OpenSim/Framework/IAssetServer.cs +++ b/OpenSim/Framework/IAssetServer.cs @@ -37,11 +37,21 @@ namespace OpenSim.Framework void Initialise(ConfigSettings settings); void Initialise(ConfigSettings settings, string url, string dir, bool test); void Initialise(ConfigSettings settings, string url); + + /// + /// Start the asset server + /// + void Start(); + + /// + /// Stop the asset server + /// + void Stop(); + void SetReceiver(IAssetReceiver receiver); void RequestAsset(UUID assetID, bool isTexture); void StoreAsset(AssetBase asset); void UpdateAsset(AssetBase asset); - void Close(); } /// diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 3840240db8..7aa9f99860 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -381,6 +381,8 @@ namespace OpenSim // Initialize the asset cache, passing a reference to the selected // asset server interface. m_assetCache = ResolveAssetCache(assetServer); + + assetServer.Start(); } // This method loads the identified asset server, passing an approrpiately diff --git a/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs b/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs index 8416fb6501..3b39d36a9c 100644 --- a/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs +++ b/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs @@ -61,6 +61,7 @@ namespace OpenSim.Tests.Common.Mock SQLAssetServer assetService = new SQLAssetServer(new TestAssetDataPlugin()); m_assetCache = new AssetCache(assetService); + m_assetCache.AssetServer.Start(); LocalInventoryService lis = new LocalInventoryService(); lis.AddPlugin(m_inventoryDataPlugin);