From c82c7e6ed9ecf4858d5afffa635013bd14e90bdf Mon Sep 17 00:00:00 2001 From: Sean McNamara Date: Tue, 26 Apr 2011 11:42:06 -0400 Subject: [PATCH] Wait for OnOarFileSaved event callback before executing script We want to execute the (optional) user script after I/O is done on the oar. I wasn't aware that ArchiveRegion is asynchronous -- now I am. Should fully resolve comment 0018290 at http://opensimulator.org/mantis/view.php?id=5440 --- .../World/AutoBackup/AutoBackupModule.cs | 23 ++++++++++++------- .../World/AutoBackup/AutoBackupModuleState.cs | 14 +++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs index 7c0a5c6c57..bd4893c08e 100644 --- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs +++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs @@ -94,18 +94,14 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - /// True means IRegionModuleBase.Close() was called on us, and we should stop operation ASAP. - /// Used to prevent elapsing timers after Close() is called from trying to start an autobackup while the sim is shutting down. - private readonly AutoBackupModuleState m_defaultState = new AutoBackupModuleState(); - /// Save memory by setting low initial capacities. Minimizes impact in common cases of all regions using same interval, and instances hosting 1 ~ 4 regions. /// Also helps if you don't want AutoBackup at all + private readonly Dictionary m_pendingSaves = new Dictionary(1); + private readonly AutoBackupModuleState m_defaultState = new AutoBackupModuleState(); private readonly Dictionary m_states = new Dictionary(1); - private readonly Dictionary> m_timerMap = new Dictionary>(1); - private readonly Dictionary m_timers = new Dictionary(1); private bool m_enabled; @@ -528,8 +524,19 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup m_log.Warn("[AUTO BACKUP]: savePath is null in HandleElapsed"); return; } - iram.ArchiveRegion(savePath, Guid.NewGuid(), null); - ExecuteScript(state.Script, savePath); + Guid guid = Guid.NewGuid(); + m_pendingSaves.Add(guid, scene); + state.LiveRequests.Add(guid, savePath); + ((Scene) scene).EventManager.OnOarFileSaved += new EventManager.OarFileSaved(EventManager_OnOarFileSaved); + iram.ArchiveRegion(savePath, guid, null); + } + + void EventManager_OnOarFileSaved(Guid guid, string message) + { + AutoBackupModuleState abms = m_states[(m_pendingSaves[guid])]; + ExecuteScript(abms.Script, abms.LiveRequests[guid]); + m_pendingSaves.Remove(guid); + abms.LiveRequests.Remove(guid); } /// This format may turn out to be too unwieldy to keep... diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs index 1b348af5eb..7fecfa435a 100644 --- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs +++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs @@ -26,11 +26,17 @@ /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// +using System; +using System.Collections.Generic; + + namespace OpenSim.Region.OptionalModules.World.AutoBackup { /// AutoBackupModuleState: Auto-Backup state for one region (scene). public class AutoBackupModuleState { + private Dictionary m_liveRequests = null; + public AutoBackupModuleState() { this.Enabled = false; @@ -41,6 +47,14 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup this.Script = null; } + public Dictionary LiveRequests + { + get { + return this.m_liveRequests ?? + (this.m_liveRequests = new Dictionary(1)); + } + } + public bool Enabled { get;