diff options
author | Justin Clarke Casey | 2009-02-02 20:59:12 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-02-02 20:59:12 +0000 |
commit | 2c2f10e156c62aa1d95923ff5309f2be7f08faeb (patch) | |
tree | c6631296849e076264ce8e034d29ca117750bfa5 | |
parent | * As per http://opensimulator.org/mantis/view.php?id=3065 (diff) | |
download | opensim-SC-2c2f10e156c62aa1d95923ff5309f2be7f08faeb.zip opensim-SC-2c2f10e156c62aa1d95923ff5309f2be7f08faeb.tar.gz opensim-SC-2c2f10e156c62aa1d95923ff5309f2be7f08faeb.tar.bz2 opensim-SC-2c2f10e156c62aa1d95923ff5309f2be7f08faeb.tar.xz |
* Establish OnOarFileSaved EventManager event and subscribe to that instead of passing in a waithandle to the archiver
* This matches the existing OnOarFileLoaded event
* This brings up the question of how these things can be made generic so that they don't have to be tied into EventManager, but that's a topic for another day
7 files changed, 65 insertions, 36 deletions
diff --git a/OpenSim/Region/Environment/Interfaces/IRegionArchiverModule.cs b/OpenSim/Region/Environment/Interfaces/IRegionArchiverModule.cs index d9f8c08..559d2a6 100644 --- a/OpenSim/Region/Environment/Interfaces/IRegionArchiverModule.cs +++ b/OpenSim/Region/Environment/Interfaces/IRegionArchiverModule.cs | |||
@@ -26,7 +26,6 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.IO; | 28 | using System.IO; |
29 | using System.Threading; | ||
30 | 29 | ||
31 | namespace OpenSim.Region.Environment.Interfaces | 30 | namespace OpenSim.Region.Environment.Interfaces |
32 | { | 31 | { |
@@ -38,6 +37,10 @@ namespace OpenSim.Region.Environment.Interfaces | |||
38 | /// <summary> | 37 | /// <summary> |
39 | /// Archive the region to the given path | 38 | /// Archive the region to the given path |
40 | /// </summary> | 39 | /// </summary> |
40 | /// | ||
41 | /// This method occurs asynchronously. If you want notification of when it has completed then subscribe to | ||
42 | /// the EventManager.OnOarFileSaved event. | ||
43 | /// | ||
41 | /// <param name="savePath"></param> | 44 | /// <param name="savePath"></param> |
42 | void ArchiveRegion(string savePath); | 45 | void ArchiveRegion(string savePath); |
43 | 46 | ||
@@ -45,21 +48,27 @@ namespace OpenSim.Region.Environment.Interfaces | |||
45 | /// Archive the region to a stream. | 48 | /// Archive the region to a stream. |
46 | /// </summary> | 49 | /// </summary> |
47 | /// | 50 | /// |
51 | /// This method occurs asynchronously. If you want notification of when it has completed then subscribe to | ||
52 | /// the EventManager.OnOarFileSaved event. | ||
53 | /// | ||
48 | /// <param name="saveStream"></param> | 54 | /// <param name="saveStream"></param> |
49 | /// <param name="waitHandle"> | 55 | void ArchiveRegion(Stream saveStream); |
50 | /// Pass in a wait handle if you want to be signalled when the operation completes. | ||
51 | /// </param> | ||
52 | void ArchiveRegion(Stream saveStream, EventWaitHandle waitHandle); | ||
53 | 56 | ||
54 | /// <summary> | 57 | /// <summary> |
55 | /// Dearchive the given region archive into the scene | 58 | /// Dearchive the given region archive into the scene |
56 | /// </summary> | 59 | /// </summary> |
60 | /// | ||
61 | /// If you want notification of when it has completed then subscribe to the EventManager.OnOarFileLoaded event. | ||
62 | /// | ||
57 | /// <param name="loadPath"></param> | 63 | /// <param name="loadPath"></param> |
58 | void DearchiveRegion(string loadPath); | 64 | void DearchiveRegion(string loadPath); |
59 | 65 | ||
60 | /// <summary> | 66 | /// <summary> |
61 | /// Dearchive a region from a stream | 67 | /// Dearchive a region from a stream. |
62 | /// </summary> | 68 | /// </summary> |
69 | /// | ||
70 | /// If you want notification of when it has completed then subscribe to the EventManager.OnOarFileLoaded event. | ||
71 | /// | ||
63 | /// <param name="loadStream"></param> | 72 | /// <param name="loadStream"></param> |
64 | void DearchiveRegion(Stream loadStream); | 73 | void DearchiveRegion(Stream loadStream); |
65 | } | 74 | } |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs index ee4323c..4e9fcef 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs | |||
@@ -233,8 +233,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
233 | { | 233 | { |
234 | sceneObject.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 0); | 234 | sceneObject.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 0); |
235 | } | 235 | } |
236 | |||
236 | m_scene.EventManager.TriggerOarFileLoaded(m_errorMessage); | 237 | m_scene.EventManager.TriggerOarFileLoaded(m_errorMessage); |
237 | |||
238 | } | 238 | } |
239 | 239 | ||
240 | /// <summary> | 240 | /// <summary> |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs index 8eec38d..179b82a 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs | |||
@@ -29,7 +29,6 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Threading; | ||
33 | using System.Xml; | 32 | using System.Xml; |
34 | using OpenMetaverse; | 33 | using OpenMetaverse; |
35 | using log4net; | 34 | using log4net; |
@@ -45,7 +44,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
45 | /// Method called when all the necessary assets for an archive request have been received. | 44 | /// Method called when all the necessary assets for an archive request have been received. |
46 | /// </summary> | 45 | /// </summary> |
47 | public delegate void AssetsRequestCallback(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids); | 46 | public delegate void AssetsRequestCallback(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids); |
48 | 47 | ||
49 | /// <summary> | 48 | /// <summary> |
50 | /// Execute the write of an archive once we have received all the necessary data | 49 | /// Execute the write of an archive once we have received all the necessary data |
51 | /// </summary> | 50 | /// </summary> |
@@ -56,27 +55,25 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
56 | protected ITerrainModule m_terrainModule; | 55 | protected ITerrainModule m_terrainModule; |
57 | protected IRegionSerialiserModule m_serialiser; | 56 | protected IRegionSerialiserModule m_serialiser; |
58 | protected List<SceneObjectGroup> m_sceneObjects; | 57 | protected List<SceneObjectGroup> m_sceneObjects; |
59 | protected RegionInfo m_regionInfo; | 58 | protected Scene m_scene; |
60 | protected Stream m_saveStream; | 59 | protected Stream m_saveStream; |
61 | protected EventWaitHandle m_signalWhenDoneEvent; | ||
62 | 60 | ||
63 | public ArchiveWriteRequestExecution( | 61 | public ArchiveWriteRequestExecution( |
64 | List<SceneObjectGroup> sceneObjects, | 62 | List<SceneObjectGroup> sceneObjects, |
65 | ITerrainModule terrainModule, | 63 | ITerrainModule terrainModule, |
66 | IRegionSerialiserModule serialiser, | 64 | IRegionSerialiserModule serialiser, |
67 | RegionInfo regionInfo, | 65 | Scene scene, |
68 | Stream saveStream, | 66 | Stream saveStream) |
69 | EventWaitHandle signalWhenDoneEvent) | ||
70 | { | 67 | { |
71 | m_sceneObjects = sceneObjects; | 68 | m_sceneObjects = sceneObjects; |
72 | m_terrainModule = terrainModule; | 69 | m_terrainModule = terrainModule; |
73 | m_serialiser = serialiser; | 70 | m_serialiser = serialiser; |
74 | m_regionInfo = regionInfo; | 71 | m_scene = scene; |
75 | m_saveStream = saveStream; | 72 | m_saveStream = saveStream; |
76 | m_signalWhenDoneEvent = signalWhenDoneEvent; | ||
77 | } | 73 | } |
78 | 74 | ||
79 | protected internal void ReceivedAllAssets(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids) | 75 | protected internal void ReceivedAllAssets( |
76 | IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids) | ||
80 | { | 77 | { |
81 | foreach (UUID uuid in assetsNotFoundUuids) | 78 | foreach (UUID uuid in assetsNotFoundUuids) |
82 | { | 79 | { |
@@ -95,11 +92,14 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
95 | archive.AddFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p2ControlFile()); | 92 | archive.AddFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p2ControlFile()); |
96 | 93 | ||
97 | // Write out region settings | 94 | // Write out region settings |
98 | string settingsPath = String.Format("{0}{1}.xml", ArchiveConstants.SETTINGS_PATH, m_regionInfo.RegionName); | 95 | string settingsPath |
99 | archive.AddFile(settingsPath, RegionSettingsSerializer.Serialize(m_regionInfo.RegionSettings)); | 96 | = String.Format("{0}{1}.xml", ArchiveConstants.SETTINGS_PATH, m_scene.RegionInfo.RegionName); |
97 | archive.AddFile(settingsPath, RegionSettingsSerializer.Serialize(m_scene.RegionInfo.RegionSettings)); | ||
100 | 98 | ||
101 | // Write out terrain | 99 | // Write out terrain |
102 | string terrainPath = String.Format("{0}{1}.r32", ArchiveConstants.TERRAINS_PATH, m_regionInfo.RegionName); | 100 | string terrainPath |
101 | = String.Format("{0}{1}.r32", ArchiveConstants.TERRAINS_PATH, m_scene.RegionInfo.RegionName); | ||
102 | |||
103 | MemoryStream ms = new MemoryStream(); | 103 | MemoryStream ms = new MemoryStream(); |
104 | m_terrainModule.SaveToStream(terrainPath, ms); | 104 | m_terrainModule.SaveToStream(terrainPath, ms); |
105 | archive.AddFile(terrainPath, ms.ToArray()); | 105 | archive.AddFile(terrainPath, ms.ToArray()); |
@@ -129,10 +129,9 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
129 | 129 | ||
130 | archive.WriteTar(m_saveStream); | 130 | archive.WriteTar(m_saveStream); |
131 | 131 | ||
132 | m_log.InfoFormat("[ARCHIVER]: Wrote out OpenSimulator archive for {0}", m_regionInfo.RegionName); | 132 | m_log.InfoFormat("[ARCHIVER]: Wrote out OpenSimulator archive for {0}", m_scene.RegionInfo.RegionName); |
133 | 133 | ||
134 | if (m_signalWhenDoneEvent != null) | 134 | m_scene.EventManager.TriggerOarFileSaved(String.Empty); |
135 | m_signalWhenDoneEvent.Set(); | ||
136 | } | 135 | } |
137 | 136 | ||
138 | /// <summary> | 137 | /// <summary> |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs index b3c9a91..a5f4770 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestPreparation.cs | |||
@@ -53,7 +53,6 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
53 | 53 | ||
54 | protected Scene m_scene; | 54 | protected Scene m_scene; |
55 | protected Stream m_saveStream; | 55 | protected Stream m_saveStream; |
56 | protected EventWaitHandle m_signalWhenDoneEvent; | ||
57 | 56 | ||
58 | /// <summary> | 57 | /// <summary> |
59 | /// Used as a temporary store of an asset which represents an object. This can be a null if no appropriate | 58 | /// Used as a temporary store of an asset which represents an object. This can be a null if no appropriate |
@@ -80,11 +79,10 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
80 | /// </summary> | 79 | /// </summary> |
81 | /// <param name="scene"></param> | 80 | /// <param name="scene"></param> |
82 | /// <param name="saveStream">The stream to which to save data.</param> | 81 | /// <param name="saveStream">The stream to which to save data.</param> |
83 | public ArchiveWriteRequestPreparation(Scene scene, Stream saveStream, EventWaitHandle signalWhenDoneEvent) | 82 | public ArchiveWriteRequestPreparation(Scene scene, Stream saveStream) |
84 | { | 83 | { |
85 | m_scene = scene; | 84 | m_scene = scene; |
86 | m_saveStream = saveStream; | 85 | m_saveStream = saveStream; |
87 | m_signalWhenDoneEvent = signalWhenDoneEvent; | ||
88 | } | 86 | } |
89 | 87 | ||
90 | /// <summary> | 88 | /// <summary> |
@@ -326,9 +324,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
326 | sceneObjects, | 324 | sceneObjects, |
327 | m_scene.RequestModuleInterface<ITerrainModule>(), | 325 | m_scene.RequestModuleInterface<ITerrainModule>(), |
328 | m_scene.RequestModuleInterface<IRegionSerialiserModule>(), | 326 | m_scene.RequestModuleInterface<IRegionSerialiserModule>(), |
329 | m_scene.RegionInfo, | 327 | m_scene, |
330 | m_saveStream, | 328 | m_saveStream); |
331 | m_signalWhenDoneEvent); | ||
332 | 329 | ||
333 | new AssetsRequest(assetUuids.Keys, m_scene.AssetCache, awre.ReceivedAllAssets).Execute(); | 330 | new AssetsRequest(assetUuids.Keys, m_scene.AssetCache, awre.ReceivedAllAssets).Execute(); |
334 | } | 331 | } |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs index e3dfda2..9d9f81e 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs | |||
@@ -73,9 +73,9 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
73 | new ArchiveWriteRequestPreparation(m_scene, savePath).ArchiveRegion(); | 73 | new ArchiveWriteRequestPreparation(m_scene, savePath).ArchiveRegion(); |
74 | } | 74 | } |
75 | 75 | ||
76 | public void ArchiveRegion(Stream saveStream, EventWaitHandle waitHandle) | 76 | public void ArchiveRegion(Stream saveStream) |
77 | { | 77 | { |
78 | new ArchiveWriteRequestPreparation(m_scene, saveStream, waitHandle).ArchiveRegion(); | 78 | new ArchiveWriteRequestPreparation(m_scene, saveStream).ArchiveRegion(); |
79 | } | 79 | } |
80 | 80 | ||
81 | public void DearchiveRegion(string loadPath) | 81 | public void DearchiveRegion(string loadPath) |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/Environment/Modules/World/Archiver/Tests/ArchiverTests.cs index 95064e2..43df685 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/Tests/ArchiverTests.cs | |||
@@ -44,13 +44,20 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver.Tests | |||
44 | [TestFixture] | 44 | [TestFixture] |
45 | public class ArchiverTests | 45 | public class ArchiverTests |
46 | { | 46 | { |
47 | private EventWaitHandle m_waitHandle = new AutoResetEvent(false); | ||
48 | |||
49 | private void SaveCompleted(string errorMessage) | ||
50 | { | ||
51 | m_waitHandle.Set(); | ||
52 | } | ||
53 | |||
47 | /// <summary> | 54 | /// <summary> |
48 | /// Test saving a V0.2 OpenSim Region Archive. | 55 | /// Test saving a V0.2 OpenSim Region Archive. |
49 | /// </summary> | 56 | /// </summary> |
50 | [Test] | 57 | [Test] |
51 | public void TestSaveOarV0p2() | 58 | public void TestSaveOarV0p2() |
52 | { | 59 | { |
53 | //log4net.Config.XmlConfigurator.Configure(); | 60 | log4net.Config.XmlConfigurator.Configure(); |
54 | 61 | ||
55 | ArchiverModule archiverModule = new ArchiverModule(); | 62 | ArchiverModule archiverModule = new ArchiverModule(); |
56 | SerialiserModule serialiserModule = new SerialiserModule(); | 63 | SerialiserModule serialiserModule = new SerialiserModule(); |
@@ -71,11 +78,12 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver.Tests | |||
71 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | 78 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); |
72 | part.Name = partName; | 79 | part.Name = partName; |
73 | 80 | ||
74 | scene.AddNewSceneObject(new SceneObjectGroup(part), false); | 81 | scene.AddNewSceneObject(new SceneObjectGroup(part), false); |
75 | EventWaitHandle waitHandle = new ManualResetEvent(false); | ||
76 | MemoryStream archiveWriteStream = new MemoryStream(); | 82 | MemoryStream archiveWriteStream = new MemoryStream(); |
77 | archiverModule.ArchiveRegion(archiveWriteStream, waitHandle); | 83 | |
78 | waitHandle.WaitOne(60000, true); | 84 | scene.EventManager.OnOarFileSaved += SaveCompleted; |
85 | archiverModule.ArchiveRegion(archiveWriteStream); | ||
86 | m_waitHandle.WaitOne(60000, true); | ||
79 | 87 | ||
80 | byte[] archive = archiveWriteStream.ToArray(); | 88 | byte[] archive = archiveWriteStream.ToArray(); |
81 | MemoryStream archiveReadStream = new MemoryStream(archive); | 89 | MemoryStream archiveReadStream = new MemoryStream(archive); |
diff --git a/OpenSim/Region/Environment/Scenes/EventManager.cs b/OpenSim/Region/Environment/Scenes/EventManager.cs index 1543bf0..618e6b5 100644 --- a/OpenSim/Region/Environment/Scenes/EventManager.cs +++ b/OpenSim/Region/Environment/Scenes/EventManager.cs | |||
@@ -273,6 +273,13 @@ namespace OpenSim.Region.Environment.Scenes | |||
273 | /// </summary> | 273 | /// </summary> |
274 | public delegate void OarFileLoaded(string message); | 274 | public delegate void OarFileLoaded(string message); |
275 | public event OarFileLoaded OnOarFileLoaded; | 275 | public event OarFileLoaded OnOarFileLoaded; |
276 | |||
277 | /// <summary> | ||
278 | /// Called when an oar file has finished saving | ||
279 | /// Message is non empty string if there were problems saving the oar file | ||
280 | /// </summary> | ||
281 | public delegate void OarFileSaved(string message); | ||
282 | public event OarFileSaved OnOarFileSaved; | ||
276 | 283 | ||
277 | /// <summary> | 284 | /// <summary> |
278 | /// Called when the script compile queue becomes empty | 285 | /// Called when the script compile queue becomes empty |
@@ -415,6 +422,8 @@ namespace OpenSim.Region.Environment.Scenes | |||
415 | private OnSetRootAgentSceneDelegate handlerSetRootAgentScene = null; | 422 | private OnSetRootAgentSceneDelegate handlerSetRootAgentScene = null; |
416 | 423 | ||
417 | private OarFileLoaded handlerOarFileLoaded = null; | 424 | private OarFileLoaded handlerOarFileLoaded = null; |
425 | private OarFileSaved handlerOarFileSaved = null; | ||
426 | |||
418 | private EmptyScriptCompileQueue handlerEmptyScriptCompileQueue = null; | 427 | private EmptyScriptCompileQueue handlerEmptyScriptCompileQueue = null; |
419 | 428 | ||
420 | public void TriggerGetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) | 429 | public void TriggerGetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) |
@@ -925,6 +934,13 @@ namespace OpenSim.Region.Environment.Scenes | |||
925 | if (handlerOarFileLoaded != null) | 934 | if (handlerOarFileLoaded != null) |
926 | handlerOarFileLoaded(message); | 935 | handlerOarFileLoaded(message); |
927 | } | 936 | } |
937 | |||
938 | public void TriggerOarFileSaved(string message) | ||
939 | { | ||
940 | handlerOarFileSaved = OnOarFileSaved; | ||
941 | if (handlerOarFileSaved != null) | ||
942 | handlerOarFileSaved(message); | ||
943 | } | ||
928 | 944 | ||
929 | public void TriggerEmptyScriptCompileQueue(int numScriptsFailed, string message) | 945 | public void TriggerEmptyScriptCompileQueue(int numScriptsFailed, string message) |
930 | { | 946 | { |