Convert both script engines to new region module format. Add proper unload

handling to XEngine. Add needed stubs to DotNetEngine.
0.6.5-rc1
Melanie Thielker 2009-04-15 18:51:17 +00:00
parent fa9b9126ee
commit 3c338e4e56
7 changed files with 83 additions and 17 deletions

View File

@ -30,7 +30,7 @@ using OpenMetaverse;
namespace OpenSim.Region.Framework.Interfaces
{
public interface IScriptModule : IRegionModule
public interface IScriptModule: INonSharedRegionModule
{
string ScriptEngineName { get; }

View File

@ -43,7 +43,7 @@ using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
[Serializable]
public class ScriptEngine : IRegionModule, IScriptEngine, IScriptModule
public class ScriptEngine : INonSharedRegionModule, IScriptEngine, IScriptModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -117,11 +117,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
}
}
public void Initialise(Scene Sceneworld, IConfigSource config)
public void Initialise(IConfigSource config)
{
ConfigSource = config;
}
public void AddRegion(Scene Sceneworld)
{
m_log.Info("[" + ScriptEngineName + "]: ScriptEngine initializing");
ConfigSource = config;
m_Scene = Sceneworld;
// Make sure we have config
@ -153,7 +157,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
m_Scene.StackModuleInterface<IScriptModule>(this);
}
public void PostInitialise()
public void RemoveRegion(Scene scene)
{
}
public void RegionLoaded(Scene scene)
{
if (!m_enabled)
return;

View File

@ -104,5 +104,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
string GetAssemblyName();
string GetXMLState();
double MinEventDelay { set; }
UUID RegionID { get; }
}
}

View File

@ -93,6 +93,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
private bool m_postOnRez;
private bool m_startedFromSavedState = false;
private string m_CurrentState = String.Empty;
private UUID m_RegionID = UUID.Zero;
//private ISponsor m_ScriptSponsor;
private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
@ -231,6 +232,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_MaxScriptQueue = maxScriptQueue;
m_stateSource = stateSource;
m_postOnRez = postOnRez;
m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
if (part != null)
{
@ -980,5 +982,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return ScriptSerializer.Serialize(this);
}
public UUID RegionID
{
get { return m_RegionID; }
}
}
}

View File

@ -60,7 +60,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
XEngine.XEngine engine = new XEngine.XEngine();
engine.Initialise(scene, initConfigSource);
engine.Initialise(initConfigSource);
engine.AddRegion(scene);
m_lslApi = new LSL_Api();
m_lslApi.Initialize(engine, part, part.LocalId, part.UUID);

View File

@ -60,9 +60,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests
[Test]
public void T001_XStart()
{
IRegionModule xengine = new XEngine();
INonSharedRegionModule xengine = new XEngine();
SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), xengine);
xengine.PostInitialise();
xengine.RegionLoaded(scene);
}
}
}

View File

@ -52,14 +52,14 @@ using OpenSim.Region.ScriptEngine.Interfaces;
namespace OpenSim.Region.ScriptEngine.XEngine
{
public class XEngine : IRegionModule, IScriptModule, IScriptEngine
public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private SmartThreadPool m_ThreadPool;
private int m_MaxScriptQueue;
private Scene m_Scene;
private IConfig m_ScriptConfig;
private IConfig m_ScriptConfig = null;
private ICompiler m_Compiler;
private int m_MinThreads;
private int m_MaxThreads ;
@ -154,9 +154,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine
//
// IRegionModule functions
//
public void Initialise(Scene scene, IConfigSource configSource)
public void Initialise(IConfigSource configSource)
{
if (configSource.Configs["XEngine"] == null)
return;
m_ScriptConfig = configSource.Configs["XEngine"];
}
public void AddRegion(Scene scene)
{
if (m_ScriptConfig == null)
return;
m_ScriptFailCount = 0;
m_ScriptErrorMessage = String.Empty;
@ -237,7 +246,52 @@ namespace OpenSim.Region.ScriptEngine.XEngine
}
}
public void PostInitialise()
public void RemoveRegion(Scene scene)
{
lock (m_Scripts)
{
foreach (IScriptInstance instance in m_Scripts.Values)
{
// Force a final state save
//
if (m_Assemblies.ContainsKey(instance.AssetID))
{
string assembly = m_Assemblies[instance.AssetID];
instance.SaveState(assembly);
}
// Clear the event queue and abort the instance thread
//
instance.ClearQueue();
instance.Stop(0);
// Unload scripts and app domains
// Must be done explicitly because they have infinite
// lifetime
//
m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
if (m_DomainScripts[instance.AppDomain].Count == 0)
{
m_DomainScripts.Remove(instance.AppDomain);
UnloadAppDomain(instance.AppDomain);
}
// Release events, timer, etc
//
instance.DestroyScriptInstance();
}
m_Scripts.Clear();
m_PrimObjects.Clear();
m_Assemblies.Clear();
m_DomainScripts.Clear();
}
lock (m_ScriptEngines)
{
m_ScriptEngines.Remove(this);
}
}
public void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
@ -346,11 +400,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
get { return "XEngine"; }
}
public bool IsSharedModule
{
get { return false; }
}
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
{
if (script.StartsWith("//MRM:"))