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)
c.Type = ChatTypeEnum.DebugChannel;
if (c.Message.Length > 1100)
c.Message = c.Message.Substring(0, 1000);
// chat works by redistributing every incoming chat
// message to each avatar in the scene
Vector3 pos = new Vector3(128, 128, 30);

View File

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

View File

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

View File

@ -92,7 +92,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_ScriptDistanceFactor = config.Configs["XEngine"].
GetFloat("ScriptDistanceLimitFactor", 1.0f);
AsyncCommands = (AsyncCommandManager)ScriptEngine.AsyncCommands;
AsyncCommands = new AsyncCommandManager(ScriptEngine);
}
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)
};
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",
resobj, new DetectParams[0])))
break;

View File

@ -71,9 +71,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
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(
"remote_data", resobj,
new DetectParams[0])))
@ -100,9 +100,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
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(
"remote_data", resobj,
new DetectParams[0])))

View File

@ -246,8 +246,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
ScriptSerializer.Deserialize(xml, this);
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
async.CreateFromData(
AsyncCommandManager.CreateFromData(m_Engine.World,
m_LocalID, m_ItemID, m_ObjectID,
PluginData);
@ -337,6 +336,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void DestroyScriptInstance()
{
ReleaseControls();
AsyncCommandManager.RemoveScript(m_Engine.World, m_LocalID, m_ItemID);
}
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_PrimName, m_ScriptName, data.Params[0].ToString());
m_State=data.Params[0].ToString();
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
async.RemoveScript(
AsyncCommandManager.RemoveScript(m_Engine.World,
m_LocalID, m_ItemID);
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
@ -691,8 +690,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID);
part.GetInventoryItem(m_ItemID).PermsMask = 0;
part.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
async.RemoveScript(m_LocalID, m_ItemID);
AsyncCommandManager.RemoveScript(m_Engine.World, m_LocalID, m_ItemID);
m_EventQueue.Clear();
m_Script.ResetVars();
m_State = "default";
@ -717,8 +715,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID);
part.GetInventoryItem(m_ItemID).PermsMask = 0;
part.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
async.RemoveScript(m_LocalID, m_ItemID);
AsyncCommandManager.RemoveScript(m_Engine.World, m_LocalID, m_ItemID);
m_EventQueue.Clear();
m_Script.ResetVars();
@ -775,8 +772,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return;
}
AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands;
PluginData = async.GetSerializationData(m_ItemID);
PluginData = AsyncCommandManager.GetSerializationData(m_Engine.World, m_ItemID);
string xml = ScriptSerializer.Serialize(this);

View File

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