From 37446b0392ba423894952f81aa0f938d2bd2de22 Mon Sep 17 00:00:00 2001
From: Tedd Hansen
Date: Sat, 18 Aug 2007 23:24:38 +0000
Subject: Moved in-AppDomain event execution from Script to
OpenSim.Region.ScriptEngine.Executor. Script no longer responsible for
handling event calls to itself (and we can create reference cache in
Executor).
---
.../ScriptEngine/DotNetEngine/AppDomainManager.cs | 66 ++++++++++------------
1 file changed, 29 insertions(+), 37 deletions(-)
(limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs')
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
index f80ebac..33e95d3 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
@@ -12,9 +12,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
private int MaxScriptsPerAppDomain = 1;
///
- /// List of all AppDomains
+ /// Internal list of all AppDomains
///
private List AppDomains = new List();
+ ///
+ /// Structure to keep track of data around AppDomain
+ ///
private struct AppDomainStructure
{
///
@@ -37,10 +40,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
private object GetLock = new object(); // Mutex
private object FreeLock = new object(); // Mutex
- private ScriptEngine m_scriptEngine;
- public AppDomainManager(ScriptEngine scriptEngine)
+ //private ScriptEngine m_scriptEngine;
+ //public AppDomainManager(ScriptEngine scriptEngine)
+ public AppDomainManager()
{
- m_scriptEngine = scriptEngine;
+ //m_scriptEngine = scriptEngine;
}
///
@@ -54,6 +58,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
// Current full?
if (CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain)
{
+ // Add it to AppDomains list and empty current
AppDomains.Add(CurrentAD);
CurrentAD = new AppDomainStructure();
}
@@ -68,7 +73,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
}
- // Increase number of scripts loaded
+ // Increase number of scripts loaded into this
+ // TODO:
+ // - 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.
+ //
CurrentAD.ScriptsLoaded++;
// Return AppDomain
return CurrentAD.CurrentAppDomain;
@@ -84,46 +93,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
// Create and prepare a new AppDomain
AppDomainNameCount++;
- // TODO: Currently security and configuration match current appdomain
+ // TODO: Currently security match current appdomain
// Construct and initialize settings for a second AppDomain.
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
- //Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
- //ads.ApplicationName = "DotNetScriptEngine";
- //ads.DynamicBase = ads.ApplicationBase;
-
- //Console.WriteLine("AppDomain BaseDirectory: " + ads.ApplicationBase);
ads.DisallowBindingRedirects = false;
ads.DisallowCodeDownload = true;
- ads.ShadowCopyFiles = "true";
-
- ads.ConfigurationFile =
- AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+ ads.ShadowCopyFiles = "true"; // Enabled shadowing
+ ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads);
- //foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
- //{
- // //Console.WriteLine("Loading: " + a.GetName(true));
- // try
- // {
- // //AD.Load(a.GetName(true));
-
- // }
- // catch (Exception e)
- // {
- // //Console.WriteLine("FAILED load");
- // }
-
- //}
- //Console.WriteLine("Assembly file: " + this.GetType().Assembly.CodeBase);
- //Console.WriteLine("Assembly name: " + this.GetType().ToString());
- //AD.CreateInstanceFrom(this.GetType().Assembly.CodeBase, "OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine");
-
- //AD.Load(this.GetType().Assembly.CodeBase);
-
- Console.WriteLine("Done preparing new AppDomain.");
+ // Return the new AppDomain
return AD;
}
@@ -135,14 +117,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
lock (FreeLock)
{
+ // Go through all
foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains))
{
+ // Don't process current AppDomain
if (ads.CurrentAppDomain != CurrentAD.CurrentAppDomain)
{
// Not current AppDomain
- if (ads.ScriptsLoaded == ads.ScriptsWaitingUnload)
+ // Is number of unloaded bigger or equal to number of loaded?
+ if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)
{
+ // Remove from internal list
AppDomains.Remove(ads);
+ // Unload
AppDomain.Unload(ads.CurrentAppDomain);
}
}
@@ -159,16 +146,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
lock (FreeLock)
{
+ // Check if it is current AppDomain
if (CurrentAD.CurrentAppDomain == ad)
{
+ // Yes - increase
CurrentAD.ScriptsWaitingUnload++;
return;
}
+ // Lopp through all AppDomains
foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains))
{
if (ads.CurrentAppDomain == ad)
{
+ // Found it - messy code to increase structure
AppDomainStructure ads2 = ads;
ads2.ScriptsWaitingUnload++;
AppDomains.Remove(ads);
@@ -178,5 +169,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
} // foreach
} // lock
}
+
}
}
--
cgit v1.1