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
bulletsim
Sean McNamara 2011-04-26 11:42:06 -04:00
parent d287e0ac68
commit c82c7e6ed9
2 changed files with 29 additions and 8 deletions

View File

@ -94,18 +94,14 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 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. /// 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 /// Also helps if you don't want AutoBackup at all
private readonly Dictionary<Guid, IScene> m_pendingSaves = new Dictionary<Guid, IScene>(1);
private readonly AutoBackupModuleState m_defaultState = new AutoBackupModuleState();
private readonly Dictionary<IScene, AutoBackupModuleState> m_states = private readonly Dictionary<IScene, AutoBackupModuleState> m_states =
new Dictionary<IScene, AutoBackupModuleState>(1); new Dictionary<IScene, AutoBackupModuleState>(1);
private readonly Dictionary<Timer, List<IScene>> m_timerMap = private readonly Dictionary<Timer, List<IScene>> m_timerMap =
new Dictionary<Timer, List<IScene>>(1); new Dictionary<Timer, List<IScene>>(1);
private readonly Dictionary<double, Timer> m_timers = new Dictionary<double, Timer>(1); private readonly Dictionary<double, Timer> m_timers = new Dictionary<double, Timer>(1);
private bool m_enabled; private bool m_enabled;
@ -528,8 +524,19 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
m_log.Warn("[AUTO BACKUP]: savePath is null in HandleElapsed"); m_log.Warn("[AUTO BACKUP]: savePath is null in HandleElapsed");
return; return;
} }
iram.ArchiveRegion(savePath, Guid.NewGuid(), null); Guid guid = Guid.NewGuid();
ExecuteScript(state.Script, savePath); 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... /// This format may turn out to be too unwieldy to keep...

View File

@ -26,11 +26,17 @@
/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// ///
using System;
using System.Collections.Generic;
namespace OpenSim.Region.OptionalModules.World.AutoBackup namespace OpenSim.Region.OptionalModules.World.AutoBackup
{ {
/// AutoBackupModuleState: Auto-Backup state for one region (scene). /// AutoBackupModuleState: Auto-Backup state for one region (scene).
public class AutoBackupModuleState public class AutoBackupModuleState
{ {
private Dictionary<Guid, string> m_liveRequests = null;
public AutoBackupModuleState() public AutoBackupModuleState()
{ {
this.Enabled = false; this.Enabled = false;
@ -41,6 +47,14 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
this.Script = null; this.Script = null;
} }
public Dictionary<Guid, string> LiveRequests
{
get {
return this.m_liveRequests ??
(this.m_liveRequests = new Dictionary<Guid, string>(1));
}
}
public bool Enabled public bool Enabled
{ {
get; get;