Decouple AsyncCommands from XEngine and the script instance. Make

all methods needed outside the API ststic. Async command processing
is now wholly internal to the API. This sets the stage for the next
convergence step.
0.6.0-stable
Melanie Thielker 2008-09-24 02:58:05 +00:00
parent 3f79e6b3e7
commit 218902bedc
8 changed files with 113 additions and 102 deletions

View File

@ -113,6 +113,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
if (c.Channel == DEBUG_CHANNEL) if (c.Channel == DEBUG_CHANNEL)
c.Type = ChatTypeEnum.DebugChannel; c.Type = ChatTypeEnum.DebugChannel;
if (c.Message.Length > 1100)
c.Message = c.Message.Substring(0, 1000);
// chat works by redistributing every incoming chat // chat works by redistributing every incoming chat
// message to each avatar in the scene // message to each avatar in the scene
Vector3 pos = new Vector3(128, 128, 30); Vector3 pos = new Vector3(128, 128, 30);

View File

@ -44,7 +44,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
{ {
Scene World { get; } Scene World { get; }
IConfig Config { get; } IConfig Config { get; }
Object AsyncCommands { get; }
ILog Log { get; } ILog Log { get; }
string ScriptEngineName { get; } string ScriptEngineName { get; }

View File

@ -47,66 +47,86 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
private static Thread cmdHandlerThread; private static Thread cmdHandlerThread;
private static int cmdHandlerThreadCycleSleepms; private static int cmdHandlerThreadCycleSleepms;
private static List<AsyncCommandManager> m_Managers = new List<AsyncCommandManager>(); private static List<IScene> m_Scenes = new List<IScene>();
public IScriptEngine m_ScriptEngine; private static List<IScriptEngine> m_ScriptEngines =
new List<IScriptEngine>();
private Dataserver m_Dataserver; public IScriptEngine m_ScriptEngine;
private Timer m_Timer; private IScene m_Scene;
private HttpRequest m_HttpRequest;
private Listener m_Listener; private static Dictionary<IScene, Dataserver> m_Dataserver =
private SensorRepeat m_SensorRepeat; new Dictionary<IScene, Dataserver>();
private XmlRequest m_XmlRequest; private static Dictionary<IScene, Timer> m_Timer =
new Dictionary<IScene, Timer>();
private static Dictionary<IScene, Listener> m_Listener =
new Dictionary<IScene, Listener>();
private static Dictionary<IScene, HttpRequest> m_HttpRequest =
new Dictionary<IScene, HttpRequest>();
private static Dictionary<IScene, SensorRepeat> m_SensorRepeat =
new Dictionary<IScene, SensorRepeat>();
private static Dictionary<IScene, XmlRequest> m_XmlRequest =
new Dictionary<IScene, XmlRequest>();
public Dataserver DataserverPlugin public Dataserver DataserverPlugin
{ {
get { return m_Dataserver; } get { return m_Dataserver[m_Scene]; }
} }
public Timer TimerPlugin public Timer TimerPlugin
{ {
get { return m_Timer; } get { return m_Timer[m_Scene]; }
} }
public HttpRequest HttpRequestPlugin public HttpRequest HttpRequestPlugin
{ {
get { return m_HttpRequest; } get { return m_HttpRequest[m_Scene]; }
} }
public Listener ListenerPlugin public Listener ListenerPlugin
{ {
get { return m_Listener; } get { return m_Listener[m_Scene]; }
} }
public SensorRepeat SensorRepeatPlugin public SensorRepeat SensorRepeatPlugin
{ {
get { return m_SensorRepeat; } get { return m_SensorRepeat[m_Scene]; }
} }
public XmlRequest XmlRequestPlugin public XmlRequest XmlRequestPlugin
{ {
get { return m_XmlRequest; } get { return m_XmlRequest[m_Scene]; }
} }
public AsyncCommandManager[] Managers public IScriptEngine[] ScriptEngines
{ {
get { return m_Managers.ToArray(); } get { return m_ScriptEngines.ToArray(); }
} }
public AsyncCommandManager(IScriptEngine _ScriptEngine) public AsyncCommandManager(IScriptEngine _ScriptEngine)
{ {
m_ScriptEngine = _ScriptEngine; m_ScriptEngine = _ScriptEngine;
if (!m_Managers.Contains(this)) m_Scene = m_ScriptEngine.World;
m_Managers.Add(this);
if (!m_Scenes.Contains(m_Scene))
m_Scenes.Add(m_Scene);
if (!m_ScriptEngines.Contains(m_ScriptEngine))
m_ScriptEngines.Add(m_ScriptEngine);
ReadConfig(); ReadConfig();
// Create instances of all plugins // Create instances of all plugins
m_Dataserver = new Dataserver(this); if (!m_Dataserver.ContainsKey(m_Scene))
m_Timer = new Timer(this); m_Dataserver[m_Scene] = new Dataserver(this);
m_HttpRequest = new HttpRequest(this); if (!m_Timer.ContainsKey(m_Scene))
m_Listener = new Listener(this); m_Timer[m_Scene] = new Timer(this);
m_SensorRepeat = new SensorRepeat(this); if (!m_HttpRequest.ContainsKey(m_Scene))
m_XmlRequest = new XmlRequest(this); m_HttpRequest[m_Scene] = new HttpRequest(this);
if (!m_Listener.ContainsKey(m_Scene))
m_Listener[m_Scene] = new Listener(this);
if (!m_SensorRepeat.ContainsKey(m_Scene))
m_SensorRepeat[m_Scene] = new SensorRepeat(this);
if (!m_XmlRequest.ContainsKey(m_Scene))
m_XmlRequest[m_Scene] = new XmlRequest(this);
StartThread(); StartThread();
} }
@ -127,26 +147,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void ReadConfig() public void ReadConfig()
{ {
cmdHandlerThreadCycleSleepms = m_ScriptEngine.Config.GetInt("AsyncLLCommandLoopms", 100); // cmdHandlerThreadCycleSleepms = m_ScriptEngine.Config.GetInt("AsyncLLCommandLoopms", 100);
// TODO: Make this sane again
cmdHandlerThreadCycleSleepms = 100;
} }
~AsyncCommandManager() ~AsyncCommandManager()
{ {
// Shut down thread // Shut down thread
try // try
{ // {
if (cmdHandlerThread != null) // if (cmdHandlerThread != null)
{ // {
if (cmdHandlerThread.IsAlive == true) // if (cmdHandlerThread.IsAlive == true)
{ // {
cmdHandlerThread.Abort(); // cmdHandlerThread.Abort();
//cmdHandlerThread.Join(); // //cmdHandlerThread.Join();
} // }
} // }
} // }
catch // catch
{ // {
} // }
} }
/// <summary> /// <summary>
@ -162,10 +184,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
Thread.Sleep(cmdHandlerThreadCycleSleepms); Thread.Sleep(cmdHandlerThreadCycleSleepms);
foreach (AsyncCommandManager m in m_Managers) DoOneCmdHandlerPass();
{
m.DoOneCmdHandlerPass();
}
} }
} }
catch catch
@ -174,20 +193,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
} }
public void DoOneCmdHandlerPass() private static void DoOneCmdHandlerPass()
{
foreach (IScene s in m_Scenes)
{ {
// Check timers // Check timers
m_Timer.CheckTimerEvents(); m_Timer[s].CheckTimerEvents();
// Check HttpRequests // Check HttpRequests
m_HttpRequest.CheckHttpRequests(); m_HttpRequest[s].CheckHttpRequests();
// Check XMLRPCRequests // Check XMLRPCRequests
m_XmlRequest.CheckXMLRPCRequests(); m_XmlRequest[s].CheckXMLRPCRequests();
// Check Listeners // Check Listeners
m_Listener.CheckListeners(); m_Listener[s].CheckListeners();
// Check Sensors // Check Sensors
m_SensorRepeat.CheckSenseRepeaterEvents(); m_SensorRepeat[s].CheckSenseRepeaterEvents();
// Check dataserver // Check dataserver
m_Dataserver.ExpireRequests(); m_Dataserver[s].ExpireRequests();
}
} }
/// <summary> /// <summary>
@ -195,38 +217,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// </summary> /// </summary>
/// <param name="localID"></param> /// <param name="localID"></param>
/// <param name="itemID"></param> /// <param name="itemID"></param>
public void RemoveScript(uint localID, UUID itemID) public static void RemoveScript(IScene scene, uint localID, UUID itemID)
{ {
// Remove a specific script // Remove a specific script
// Remove dataserver events // Remove dataserver events
m_Dataserver.RemoveEvents(localID, itemID); m_Dataserver[scene].RemoveEvents(localID, itemID);
// Remove from: Timers // Remove from: Timers
m_Timer.UnSetTimerEvents(localID, itemID); m_Timer[scene].UnSetTimerEvents(localID, itemID);
// Remove from: HttpRequest // Remove from: HttpRequest
IHttpRequests iHttpReq = IHttpRequests iHttpReq =
m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>(); scene.RequestModuleInterface<IHttpRequests>();
iHttpReq.StopHttpRequest(localID, itemID); iHttpReq.StopHttpRequest(localID, itemID);
IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); IWorldComm comms = scene.RequestModuleInterface<IWorldComm>();
comms.DeleteListener(itemID); comms.DeleteListener(itemID);
IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); IXMLRPC xmlrpc = scene.RequestModuleInterface<IXMLRPC>();
xmlrpc.DeleteChannels(itemID); xmlrpc.DeleteChannels(itemID);
xmlrpc.CancelSRDRequests(itemID); xmlrpc.CancelSRDRequests(itemID);
// Remove Sensors // Remove Sensors
m_SensorRepeat.UnSetSenseRepeaterEvents(localID, itemID); m_SensorRepeat[scene].UnSetSenseRepeaterEvents(localID, itemID);
} }
public Object[] GetSerializationData(UUID itemID) public static Object[] GetSerializationData(IScene scene, UUID itemID)
{ {
List<Object> data = new List<Object>(); List<Object> data = new List<Object>();
Object[] listeners=m_Listener.GetSerializationData(itemID); Object[] listeners=m_Listener[scene].GetSerializationData(itemID);
if (listeners.Length > 0) if (listeners.Length > 0)
{ {
data.Add("listener"); data.Add("listener");
@ -234,7 +256,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
data.AddRange(listeners); data.AddRange(listeners);
} }
Object[] timers=m_Timer.GetSerializationData(itemID); Object[] timers=m_Timer[scene].GetSerializationData(itemID);
if (timers.Length > 0) if (timers.Length > 0)
{ {
data.Add("timer"); data.Add("timer");
@ -242,7 +264,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
data.AddRange(timers); data.AddRange(timers);
} }
Object[] sensors=m_SensorRepeat.GetSerializationData(itemID); Object[] sensors=m_SensorRepeat[scene].GetSerializationData(itemID);
if (sensors.Length > 0) if (sensors.Length > 0)
{ {
data.Add("sensor"); data.Add("sensor");
@ -253,8 +275,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return data.ToArray(); return data.ToArray();
} }
public void CreateFromData(uint localID, UUID itemID, UUID hostID, public static void CreateFromData(IScene scene, uint localID,
Object[] data) UUID itemID, UUID hostID, Object[] data)
{ {
int idx = 0; int idx = 0;
int len; int len;
@ -275,15 +297,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
switch (type) switch (type)
{ {
case "listener": case "listener":
m_Listener.CreateFromData(localID, itemID, hostID, m_Listener[scene].CreateFromData(localID, itemID,
item); hostID, item);
break; break;
case "timer": case "timer":
m_Timer.CreateFromData(localID, itemID, hostID, item); m_Timer[scene].CreateFromData(localID, itemID,
hostID, item);
break; break;
case "sensor": case "sensor":
m_SensorRepeat.CreateFromData(localID, itemID, hostID, m_SensorRepeat[scene].CreateFromData(localID,
item); itemID, hostID, item);
break; break;
} }
} }

View File

@ -92,7 +92,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_ScriptDistanceFactor = config.Configs["XEngine"]. m_ScriptDistanceFactor = config.Configs["XEngine"].
GetFloat("ScriptDistanceLimitFactor", 1.0f); GetFloat("ScriptDistanceLimitFactor", 1.0f);
AsyncCommands = (AsyncCommandManager)ScriptEngine.AsyncCommands; AsyncCommands = new AsyncCommandManager(ScriptEngine);
} }
private DateTime m_timer = DateTime.Now; private DateTime m_timer = DateTime.Now;

View File

@ -77,9 +77,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(httpInfo.response_body) new LSL_Types.LSLString(httpInfo.response_body)
}; };
foreach (AsyncCommandManager m in m_CmdManager.Managers) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
if (m.m_ScriptEngine.PostObjectEvent(httpInfo.localID, if (e.PostObjectEvent(httpInfo.localID,
new EventParams("http_response", new EventParams("http_response",
resobj, new DetectParams[0]))) resobj, new DetectParams[0])))
break; break;

View File

@ -71,9 +71,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(rInfo.GetStrVal()) new LSL_Types.LSLString(rInfo.GetStrVal())
}; };
foreach (AsyncCommandManager m in m_CmdManager.Managers) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
if (m.m_ScriptEngine.PostScriptEvent( if (e.PostScriptEvent(
rInfo.GetItemID(), new EventParams( rInfo.GetItemID(), new EventParams(
"remote_data", resobj, "remote_data", resobj,
new DetectParams[0]))) new DetectParams[0])))
@ -100,9 +100,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(srdInfo.sdata) new LSL_Types.LSLString(srdInfo.sdata)
}; };
foreach (AsyncCommandManager m in m_CmdManager.Managers) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
if (m.m_ScriptEngine.PostScriptEvent( if (e.PostScriptEvent(
srdInfo.m_itemID, new EventParams( srdInfo.m_itemID, new EventParams(
"remote_data", resobj, "remote_data", resobj,
new DetectParams[0]))) new DetectParams[0])))

View File

@ -246,8 +246,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
ScriptSerializer.Deserialize(xml, this); ScriptSerializer.Deserialize(xml, this);
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; AsyncCommandManager.CreateFromData(m_Engine.World,
async.CreateFromData(
m_LocalID, m_ItemID, m_ObjectID, m_LocalID, m_ItemID, m_ObjectID,
PluginData); PluginData);
@ -337,6 +336,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void DestroyScriptInstance() public void DestroyScriptInstance()
{ {
ReleaseControls(); ReleaseControls();
AsyncCommandManager.RemoveScript(m_Engine.World, m_LocalID, m_ItemID);
} }
public void RemoveState() public void RemoveState()
@ -554,8 +554,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
// m_Engine.Log.DebugFormat("[Script] Script {0}.{1} state set to {2}", // m_Engine.Log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
// m_PrimName, m_ScriptName, data.Params[0].ToString()); // m_PrimName, m_ScriptName, data.Params[0].ToString());
m_State=data.Params[0].ToString(); m_State=data.Params[0].ToString();
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; AsyncCommandManager.RemoveScript(m_Engine.World,
async.RemoveScript(
m_LocalID, m_ItemID); m_LocalID, m_ItemID);
SceneObjectPart part = m_Engine.World.GetSceneObjectPart( SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
@ -691,8 +690,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID);
part.GetInventoryItem(m_ItemID).PermsMask = 0; part.GetInventoryItem(m_ItemID).PermsMask = 0;
part.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero; part.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; AsyncCommandManager.RemoveScript(m_Engine.World, m_LocalID, m_ItemID);
async.RemoveScript(m_LocalID, m_ItemID);
m_EventQueue.Clear(); m_EventQueue.Clear();
m_Script.ResetVars(); m_Script.ResetVars();
m_State = "default"; m_State = "default";
@ -717,8 +715,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID);
part.GetInventoryItem(m_ItemID).PermsMask = 0; part.GetInventoryItem(m_ItemID).PermsMask = 0;
part.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero; part.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; AsyncCommandManager.RemoveScript(m_Engine.World, m_LocalID, m_ItemID);
async.RemoveScript(m_LocalID, m_ItemID);
m_EventQueue.Clear(); m_EventQueue.Clear();
m_Script.ResetVars(); m_Script.ResetVars();
@ -775,8 +772,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return; return;
} }
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; PluginData = AsyncCommandManager.GetSerializationData(m_Engine.World, m_ItemID);
PluginData = async.GetSerializationData(m_ItemID);
string xml = ScriptSerializer.Serialize(this); string xml = ScriptSerializer.Serialize(this);

View File

@ -76,7 +76,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
#pragma warning restore 414 #pragma warning restore 414
private int m_EventLimit; private int m_EventLimit;
private bool m_KillTimedOutScripts; private bool m_KillTimedOutScripts;
private AsyncCommandManager m_AsyncCommands;
bool m_firstStart = true; bool m_firstStart = true;
private static List<XEngine> m_ScriptEngines = private static List<XEngine> m_ScriptEngines =
@ -142,11 +141,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
get { return m_ScriptConfig; } get { return m_ScriptConfig; }
} }
public Object AsyncCommands
{
get { return (Object)m_AsyncCommands; }
}
// //
// IRegionModule functions // IRegionModule functions
// //
@ -239,8 +233,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
m_Scene.EventManager.OnStopScript += OnStopScript; m_Scene.EventManager.OnStopScript += OnStopScript;
m_Scene.EventManager.OnShutdown += OnShutdown; m_Scene.EventManager.OnShutdown += OnShutdown;
m_AsyncCommands = new AsyncCommandManager(this);
if (m_SleepTime > 0) if (m_SleepTime > 0)
{ {
m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance), m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance),
@ -574,8 +566,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
if (!m_Scripts.ContainsKey(itemID)) if (!m_Scripts.ContainsKey(itemID))
return; return;
m_AsyncCommands.RemoveScript(localID, itemID);
IScriptInstance instance=m_Scripts[itemID]; IScriptInstance instance=m_Scripts[itemID];
m_Scripts.Remove(itemID); m_Scripts.Remove(itemID);