Moved script loading from ScriptManager to AppDomainManager. Now increases scripts loaded count in AppDomain properly.

afrisby
Tedd Hansen 2007-08-19 06:52:59 +00:00
parent 75f6c3d364
commit 1893164d26
2 changed files with 36 additions and 33 deletions

View File

@ -5,6 +5,10 @@ using System.Reflection;
using System.Threading; using System.Threading;
using System.Runtime.Remoting; using System.Runtime.Remoting;
using System.IO; using System.IO;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Scenes.Scripting;
using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL;
using OpenSim.Region.ScriptEngine.Common;
namespace OpenSim.Region.ScriptEngine.DotNetEngine namespace OpenSim.Region.ScriptEngine.DotNetEngine
{ {
@ -51,7 +55,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
/// Find a free AppDomain, creating one if necessary /// Find a free AppDomain, creating one if necessary
/// </summary> /// </summary>
/// <returns>Free AppDomain</returns> /// <returns>Free AppDomain</returns>
internal AppDomain GetFreeAppDomain() private AppDomainStructure GetFreeAppDomain()
{ {
FreeAppDomains(); FreeAppDomains();
lock(GetLock) { lock(GetLock) {
@ -78,9 +82,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
// - We assume that every time someone wants an AppDomain they will load into it // - We assume that every time someone wants an AppDomain they will load into it
// if this assumption is wrong we end up with a miscount and will never unload it. // if this assumption is wrong we end up with a miscount and will never unload it.
// //
CurrentAD.ScriptsLoaded++;
// Return AppDomain // Return AppDomain
return CurrentAD.CurrentAppDomain; return CurrentAD;
} // lock } // lock
} }
@ -137,12 +141,36 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
} // lock } // lock
} }
public OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadScript(string FileName, IScriptHost host)
{
//LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceAndUnwrap(FileName, "SecondLife.Script");
//Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory);
// * Find next available AppDomain to put it in
AppDomainStructure FreeAppDomain = GetFreeAppDomain();
LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
//LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
//Type mytype = mbrt.GetType();
//Console.WriteLine("is proxy={0}", RemotingServices.IsTransparentProxy(mbrt));
FreeAppDomain.ScriptsLoaded++;
//mbrt.Start();
return mbrt;
//return (LSL_BaseClass)mbrt;
}
/// <summary> /// <summary>
/// Increase "dead script" counter for an AppDomain /// Increase "dead script" counter for an AppDomain
/// </summary> /// </summary>
/// <param name="ad"></param> /// <param name="ad"></param>
[Obsolete("Needs optimizing!!!")] [Obsolete("Needs fixing!!!")]
public void StopScriptInAppDomain(AppDomain ad) public void StopScript(AppDomain ad)
{ {
lock (FreeLock) lock (FreeLock)
{ {
@ -170,5 +198,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
} // lock } // lock
} }
} }
} }

View File

@ -172,15 +172,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
// * Insert yield into code // * Insert yield into code
FileName = ProcessYield(FileName); FileName = ProcessYield(FileName);
// * Find next available AppDomain to put it in
AppDomain FreeAppDomain = m_scriptEngine.myAppDomainManager.GetFreeAppDomain();
// * Load and start script, for now with dummy host
//OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName);
//OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID);
OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName, ObjectID);
// Add it to our temporary active script keeper // Add it to our temporary active script keeper
//Scripts.Add(FullScriptID, Script); //Scripts.Add(FullScriptID, Script);
@ -207,30 +204,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
return FileName; return FileName;
} }
/// <summary>
/// Does actual loading and initialization of script Assembly
/// </summary>
/// <param name="FreeAppDomain">AppDomain to load script into</param>
/// <param name="FileName">FileName of script assembly (.dll)</param>
/// <returns></returns>
private OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadAndInitAssembly(AppDomain FreeAppDomain, string FileName, IScriptHost host)
{
//LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceAndUnwrap(FileName, "SecondLife.Script");
//Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory);
LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
//LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
Type mytype = mbrt.GetType();
Console.WriteLine("is proxy={0}", RemotingServices.IsTransparentProxy(mbrt));
//mbrt.Start();
return mbrt;
//return (LSL_BaseClass)mbrt;
}
/// <summary> /// <summary>
/// Execute a LL-event-function in Script /// Execute a LL-event-function in Script