aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs44
1 files changed, 31 insertions, 13 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs
index 3519d54..2ed0529 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AppDomainManager.cs
@@ -35,7 +35,7 @@ using OpenSim.Region.ScriptEngine.Common;
35 35
36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase 36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
37{ 37{
38 public class AppDomainManager 38 public class AppDomainManager : iScriptEngineFunctionModule
39 { 39 {
40 40
41 // 41 //
@@ -85,12 +85,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
85 private object getLock = new object(); // Mutex 85 private object getLock = new object(); // Mutex
86 private object freeLock = new object(); // Mutex 86 private object freeLock = new object(); // Mutex
87 87
88 //private ScriptEngine m_scriptEngine; 88 private ScriptEngine m_scriptEngine;
89 //public AppDomainManager(ScriptEngine scriptEngine) 89 //public AppDomainManager(ScriptEngine scriptEngine)
90 public AppDomainManager(int MaxScriptsPerDomain) 90 public AppDomainManager(ScriptEngine scriptEngine)
91 { 91 {
92 maxScriptsPerAppDomain = MaxScriptsPerDomain; 92 m_scriptEngine = scriptEngine;
93 //m_scriptEngine = scriptEngine; 93 ReadConfig();
94 }
95
96 public void ReadConfig()
97 {
98 maxScriptsPerAppDomain = m_scriptEngine.ScriptConfigSource.GetInt("ScriptsPerAppDomain", 1);
94 } 99 }
95 100
96 /// <summary> 101 /// <summary>
@@ -99,7 +104,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
99 /// <returns>Free AppDomain</returns> 104 /// <returns>Free AppDomain</returns>
100 private AppDomainStructure GetFreeAppDomain() 105 private AppDomainStructure GetFreeAppDomain()
101 { 106 {
102 Console.WriteLine("Finding free AppDomain"); 107 // Console.WriteLine("Finding free AppDomain");
103 lock (getLock) 108 lock (getLock)
104 { 109 {
105 // Current full? 110 // Current full?
@@ -117,7 +122,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
117 currentAD.CurrentAppDomain = PrepareNewAppDomain(); 122 currentAD.CurrentAppDomain = PrepareNewAppDomain();
118 } 123 }
119 124
120 Console.WriteLine("Scripts loaded in this Appdomain: " + currentAD.ScriptsLoaded); 125 // Console.WriteLine("Scripts loaded in this Appdomain: " + currentAD.ScriptsLoaded);
121 return currentAD; 126 return currentAD;
122 } // lock 127 } // lock
123 } 128 }
@@ -144,7 +149,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
144 ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; 149 ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
145 150
146 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads); 151 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads);
147 Console.WriteLine("Loading: " + 152 m_scriptEngine.Log.Verbose(m_scriptEngine.ScriptEngineName, "AppDomain Loading: " +
148 AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll").ToString()); 153 AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll").ToString());
149 AD.Load(AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll")); 154 AD.Load(AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll"));
150 155
@@ -169,17 +174,16 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
169 // Is number of unloaded bigger or equal to number of loaded? 174 // Is number of unloaded bigger or equal to number of loaded?
170 if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) 175 if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)
171 { 176 {
172 Console.WriteLine("Found empty AppDomain, unloading");
173 // Remove from internal list 177 // Remove from internal list
174 appDomains.Remove(ads); 178 appDomains.Remove(ads);
175#if DEBUG 179#if DEBUG
180 Console.WriteLine("Found empty AppDomain, unloading");
176 long m = GC.GetTotalMemory(true); 181 long m = GC.GetTotalMemory(true);
177#endif 182#endif
178 // Unload 183 // Unload
179 AppDomain.Unload(ads.CurrentAppDomain); 184 AppDomain.Unload(ads.CurrentAppDomain);
180#if DEBUG 185#if DEBUG
181 Console.WriteLine("AppDomain unload freed " + (m - GC.GetTotalMemory(true)) + 186 m_scriptEngine.Log.Verbose(m_scriptEngine.ScriptEngineName, "AppDomain unload freed " + (m - GC.GetTotalMemory(true)) + " bytes of memory");
182 " bytes of memory");
183#endif 187#endif
184 } 188 }
185 } 189 }
@@ -193,7 +197,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
193 // Find next available AppDomain to put it in 197 // Find next available AppDomain to put it in
194 AppDomainStructure FreeAppDomain = GetFreeAppDomain(); 198 AppDomainStructure FreeAppDomain = GetFreeAppDomain();
195 199
196 Console.WriteLine("Loading into AppDomain: " + FileName); 200#if DEBUG
201 m_scriptEngine.Log.Verbose(m_scriptEngine.ScriptEngineName, "Loading into AppDomain: " + FileName);
202#endif
197 IScript mbrt = 203 IScript mbrt =
198 (IScript) 204 (IScript)
199 FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); 205 FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
@@ -213,7 +219,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
213 { 219 {
214 lock (freeLock) 220 lock (freeLock)
215 { 221 {
216 Console.WriteLine("Stopping script in AppDomain"); 222#if DEBUG
223 m_scriptEngine.Log.Verbose(m_scriptEngine.ScriptEngineName, "Stopping script in AppDomain");
224#endif
217 // Check if it is current AppDomain 225 // Check if it is current AppDomain
218 if (currentAD.CurrentAppDomain == ad) 226 if (currentAD.CurrentAppDomain == ad)
219 { 227 {
@@ -236,5 +244,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
236 244
237 UnloadAppDomains(); // Outsite lock, has its own GetLock 245 UnloadAppDomains(); // Outsite lock, has its own GetLock
238 } 246 }
247 /// <summary>
248 /// If set to true then threads and stuff should try to make a graceful exit
249 /// </summary>
250 public bool PleaseShutdown
251 {
252 get { return _PleaseShutdown; }
253 set { _PleaseShutdown = value; }
254 }
255 private bool _PleaseShutdown = false;
256
239 } 257 }
240} \ No newline at end of file 258} \ No newline at end of file