From d02a90823f2873f1b4de63062e3909d03a5a91fa Mon Sep 17 00:00:00 2001
From: Tedd Hansen
Date: Fri, 1 Feb 2008 23:36:36 +0000
Subject: SCRIPTING STILL BROKEN Added comments and regions, restructured code
Changed a lot of AppDomain junk from console from using Console.Write to
Log.Verbose and set it to #if DEBUG All modules should now refresh their
configuration runtime Made all logging in ScriptEngine.Common get script name
from actual engine Renamed LSLLongCmdHandler to AsyncLSLCommandManager Added
auto-recover with 5 sec throttle for new MaintenanceThread
---
.../Common/ScriptEngineBase/MaintenanceThread.cs | 86 ++++++++++++++--------
1 file changed, 56 insertions(+), 30 deletions(-)
(limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs')
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs
index 9536291..105d47f 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs
@@ -8,7 +8,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
///
/// This class does maintenance on script engine.
///
- public class MaintenanceThread
+ public class MaintenanceThread : iScriptEngineFunctionModule
{
public ScriptEngine m_ScriptEngine;
private int MaintenanceLoopms;
@@ -28,7 +28,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
StopMaintenanceThread();
}
- private void ReadConfig()
+ public void ReadConfig()
{
MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50);
}
@@ -80,48 +80,74 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
///
public void MaintenanceLoop()
{
- try
+ if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms)
+ m_ScriptEngine.Log.Warn(m_ScriptEngine.ScriptEngineName,
+ "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run.");
+
+ while (true)
{
- long Last_maxFunctionExecutionTimens = 0;// DateTime.Now.Ticks;
- long Last_ReReadConfigFilens = DateTime.Now.Ticks;
- while (true)
+ try
{
- System.Threading.Thread.Sleep(MaintenanceLoopms); // Sleep
-
- // Re-reading config every x seconds?
- if (m_ScriptEngine.ReReadConfigFileSeconds > 0)
+ long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks;
+ long Last_ReReadConfigFilens = DateTime.Now.Ticks;
+ while (true)
{
- // Check if its time to re-read config
- if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.ReReadConfigFilens)
+ System.Threading.Thread.Sleep(MaintenanceLoopms); // Sleep before next pass
+ if (PleaseShutdown)
+ return;
+ //
+ // Re-reading config every x seconds
+ //
+ if (m_ScriptEngine.RefreshConfigFileSeconds > 0)
{
- // Its time to re-read config file
- m_ScriptEngine.ConfigSource.Reload(); // Re-read config
- Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time
+ // Check if its time to re-read config
+ if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.RefreshConfigFilens)
+ {
+ // Its time to re-read config file
+ m_ScriptEngine.ConfigSource.Reload(); // Refresh config
+ m_ScriptEngine.ReadConfig();
+ Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time
+ }
}
- }
- // Adjust number of running script threads if not correct
- if (m_ScriptEngine.m_EventQueueManager.eventQueueThreads.Count != m_ScriptEngine.m_EventQueueManager.numberOfThreads)
- {
+ //
+ // Adjust number of running script threads if not correct
+ //
m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads();
- }
-
- // Check if any script has exceeded its max execution time
- if (m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime)
- {
- if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens)
+ //
+ // Check if any script has exceeded its max execution time
+ //
+ if (m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime)
{
- m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check
- Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time
+ // We are enforcing execution time
+ if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens >
+ m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens)
+ {
+ // Its time to check again
+ m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check
+ Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time
+ }
}
}
}
- }
- catch (ThreadAbortException tae)
- {
+ catch (Exception ex)
+ {
+ m_ScriptEngine.Log.Error(m_ScriptEngine.ScriptEngineName, "Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: " + ex.ToString());
+ Thread.Sleep(5000);
+ }
}
}
#endregion
+ ///
+ /// If set to true then threads and stuff should try to make a graceful exit
+ ///
+ public bool PleaseShutdown
+ {
+ get { return _PleaseShutdown; }
+ set { _PleaseShutdown = value; }
+ }
+ private bool _PleaseShutdown = false;
+
}
}
--
cgit v1.1