From 837a77b24ac805dbbfb7a28d6ac9e8767444161d Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Wed, 5 Jan 2011 15:32:43 -0800 Subject: [PATCH] Abandoned the previous temporary solution of propogating events. Instead, rename legacy (Scene)EventManager as EventManagerBase, and implement a new EventManager, to enable handling local/remote events differently. Handlers for UpdateScript has been implemented as a sample case. --- .../SymmetricSync/RegionSyncModule.cs | 44 +++++++++--- .../SymmetricSync/ScriptEngineSyncModule.cs | 2 +- .../SymmetricSync/SymmetricSyncMessage.cs | 2 +- .../Framework/Interfaces/IRegionSyncModule.cs | 5 +- .../Region/Framework/Scenes/EventManager.cs | 69 ++++++++++++------- OpenSim/Region/Framework/Scenes/Scene.cs | 11 ++- 6 files changed, 93 insertions(+), 40 deletions(-) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index 4d675512af..edeab2e66a 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -87,12 +87,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; InstallInterfaces(); - //Register for Scene events + //Register for local Scene events m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation; m_scene.EventManager.OnObjectBeingRemovedFromScene += new EventManager.ObjectBeingRemovedFromScene(RegionSyncModule_OnObjectBeingRemovedFromScene); - //Register for scene events that need to be propogated to other actors - m_scene.EventManager.OnUpdateScript += RegionSyncModule_OnUpdateScript; } //Called after AddRegion() has been called for all region modules of the scene @@ -842,9 +840,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule return; } //EVENTS PROCESSING - case SymmetricSyncMessage.MsgType.OnUpdateScript: + case SymmetricSyncMessage.MsgType.UpdateScript: { - HandleEvent_OnUpdateScript(msg); + HandleRemoteEvent_OnUpdateScript(msg); return; } default: @@ -980,7 +978,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule /// Handler for SymmetricSyncMessage.MsgType.OnUpdateScript /// /// - private void HandleEvent_OnUpdateScript(SymmetricSyncMessage msg) + private void HandleRemoteEvent_OnUpdateScript(SymmetricSyncMessage msg) { m_log.Debug(LogHeader + ", " + m_actorID + ": received OnUpdateScript"); @@ -993,10 +991,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule UUID primID = data["primID"].AsUUID(); bool isRunning = data["running"].AsBoolean(); UUID assetID = data["assetID"].AsUUID(); - //m_scene.EventManager.TriggerUpdateScript(agentID, itemID, primID, isRunning, assetID); + m_scene.EventManager.TriggerUpdateScriptLocally(agentID, itemID, primID, isRunning, assetID); //trigger the OnUpdateScriptBySync event, so that the handler of the event knows it is event initiated remotely - m_scene.EventManager.TriggerOnUpdateScriptBySync(agentID, itemID, primID, isRunning, assetID); + //m_scene.EventManager.TriggerOnUpdateScriptBySync(agentID, itemID, primID, isRunning, assetID); //if this is a relay node, forwards the event @@ -1031,6 +1029,24 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } + public void PublishSceneEvent(EventManager.EventNames ev, Object[] evArgs) + { + switch (ev) + { + case EventManager.EventNames.UpdateScript: + if (evArgs.Length < 5) + { + m_log.Error(LogHeader + " not enough event args for UpdateScript"); + return; + } + m_log.Debug(LogHeader + " PublishSceneEvent UpdateScript"); + OnLocalUpdateScript((UUID)evArgs[0], (UUID)evArgs[1], (UUID)evArgs[2], (bool)evArgs[3], (UUID)evArgs[4]); + return; + default: + return; + } + } + /// /// The handler for (locally initiated) event OnUpdateScript: publish it to other actors. /// @@ -1039,7 +1055,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule /// /// /// - public void RegionSyncModule_OnUpdateScript(UUID agentID, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) + private void OnLocalUpdateScript(UUID agentID, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) { m_log.Debug(LogHeader + " RegionSyncModule_OnUpdateScript"); @@ -1050,9 +1066,16 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule data["running"] = OSD.FromBoolean(isScriptRunning); data["assetID"] = OSD.FromUUID(newAssetID); - PublishSceneEvent(data); + data["actorID"] = OSD.FromString(m_actorID); + data["seqNum"] = OSD.FromULong(GetNextEventSeq()); + + SymmetricSyncMessage rsm = new SymmetricSyncMessage(SymmetricSyncMessage.MsgType.UpdateScript, OSDParser.SerializeJsonString(data)); + //send to actors who are interested in the event + SendSceneEventToRelevantSyncConnectors(m_actorID, rsm); } + + /* private void PublishSceneEvent(OSDMap data) { data["actorID"] = OSD.FromString(m_actorID); @@ -1061,6 +1084,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule SymmetricSyncMessage rsm = new SymmetricSyncMessage(SymmetricSyncMessage.MsgType.OnUpdateScript, OSDParser.SerializeJsonString(data)); SendSceneEventToRelevantSyncConnectors(m_actorID, rsm); } + * */ private ulong GetNextEventSeq() { diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs index 78471fb764..cc9213b722 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs @@ -90,7 +90,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //for local OnUpdateScript, we'll handle it the same way as a remove OnUpdateScript. //RegionSyncModule will capture a locally initiated OnUpdateScript event and publish it to other actors. m_scene.EventManager.OnUpdateScript += ScriptEngine_OnUpdateScript; - m_scene.EventManager.OnUpdateScriptBySync += ScriptEngine_OnUpdateScript; + //m_scene.EventManager.OnUpdateScriptBySync += ScriptEngine_OnUpdateScript; } //Called after AddRegion() has been called for all region modules of the scene. diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs index 4785992374..d8d925147a 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs @@ -34,7 +34,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //RegionStatus, ActorID, //events - OnUpdateScript, + UpdateScript, } #endregion diff --git a/OpenSim/Region/Framework/Interfaces/IRegionSyncModule.cs b/OpenSim/Region/Framework/Interfaces/IRegionSyncModule.cs index 2cc75c962d..8733f8ec6d 100755 --- a/OpenSim/Region/Framework/Interfaces/IRegionSyncModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IRegionSyncModule.cs @@ -26,7 +26,7 @@ */ //KittyL: Added to support running script engine actor - +using System; using System.Collections.Generic; using OpenMetaverse; @@ -65,6 +65,9 @@ namespace OpenSim.Region.Framework.Interfaces void SendTerrainUpdates(string lastUpdateActorID); //void SendDeleteObject(SceneObjectGroup sog); + //For propogating scene events to other actors + void PublishSceneEvent(EventManager.EventNames ev, Object[] evArgs); + //TODO LIST: //Special API for handling avatars //void QueuePresenceForTerseUpdate(ScenePresence presence) diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 08f56cece9..c178f563c3 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -41,9 +41,50 @@ namespace OpenSim.Region.Framework.Scenes //SYMMETRIC SYNC: Rename the original EventManager as EventManagerBase, and implement a new EventManager that inherits from EventManagerBase /// - /// A class for triggering remote scene events. + /// A wrapper class to implement handle event differently depending on if they are initiated locally or remotelly (i.e. by another actor) /// - public class EventManager + public class EventManager: EventManagerBase + { + private Scene m_scene; + + //the events that we'll handle specially in sym-sync + public enum EventNames + { + UpdateScript, + } + + public EventManager(Scene scene) + { + m_scene = scene; + } + public override void TriggerUpdateScript(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) + { + //publish the event to other actors who are intersted in it + if (m_scene.RegionSyncModule != null) + { + Object[] eventArgs = new Object[5]; + eventArgs[0] = (Object) clientId; + eventArgs[1] = (Object)itemId; + eventArgs[2] = (Object)primId; + eventArgs[3] = (Object)isScriptRunning; + eventArgs[4] = (Object)newAssetID; + m_scene.RegionSyncModule.PublishSceneEvent(EventNames.UpdateScript, eventArgs); + } + + //trigger event locally, as the legacy code does + TriggerUpdateScriptLocally(clientId, itemId, primId, isScriptRunning, newAssetID); + } + + public void TriggerUpdateScriptLocally(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) + { + base.TriggerUpdateScript(clientId, itemId, primId, isScriptRunning, newAssetID); + } + } + + /// + /// A class for triggering scene events. + /// + public class EventManagerBase { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -2195,7 +2236,7 @@ namespace OpenSim.Region.Framework.Scenes //OnUpdateTaskInventoryScriptAsset: triggered after Scene receives client's upload of updated script and stores it as asset public delegate void UpdateScript(UUID clientID, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID); public event UpdateScript OnUpdateScript; - public void TriggerUpdateScript(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) + public virtual void TriggerUpdateScript(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) { UpdateScript handlerUpdateScript = OnUpdateScript; if (handlerUpdateScript != null) @@ -2292,28 +2333,6 @@ namespace OpenSim.Region.Framework.Scenes } } - public event UpdateScriptBySync OnUpdateScriptBySync; - public delegate void UpdateScriptBySync(UUID agentID, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID); - public void TriggerOnUpdateScriptBySync(UUID agentID, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID) - { - UpdateScriptBySync handlerUpdateScriptBySync = OnUpdateScriptBySync; - if (handlerUpdateScriptBySync != null) - { - foreach (UpdateScriptBySync d in handlerUpdateScriptBySync.GetInvocationList()) - { - try - { - d(agentID, itemId, primId, isScriptRunning, newAssetID); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[EVENT MANAGER]: Delegate for TriggerOnUpdateScriptBySync failed - continuing. {0} {1}", - e.Message, e.StackTrace); - } - } - } - } //end of SYMMETRIC SYNC } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 95ecfb3d5f..33abe9e0e9 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -821,7 +821,10 @@ namespace OpenSim.Region.Framework.Scenes m_physicalPrim = physicalPrim; m_seeIntoRegionFromNeighbor = SeeIntoRegionFromNeighbor; - m_eventManager = new EventManager(); + //SYMMETRIC SYNC: pass Scene reference to EventManager + //m_eventManager = new EventManager(); + m_eventManager = new EventManager(this); + //end of SYMMETRIC SYNC m_permissions = new ScenePermissions(this); m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); @@ -1029,7 +1032,11 @@ namespace OpenSim.Region.Framework.Scenes BordersLocked = false; m_regInfo = regInfo; - m_eventManager = new EventManager(); + + //SYMMETRIC SYNC: pass Scene reference to EventManager + //m_eventManager = new EventManager(); + m_eventManager = new EventManager(this); + //end of SYMMETRIC SYNC m_lastUpdate = Util.EnvironmentTickCount(); }