29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Threading;
33 using OpenSim.Framework;
34 using OpenSim.Framework.Monitoring;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.ScriptEngine.Interfaces;
37 using OpenSim.Region.ScriptEngine.Shared;
38 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
40 using System.Reflection;
43 namespace OpenSim.
Region.ScriptEngine.Shared.Api
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private static Thread cmdHandlerThread;
53 private static int cmdHandlerThreadCycleSleepms;
62 private static object staticLock =
new object();
64 private static List<IScriptEngine> m_ScriptEngines =
65 new List<IScriptEngine>();
69 private static Dictionary<IScriptEngine, Dataserver> m_Dataserver =
70 new Dictionary<IScriptEngine, Dataserver>();
71 private static Dictionary<IScriptEngine, Timer> m_Timer =
72 new Dictionary<IScriptEngine, Timer>();
73 private static Dictionary<IScriptEngine, Listener> m_Listener =
74 new Dictionary<IScriptEngine, Listener>();
75 private static Dictionary<IScriptEngine, HttpRequest> m_HttpRequest =
76 new Dictionary<IScriptEngine, HttpRequest>();
77 private static Dictionary<IScriptEngine, SensorRepeat> m_SensorRepeat =
78 new Dictionary<IScriptEngine, SensorRepeat>();
79 private static Dictionary<IScriptEngine, XmlRequest> m_XmlRequest =
80 new Dictionary<IScriptEngine, XmlRequest>();
87 return m_Dataserver[m_ScriptEngine];
91 public Timer TimerPlugin
96 return m_Timer[m_ScriptEngine];
105 return m_HttpRequest[m_ScriptEngine];
114 return m_Listener[m_ScriptEngine];
123 return m_SensorRepeat[m_ScriptEngine];
132 return m_XmlRequest[m_ScriptEngine];
141 return m_ScriptEngines.ToArray();
147 m_ScriptEngine = _ScriptEngine;
155 if (m_ScriptEngines.Count == 0)
158 if (!m_ScriptEngines.Contains(m_ScriptEngine))
159 m_ScriptEngines.Add(m_ScriptEngine);
162 if (!m_Dataserver.ContainsKey(m_ScriptEngine))
163 m_Dataserver[m_ScriptEngine] =
new Dataserver(
this);
164 if (!m_Timer.ContainsKey(m_ScriptEngine))
165 m_Timer[m_ScriptEngine] =
new Timer(
this);
166 if (!m_HttpRequest.ContainsKey(m_ScriptEngine))
167 m_HttpRequest[m_ScriptEngine] =
new HttpRequest(
this);
168 if (!m_Listener.ContainsKey(m_ScriptEngine))
169 m_Listener[m_ScriptEngine] =
new Listener(
this);
170 if (!m_SensorRepeat.ContainsKey(m_ScriptEngine))
171 m_SensorRepeat[m_ScriptEngine] =
new SensorRepeat(
this);
172 if (!m_XmlRequest.ContainsKey(m_ScriptEngine))
173 m_XmlRequest[m_ScriptEngine] =
new XmlRequest(
this);
179 private static void StartThread()
181 if (cmdHandlerThread == null)
185 = WorkManager.StartThread(
186 CmdHandlerThreadLoop,
"AsyncLSLCmdHandlerThread", ThreadPriority.Normal,
true,
true);
190 private void ReadConfig()
194 cmdHandlerThreadCycleSleepms = 100;
197 ~AsyncCommandManager()
219 private static void CmdHandlerThreadLoop()
225 Thread.Sleep(cmdHandlerThreadCycleSleepms);
227 DoOneCmdHandlerPass();
229 Watchdog.UpdateThread();
233 m_log.Error(
"[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e);
238 private static void DoOneCmdHandlerPass()
243 m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests();
246 m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests();
251 m_Listener[s].CheckListeners();
254 m_Timer[s].CheckTimerEvents();
257 m_SensorRepeat[s].CheckSenseRepeaterEvents();
260 m_Dataserver[s].ExpireRequests();
278 m_Dataserver[engine].RemoveEvents(localID, itemID);
281 m_Timer[engine].UnSetTimerEvents(localID, itemID);
285 if (iHttpReq != null)
286 iHttpReq.StopHttpRequest(localID, itemID);
290 comms.DeleteListener(itemID);
295 xmlrpc.DeleteChannels(itemID);
296 xmlrpc.CancelSRDRequests(itemID);
300 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
309 m_Dataserver[engine].RemoveEvents(localID, itemID);
313 comms.DeleteListener(itemID);
318 xmlrpc.DeleteChannels(itemID);
319 xmlrpc.CancelSRDRequests(itemID);
322 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
335 if (m_SensorRepeat.ContainsKey(engine))
336 return m_SensorRepeat[engine];
351 if (m_Dataserver.ContainsKey(engine))
352 return m_Dataserver[engine];
367 if (m_Timer.ContainsKey(engine))
368 return m_Timer[engine];
383 if (m_Listener.ContainsKey(engine))
384 return m_Listener[engine];
394 List<Object> data =
new List<Object>();
398 Object[] listeners = m_Listener[engine].GetSerializationData(itemID);
399 if (listeners.Length > 0)
401 data.Add(
"listener");
402 data.Add(listeners.Length);
403 data.AddRange(listeners);
406 Object[] timers=m_Timer[engine].GetSerializationData(itemID);
407 if (timers.Length > 0)
410 data.Add(timers.Length);
411 data.AddRange(timers);
414 Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID);
415 if (sensors.Length > 0)
418 data.Add(sensors.Length);
419 data.AddRange(sensors);
423 return data.ToArray();
427 UUID itemID, UUID hostID, Object[] data)
432 while (idx < data.Length)
434 string type = data[idx].ToString();
435 len = (int)data[idx+1];
441 Array.Copy(data, idx, item, 0, len);
450 m_Listener[engine].CreateFromData(localID, itemID,
454 m_Timer[engine].CreateFromData(localID, itemID,
458 m_SensorRepeat[engine].CreateFromData(localID,
459 itemID, hostID, item);
static Timer GetTimerPlugin(IScriptEngine engine)
Get the timer plugin for this script engine.
Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer Timer
static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID)
Remove a specific script (and all its pending commands)
static void StateChange(IScriptEngine engine, uint localID, UUID itemID)
static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine)
Get the sensor repeat plugin for this script engine.
An interface for a script API module to communicate with the engine it's running under ...
static Dataserver GetDataserverPlugin(IScriptEngine engine)
Get the dataserver plugin for this script engine.
static void CreateFromData(IScriptEngine engine, uint localID, UUID itemID, UUID hostID, Object[] data)
static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
static Listener GetListenerPlugin(IScriptEngine engine)
Get the listener plugin for this script engine.
IScriptEngine m_ScriptEngine
AsyncCommandManager(IScriptEngine _ScriptEngine)