aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs66
1 files changed, 29 insertions, 37 deletions
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
12 { 12 {
13 private int MaxScriptsPerAppDomain = 1; 13 private int MaxScriptsPerAppDomain = 1;
14 /// <summary> 14 /// <summary>
15 /// List of all AppDomains 15 /// Internal list of all AppDomains
16 /// </summary> 16 /// </summary>
17 private List<AppDomainStructure> AppDomains = new List<AppDomainStructure>(); 17 private List<AppDomainStructure> AppDomains = new List<AppDomainStructure>();
18 /// <summary>
19 /// Structure to keep track of data around AppDomain
20 /// </summary>
18 private struct AppDomainStructure 21 private struct AppDomainStructure
19 { 22 {
20 /// <summary> 23 /// <summary>
@@ -37,10 +40,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
37 private object GetLock = new object(); // Mutex 40 private object GetLock = new object(); // Mutex
38 private object FreeLock = new object(); // Mutex 41 private object FreeLock = new object(); // Mutex
39 42
40 private ScriptEngine m_scriptEngine; 43 //private ScriptEngine m_scriptEngine;
41 public AppDomainManager(ScriptEngine scriptEngine) 44 //public AppDomainManager(ScriptEngine scriptEngine)
45 public AppDomainManager()
42 { 46 {
43 m_scriptEngine = scriptEngine; 47 //m_scriptEngine = scriptEngine;
44 } 48 }
45 49
46 /// <summary> 50 /// <summary>
@@ -54,6 +58,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
54 // Current full? 58 // Current full?
55 if (CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain) 59 if (CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain)
56 { 60 {
61 // Add it to AppDomains list and empty current
57 AppDomains.Add(CurrentAD); 62 AppDomains.Add(CurrentAD);
58 CurrentAD = new AppDomainStructure(); 63 CurrentAD = new AppDomainStructure();
59 } 64 }
@@ -68,7 +73,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
68 73
69 } 74 }
70 75
71 // Increase number of scripts loaded 76 // Increase number of scripts loaded into this
77 // TODO:
78 // - We assume that every time someone wants an AppDomain they will load into it
79 // if this assumption is wrong we end up with a miscount and will never unload it.
80 //
72 CurrentAD.ScriptsLoaded++; 81 CurrentAD.ScriptsLoaded++;
73 // Return AppDomain 82 // Return AppDomain
74 return CurrentAD.CurrentAppDomain; 83 return CurrentAD.CurrentAppDomain;
@@ -84,46 +93,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
84 { 93 {
85 // Create and prepare a new AppDomain 94 // Create and prepare a new AppDomain
86 AppDomainNameCount++; 95 AppDomainNameCount++;
87 // TODO: Currently security and configuration match current appdomain 96 // TODO: Currently security match current appdomain
88 97
89 // Construct and initialize settings for a second AppDomain. 98 // Construct and initialize settings for a second AppDomain.
90 AppDomainSetup ads = new AppDomainSetup(); 99 AppDomainSetup ads = new AppDomainSetup();
91 ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; 100 ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
92 //Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
93 //ads.ApplicationName = "DotNetScriptEngine";
94 //ads.DynamicBase = ads.ApplicationBase;
95
96 //Console.WriteLine("AppDomain BaseDirectory: " + ads.ApplicationBase);
97 ads.DisallowBindingRedirects = false; 101 ads.DisallowBindingRedirects = false;
98 ads.DisallowCodeDownload = true; 102 ads.DisallowCodeDownload = true;
99 ads.ShadowCopyFiles = "true"; 103 ads.ShadowCopyFiles = "true"; // Enabled shadowing
100 104 ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
101 ads.ConfigurationFile =
102 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
103 105
104 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads); 106 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads);
105 //foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
106 //{
107 // //Console.WriteLine("Loading: " + a.GetName(true));
108 // try
109 // {
110 // //AD.Load(a.GetName(true));
111
112 // }
113 // catch (Exception e)
114 // {
115 // //Console.WriteLine("FAILED load");
116 // }
117
118 //}
119 107
120 //Console.WriteLine("Assembly file: " + this.GetType().Assembly.CodeBase); 108 // Return the new AppDomain
121 //Console.WriteLine("Assembly name: " + this.GetType().ToString());
122 //AD.CreateInstanceFrom(this.GetType().Assembly.CodeBase, "OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine");
123
124 //AD.Load(this.GetType().Assembly.CodeBase);
125
126 Console.WriteLine("Done preparing new AppDomain.");
127 return AD; 109 return AD;
128 110
129 } 111 }
@@ -135,14 +117,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
135 { 117 {
136 lock (FreeLock) 118 lock (FreeLock)
137 { 119 {
120 // Go through all
138 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains)) 121 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains))
139 { 122 {
123 // Don't process current AppDomain
140 if (ads.CurrentAppDomain != CurrentAD.CurrentAppDomain) 124 if (ads.CurrentAppDomain != CurrentAD.CurrentAppDomain)
141 { 125 {
142 // Not current AppDomain 126 // Not current AppDomain
143 if (ads.ScriptsLoaded == ads.ScriptsWaitingUnload) 127 // Is number of unloaded bigger or equal to number of loaded?
128 if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)
144 { 129 {
130 // Remove from internal list
145 AppDomains.Remove(ads); 131 AppDomains.Remove(ads);
132 // Unload
146 AppDomain.Unload(ads.CurrentAppDomain); 133 AppDomain.Unload(ads.CurrentAppDomain);
147 } 134 }
148 } 135 }
@@ -159,16 +146,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
159 { 146 {
160 lock (FreeLock) 147 lock (FreeLock)
161 { 148 {
149 // Check if it is current AppDomain
162 if (CurrentAD.CurrentAppDomain == ad) 150 if (CurrentAD.CurrentAppDomain == ad)
163 { 151 {
152 // Yes - increase
164 CurrentAD.ScriptsWaitingUnload++; 153 CurrentAD.ScriptsWaitingUnload++;
165 return; 154 return;
166 } 155 }
167 156
157 // Lopp through all AppDomains
168 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains)) 158 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains))
169 { 159 {
170 if (ads.CurrentAppDomain == ad) 160 if (ads.CurrentAppDomain == ad)
171 { 161 {
162 // Found it - messy code to increase structure
172 AppDomainStructure ads2 = ads; 163 AppDomainStructure ads2 = ads;
173 ads2.ScriptsWaitingUnload++; 164 ads2.ScriptsWaitingUnload++;
174 AppDomains.Remove(ads); 165 AppDomains.Remove(ads);
@@ -178,5 +169,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
178 } // foreach 169 } // foreach
179 } // lock 170 } // lock
180 } 171 }
172
181 } 173 }
182} 174}