Change XEngine startup to enable it to run as a normal region module

rather than a special one
0.6.0-stable
Melanie Thielker 2008-09-21 02:52:12 +00:00
parent c8349e21c4
commit 85586bb7b2
1 changed files with 40 additions and 27 deletions

View File

@ -60,6 +60,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
private Scene m_Scene; private Scene m_Scene;
private IConfig m_ScriptConfig; private IConfig m_ScriptConfig;
private Compiler m_Compiler; private Compiler m_Compiler;
private int m_MinThreads;
private int m_MaxThreads ;
private int m_IdleTimeout;
private int m_StackSize;
private int m_SleepTime;
private int m_SaveTime;
private ThreadPriority m_Prio;
// disable warning: need to keep a reference to XEngine.EventManager // disable warning: need to keep a reference to XEngine.EventManager
// alive to avoid it being garbage collected // alive to avoid it being garbage collected
@ -159,34 +166,35 @@ namespace OpenSim.Region.ScriptEngine.XEngine
return; return;
} }
int minThreads = m_ScriptConfig.GetInt("MinThreads", 2); m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2);
int maxThreads = m_ScriptConfig.GetInt("MaxThreads", 100); m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100);
int idleTimeout = m_ScriptConfig.GetInt("IdleTimeout", 60); m_IdleTimeout = m_ScriptConfig.GetInt("IdleTimeout", 60);
string priority = m_ScriptConfig.GetString("Priority", "BelowNormal"); string priority = m_ScriptConfig.GetString("Priority", "BelowNormal");
int maxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300); m_MaxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300);
int stackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144); m_StackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144);
int sleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000; m_SleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000;
m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30);
m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false);
int saveTime = m_ScriptConfig.GetInt("SaveInterval", 120) * 1000; m_SaveTime = m_ScriptConfig.GetInt("SaveInterval", 120) * 1000;
ThreadPriority prio = ThreadPriority.BelowNormal; m_Prio = ThreadPriority.BelowNormal;
switch (priority) switch (priority)
{ {
case "Lowest": case "Lowest":
prio = ThreadPriority.Lowest; m_Prio = ThreadPriority.Lowest;
break; break;
case "BelowNormal": case "BelowNormal":
prio = ThreadPriority.BelowNormal; m_Prio = ThreadPriority.BelowNormal;
break; break;
case "Normal": case "Normal":
prio = ThreadPriority.Normal; m_Prio = ThreadPriority.Normal;
break; break;
case "AboveNormal": case "AboveNormal":
prio = ThreadPriority.AboveNormal; m_Prio = ThreadPriority.AboveNormal;
break; break;
case "Highest": case "Highest":
prio = ThreadPriority.Highest; m_Prio = ThreadPriority.Highest;
break; break;
default: default:
m_log.ErrorFormat("[XEngine] Invalid thread priority: '{0}'. Assuming BelowNormal", priority); m_log.ErrorFormat("[XEngine] Invalid thread priority: '{0}'. Assuming BelowNormal", priority);
@ -198,14 +206,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
m_ScriptEngines.Add(this); m_ScriptEngines.Add(this);
} }
m_EventManager = new EventManager(this); scene.RegisterModuleInterface<IScriptModule>(this);
StartEngine(minThreads, maxThreads, idleTimeout, prio, // Needs to be here so we can queue the scripts that need starting
maxScriptQueue, stackSize); //
m_Scene.EventManager.OnRezScript += OnRezScript;
// Complete basic setup of the thread pool
//
SetupEngine(m_MinThreads, m_MaxThreads, m_IdleTimeout, m_Prio,
m_MaxScriptQueue, m_StackSize);
}
public void PostInitialise()
{
m_EventManager = new EventManager(this);
m_Compiler = new Compiler(this); m_Compiler = new Compiler(this);
m_Scene.EventManager.OnRezScript += OnRezScript;
m_Scene.EventManager.OnRemoveScript += OnRemoveScript; m_Scene.EventManager.OnRemoveScript += OnRemoveScript;
m_Scene.EventManager.OnScriptReset += OnScriptReset; m_Scene.EventManager.OnScriptReset += OnScriptReset;
m_Scene.EventManager.OnStartScript += OnStartScript; m_Scene.EventManager.OnStartScript += OnStartScript;
@ -214,23 +232,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine
m_AsyncCommands = new AsyncCommandManager(this); m_AsyncCommands = new AsyncCommandManager(this);
if (sleepTime > 0) if (m_SleepTime > 0)
{ {
m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance), m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance),
new Object[]{ sleepTime }); new Object[]{ m_SleepTime });
} }
if (saveTime > 0) if (m_SaveTime > 0)
{ {
m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup), m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup),
new Object[] { saveTime }); new Object[] { m_SaveTime });
} }
scene.RegisterModuleInterface<IScriptModule>(this);
}
public void PostInitialise()
{
m_ThreadPool.Start(); m_ThreadPool.Start();
} }
@ -641,7 +654,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
// //
// Start processing // Start processing
// //
private void StartEngine(int minThreads, int maxThreads, private void SetupEngine(int minThreads, int maxThreads,
int idleTimeout, ThreadPriority threadPriority, int idleTimeout, ThreadPriority threadPriority,
int maxScriptQueue, int stackSize) int maxScriptQueue, int stackSize)
{ {