From 63936d442ca7e6bdc0f09a5e974c57b3b5726353 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Wed, 15 Apr 2009 19:12:37 +0000 Subject: * Make it possible to add a request id to load and save oar requests * This allows specific requests to be identified. --- .../World/Archiver/ArchiveReadRequest.cs | 14 ++++++----- .../World/Archiver/ArchiveWriteRequestExecution.cs | 7 ++++-- .../Archiver/ArchiveWriteRequestPreparation.cs | 13 +++++++---- .../CoreModules/World/Archiver/ArchiverModule.cs | 27 +++++++++++++++------- .../World/Archiver/Tests/ArchiverTests.cs | 13 ++++++++--- .../Framework/Interfaces/IRegionArchiverModule.cs | 23 ++++++++++++++---- OpenSim/Region/Framework/Scenes/EventManager.cs | 14 ++++++----- .../Scripting/RegionReady/RegionReady.cs | 10 ++++---- 8 files changed, 83 insertions(+), 38 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index 3f6e822..1e57be0 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -55,6 +55,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver private Scene m_scene; private Stream m_loadStream; + private Guid m_requestId; private string m_errorMessage; /// @@ -67,19 +68,21 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// private IDictionary m_validUserUuids = new Dictionary(); - public ArchiveReadRequest(Scene scene, string loadPath, bool merge) + public ArchiveReadRequest(Scene scene, string loadPath, bool merge, Guid requestId) { m_scene = scene; m_loadStream = new GZipStream(GetStream(loadPath), CompressionMode.Decompress); m_errorMessage = String.Empty; m_merge = merge; + m_requestId = requestId; } - public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge) + public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, Guid requestId) { m_scene = scene; m_loadStream = loadStream; m_merge = merge; + m_requestId = requestId; } /// @@ -141,7 +144,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_log.ErrorFormat( "[ARCHIVER]: Error loading oar file. Exception was: {0}", e); m_errorMessage += e.ToString(); - m_scene.EventManager.TriggerOarFileLoaded(m_errorMessage); + m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage); return; } @@ -163,8 +166,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface(); - int sceneObjectsLoadedCount = 0; - + int sceneObjectsLoadedCount = 0; foreach (string serialisedSceneObject in serialisedSceneObjects) { @@ -247,7 +249,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive"); - m_scene.EventManager.TriggerOarFileLoaded(m_errorMessage); + m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage); } /// diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs index 85391b3..943d9d1 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs @@ -58,19 +58,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver protected List m_sceneObjects; protected Scene m_scene; protected Stream m_saveStream; + protected Guid m_requestId; public ArchiveWriteRequestExecution( List sceneObjects, ITerrainModule terrainModule, IRegionSerialiserModule serialiser, Scene scene, - Stream saveStream) + Stream saveStream, + Guid requestId) { m_sceneObjects = sceneObjects; m_terrainModule = terrainModule; m_serialiser = serialiser; m_scene = scene; m_saveStream = saveStream; + m_requestId = requestId; } protected internal void ReceivedAllAssets( @@ -140,7 +143,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_log.InfoFormat("[ARCHIVER]: Wrote out OpenSimulator archive for {0}", m_scene.RegionInfo.RegionName); - m_scene.EventManager.TriggerOarFileSaved(String.Empty); + m_scene.EventManager.TriggerOarFileSaved(m_requestId, String.Empty); } /// diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs index accf7e4..a6ad24c 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs @@ -50,14 +50,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver protected Scene m_scene; protected Stream m_saveStream; + protected Guid m_requestId; /// /// Constructor /// - public ArchiveWriteRequestPreparation(Scene scene, string savePath) + public ArchiveWriteRequestPreparation(Scene scene, string savePath, Guid requestId) { m_scene = scene; - m_saveStream = new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress); + m_saveStream = new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress); + m_requestId = requestId; } /// @@ -65,10 +67,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// /// /// The stream to which to save data. - public ArchiveWriteRequestPreparation(Scene scene, Stream saveStream) + /// The id associated with this request + public ArchiveWriteRequestPreparation(Scene scene, Stream saveStream, Guid requestId) { m_scene = scene; m_saveStream = saveStream; + m_requestId = requestId; } /// @@ -129,7 +133,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_scene.RequestModuleInterface(), m_scene.RequestModuleInterface(), m_scene, - m_saveStream); + m_saveStream, + m_requestId); new AssetsRequest(assetUuids.Keys, m_scene.CommsManager.AssetCache, awre.ReceivedAllAssets).Execute(); } diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs index dd67027..b6e2d31 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.IO; using System.Reflection; using log4net; @@ -63,38 +64,48 @@ namespace OpenSim.Region.CoreModules.World.Archiver public void ArchiveRegion(string savePath) { + ArchiveRegion(savePath, Guid.Empty); + } + + public void ArchiveRegion(string savePath, Guid requestId) + { m_log.InfoFormat( "[ARCHIVER]: Writing archive for region {0} to {1}", m_scene.RegionInfo.RegionName, savePath); - new ArchiveWriteRequestPreparation(m_scene, savePath).ArchiveRegion(); + new ArchiveWriteRequestPreparation(m_scene, savePath, requestId).ArchiveRegion(); } public void ArchiveRegion(Stream saveStream) { - new ArchiveWriteRequestPreparation(m_scene, saveStream).ArchiveRegion(); + ArchiveRegion(saveStream, Guid.Empty); } + + public void ArchiveRegion(Stream saveStream, Guid requestId) + { + new ArchiveWriteRequestPreparation(m_scene, saveStream, requestId).ArchiveRegion(); + } public void DearchiveRegion(string loadPath) { - DearchiveRegion(loadPath, false); + DearchiveRegion(loadPath, false, Guid.Empty); } - public void DearchiveRegion(string loadPath, bool merge) + public void DearchiveRegion(string loadPath, bool merge, Guid requestId) { m_log.InfoFormat( "[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath); - new ArchiveReadRequest(m_scene, loadPath, merge).DearchiveRegion(); + new ArchiveReadRequest(m_scene, loadPath, merge, requestId).DearchiveRegion(); } public void DearchiveRegion(Stream loadStream) { - DearchiveRegion(loadStream, false); + DearchiveRegion(loadStream, false, Guid.Empty); } - public void DearchiveRegion(Stream loadStream, bool merge) + public void DearchiveRegion(Stream loadStream, bool merge, Guid requestId) { - new ArchiveReadRequest(m_scene, loadStream, merge).DearchiveRegion(); + new ArchiveReadRequest(m_scene, loadStream, merge, requestId).DearchiveRegion(); } } } diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index 165a607..3ffabbd 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs @@ -47,10 +47,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests [TestFixture, LongRunning] public class ArchiverTests { - private void SaveCompleted(string errorMessage) + private Guid m_lastRequestId; + + private void SaveCompleted(Guid requestId, string errorMessage) { lock (this) { + m_lastRequestId = requestId; System.Console.WriteLine("About to pulse ArchiverTests"); Monitor.PulseAll(this); } @@ -112,15 +115,19 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests MemoryStream archiveWriteStream = new MemoryStream(); scene.EventManager.OnOarFileSaved += SaveCompleted; + Guid requestId = new Guid("00000000-0000-0000-0000-808080808080"); + lock (this) { - archiverModule.ArchiveRegion(archiveWriteStream); + archiverModule.ArchiveRegion(archiveWriteStream, requestId); AssetServerBase assetServer = (AssetServerBase)scene.CommsManager.AssetCache.AssetServer; while (assetServer.HasWaitingRequests()) assetServer.ProcessNextRequest(); Monitor.Wait(this, 60000); } + + Assert.That(m_lastRequestId, Is.EqualTo(requestId)); byte[] archive = archiveWriteStream.ToArray(); MemoryStream archiveReadStream = new MemoryStream(archive); @@ -303,7 +310,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests byte[] archive = archiveWriteStream.ToArray(); MemoryStream archiveReadStream = new MemoryStream(archive); - archiverModule.DearchiveRegion(archiveReadStream, true); + archiverModule.DearchiveRegion(archiveReadStream, true, Guid.Empty); SceneObjectPart object1Existing = scene.GetSceneObjectPart(part1Name); Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge"); diff --git a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs index 601b83e..530fb79 100644 --- a/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IRegionArchiverModule.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.IO; namespace OpenSim.Region.Framework.Interfaces @@ -43,6 +44,17 @@ namespace OpenSim.Region.Framework.Interfaces /// /// void ArchiveRegion(string savePath); + + /// + /// Archive the region to the given path + /// + /// + /// This method occurs asynchronously. If you want notification of when it has completed then subscribe to + /// the EventManager.OnOarFileSaved event. + /// + /// + /// If supplied, this request Id is later returned in the saved event + void ArchiveRegion(string savePath, Guid requestId); /// /// Archive the region to a stream. @@ -52,7 +64,8 @@ namespace OpenSim.Region.Framework.Interfaces /// the EventManager.OnOarFileSaved event. /// /// - void ArchiveRegion(Stream saveStream); + /// If supplied, this request Id is later returned in the saved event + void ArchiveRegion(Stream saveStream, Guid requestId); /// /// Dearchive the given region archive. This replaces the existing scene. @@ -74,7 +87,8 @@ namespace OpenSim.Region.Framework.Interfaces /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region /// settings in the archive will be ignored. /// - void DearchiveRegion(string loadPath, bool merge); + /// If supplied, this request Id is later returned in the saved event + void DearchiveRegion(string loadPath, bool merge, Guid requestId); /// /// Dearchive a region from a stream. This replaces the existing scene. @@ -95,7 +109,8 @@ namespace OpenSim.Region.Framework.Interfaces /// /// If true, the loaded region merges with the existing one rather than replacing it. Any terrain or region /// settings in the archive will be ignored. - /// - void DearchiveRegion(Stream loadStream, bool merge); + /// + /// If supplied, this request Id is later returned in the saved event + void DearchiveRegion(Stream loadStream, bool merge, Guid requestId); } } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 7496af0..469f139 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -279,14 +279,16 @@ namespace OpenSim.Region.Framework.Scenes /// the scripts may not have started yet /// Message is non empty string if there were problems loading the oar file /// - public delegate void OarFileLoaded(string message); + public delegate void OarFileLoaded(Guid guid, string message); public event OarFileLoaded OnOarFileLoaded; /// /// Called when an oar file has finished saving /// Message is non empty string if there were problems saving the oar file + /// If a guid was supplied on the original call to identify, the request, this is returned. Otherwise + /// Guid.Empty is returned. /// - public delegate void OarFileSaved(string message); + public delegate void OarFileSaved(Guid guid, string message); public event OarFileSaved OnOarFileSaved; /// @@ -968,18 +970,18 @@ namespace OpenSim.Region.Framework.Scenes return 6; } - public void TriggerOarFileLoaded(string message) + public void TriggerOarFileLoaded(Guid requestId, string message) { handlerOarFileLoaded = OnOarFileLoaded; if (handlerOarFileLoaded != null) - handlerOarFileLoaded(message); + handlerOarFileLoaded(requestId, message); } - public void TriggerOarFileSaved(string message) + public void TriggerOarFileSaved(Guid requestId, string message) { handlerOarFileSaved = OnOarFileSaved; if (handlerOarFileSaved != null) - handlerOarFileSaved(message); + handlerOarFileSaved(requestId, message); } public void TriggerEmptyScriptCompileQueue(int numScriptsFailed, string message) diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs index 6035712..4f57470 100644 --- a/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs +++ b/OpenSim/Region/OptionalModules/Scripting/RegionReady/RegionReady.cs @@ -76,13 +76,13 @@ namespace OpenSim.Region.CoreModules.Scripting.RegionReady { if (m_enabled) { - m_log.Info("[RegionReady] Enabled"); + m_log.Info("[RegionReady]: Enabled"); m_scene.EventManager.OnEmptyScriptCompileQueue += new EventManager.EmptyScriptCompileQueue(OnEmptyScriptCompileQueue); m_scene.EventManager.OnOarFileLoaded += new EventManager.OarFileLoaded(OnOarFileLoaded); } else { - m_log.Info("[RegionReady] Disabled"); + m_log.Info("[RegionReady]: Disabled"); } } @@ -129,20 +129,20 @@ namespace OpenSim.Region.CoreModules.Scripting.RegionReady c.Sender = null; c.SenderUUID = UUID.Zero; - m_log.InfoFormat("[RegionReady] Region \"{0}\" is ready: \"{1}\" on channel {2}", + m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}", m_scene.RegionInfo.RegionName, c.Message, m_channelNotify); m_scene.EventManager.TriggerOnChatBroadcast(this, c); } } - void OnOarFileLoaded(string message) + void OnOarFileLoaded(Guid requestId, string message) { m_oarFileLoading = true; if (message==String.Empty) { m_lastOarLoadedOk = true; } else { - m_log.InfoFormat("[RegionReady] Oar file load errors: {0}", message); + m_log.InfoFormat("[RegionReady]: Oar file load errors: {0}", message); m_lastOarLoadedOk = false; } } -- cgit v1.1