diff options
author | lbsa71 | 2007-10-30 09:05:31 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-30 09:05:31 +0000 |
commit | 67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch) | |
tree | 20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs | |
parent | * Deleted .user file (diff) | |
download | opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2 opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz |
* Optimized usings
* Shortened type references
* Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs')
-rw-r--r-- | OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs index e5478ae..e6c1678 100644 --- a/OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs +++ b/OpenSim/Grid/ScriptEngine/DotNetEngine/AppDomainManager.cs | |||
@@ -27,27 +27,22 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections; | ||
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using System.Text; | ||
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.Threading; | ||
34 | using System.Runtime.Remoting; | ||
35 | using System.IO; | ||
36 | using OpenSim.Region.Environment.Scenes; | ||
37 | using OpenSim.Region.Environment.Scenes.Scripting; | ||
38 | using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL; | 33 | using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL; |
39 | using OpenSim.Region.ScriptEngine.Common; | ||
40 | using libsecondlife; | ||
41 | 34 | ||
42 | namespace OpenSim.Grid.ScriptEngine.DotNetEngine | 35 | namespace OpenSim.Grid.ScriptEngine.DotNetEngine |
43 | { | 36 | { |
44 | public class AppDomainManager | 37 | public class AppDomainManager |
45 | { | 38 | { |
46 | private int maxScriptsPerAppDomain = 1; | 39 | private int maxScriptsPerAppDomain = 1; |
40 | |||
47 | /// <summary> | 41 | /// <summary> |
48 | /// Internal list of all AppDomains | 42 | /// Internal list of all AppDomains |
49 | /// </summary> | 43 | /// </summary> |
50 | private List<AppDomainStructure> appDomains = new List<AppDomainStructure>(); | 44 | private List<AppDomainStructure> appDomains = new List<AppDomainStructure>(); |
45 | |||
51 | /// <summary> | 46 | /// <summary> |
52 | /// Structure to keep track of data around AppDomain | 47 | /// Structure to keep track of data around AppDomain |
53 | /// </summary> | 48 | /// </summary> |
@@ -57,19 +52,23 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
57 | /// The AppDomain itself | 52 | /// The AppDomain itself |
58 | /// </summary> | 53 | /// </summary> |
59 | public AppDomain CurrentAppDomain; | 54 | public AppDomain CurrentAppDomain; |
55 | |||
60 | /// <summary> | 56 | /// <summary> |
61 | /// Number of scripts loaded into AppDomain | 57 | /// Number of scripts loaded into AppDomain |
62 | /// </summary> | 58 | /// </summary> |
63 | public int ScriptsLoaded; | 59 | public int ScriptsLoaded; |
60 | |||
64 | /// <summary> | 61 | /// <summary> |
65 | /// Number of dead scripts | 62 | /// Number of dead scripts |
66 | /// </summary> | 63 | /// </summary> |
67 | public int ScriptsWaitingUnload; | 64 | public int ScriptsWaitingUnload; |
68 | } | 65 | } |
66 | |||
69 | /// <summary> | 67 | /// <summary> |
70 | /// Current AppDomain | 68 | /// Current AppDomain |
71 | /// </summary> | 69 | /// </summary> |
72 | private AppDomainStructure currentAD; | 70 | private AppDomainStructure currentAD; |
71 | |||
73 | private object getLock = new object(); // Mutex | 72 | private object getLock = new object(); // Mutex |
74 | private object freeLock = new object(); // Mutex | 73 | private object freeLock = new object(); // Mutex |
75 | 74 | ||
@@ -94,22 +93,23 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
94 | { | 93 | { |
95 | // Add it to AppDomains list and empty current | 94 | // Add it to AppDomains list and empty current |
96 | appDomains.Add(currentAD); | 95 | appDomains.Add(currentAD); |
97 | currentAD = null; | 96 | currentAD = null; |
98 | } | 97 | } |
99 | // No current | 98 | // No current |
100 | if (currentAD == null) | 99 | if (currentAD == null) |
101 | { | 100 | { |
102 | // Create a new current AppDomain | 101 | // Create a new current AppDomain |
103 | currentAD = new AppDomainStructure(); | 102 | currentAD = new AppDomainStructure(); |
104 | currentAD.CurrentAppDomain = PrepareNewAppDomain(); | 103 | currentAD.CurrentAppDomain = PrepareNewAppDomain(); |
105 | } | 104 | } |
106 | 105 | ||
107 | Console.WriteLine("Scripts loaded in this Appdomain: " + currentAD.ScriptsLoaded); | 106 | Console.WriteLine("Scripts loaded in this Appdomain: " + currentAD.ScriptsLoaded); |
108 | return currentAD; | 107 | return currentAD; |
109 | } // lock | 108 | } // lock |
110 | } | 109 | } |
111 | 110 | ||
112 | private int AppDomainNameCount; | 111 | private int AppDomainNameCount; |
112 | |||
113 | /// <summary> | 113 | /// <summary> |
114 | /// Create and prepare a new AppDomain for scripts | 114 | /// Create and prepare a new AppDomain for scripts |
115 | /// </summary> | 115 | /// </summary> |
@@ -130,12 +130,12 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
130 | ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; | 130 | ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; |
131 | 131 | ||
132 | AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads); | 132 | AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads); |
133 | Console.WriteLine("Loading: " + AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll").ToString()); | 133 | Console.WriteLine("Loading: " + |
134 | AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll").ToString()); | ||
134 | AD.Load(AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll")); | 135 | AD.Load(AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll")); |
135 | 136 | ||
136 | // Return the new AppDomain | 137 | // Return the new AppDomain |
137 | return AD; | 138 | return AD; |
138 | |||
139 | } | 139 | } |
140 | 140 | ||
141 | /// <summary> | 141 | /// <summary> |
@@ -146,7 +146,7 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
146 | lock (freeLock) | 146 | lock (freeLock) |
147 | { | 147 | { |
148 | // Go through all | 148 | // Go through all |
149 | foreach (AppDomainStructure ads in new System.Collections.ArrayList(appDomains)) | 149 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) |
150 | { | 150 | { |
151 | // Don't process current AppDomain | 151 | // Don't process current AppDomain |
152 | if (ads.CurrentAppDomain != currentAD.CurrentAppDomain) | 152 | if (ads.CurrentAppDomain != currentAD.CurrentAppDomain) |
@@ -164,23 +164,25 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
164 | // Unload | 164 | // Unload |
165 | AppDomain.Unload(ads.CurrentAppDomain); | 165 | AppDomain.Unload(ads.CurrentAppDomain); |
166 | #if DEBUG | 166 | #if DEBUG |
167 | Console.WriteLine("AppDomain unload freed " + (m - GC.GetTotalMemory(true)) + " bytes of memory"); | 167 | Console.WriteLine("AppDomain unload freed " + (m - GC.GetTotalMemory(true)) + |
168 | " bytes of memory"); | ||
168 | #endif | 169 | #endif |
169 | } | 170 | } |
170 | } | 171 | } |
171 | } // foreach | 172 | } // foreach |
172 | } // lock | 173 | } // lock |
173 | } | 174 | } |
174 | |||
175 | 175 | ||
176 | 176 | ||
177 | public OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadScript(string FileName) | 177 | public LSL_BaseClass LoadScript(string FileName) |
178 | { | 178 | { |
179 | // Find next available AppDomain to put it in | 179 | // Find next available AppDomain to put it in |
180 | AppDomainStructure FreeAppDomain = GetFreeAppDomain(); | 180 | AppDomainStructure FreeAppDomain = GetFreeAppDomain(); |
181 | 181 | ||
182 | Console.WriteLine("Loading into AppDomain: " + FileName); | 182 | Console.WriteLine("Loading into AppDomain: " + FileName); |
183 | LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); | 183 | LSL_BaseClass mbrt = |
184 | (LSL_BaseClass) | ||
185 | FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); | ||
184 | //Console.WriteLine("ScriptEngine AppDomainManager: is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); | 186 | //Console.WriteLine("ScriptEngine AppDomainManager: is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); |
185 | FreeAppDomain.ScriptsLoaded++; | 187 | FreeAppDomain.ScriptsLoaded++; |
186 | 188 | ||
@@ -207,7 +209,7 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
207 | } | 209 | } |
208 | 210 | ||
209 | // Lopp through all AppDomains | 211 | // Lopp through all AppDomains |
210 | foreach (AppDomainStructure ads in new System.Collections.ArrayList(appDomains)) | 212 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) |
211 | { | 213 | { |
212 | if (ads.CurrentAppDomain == ad) | 214 | if (ads.CurrentAppDomain == ad) |
213 | { | 215 | { |
@@ -219,10 +221,6 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine | |||
219 | } // lock | 221 | } // lock |
220 | 222 | ||
221 | UnloadAppDomains(); // Outsite lock, has its own GetLock | 223 | UnloadAppDomains(); // Outsite lock, has its own GetLock |
222 | |||
223 | |||
224 | } | 224 | } |
225 | |||
226 | |||
227 | } | 225 | } |
228 | } | 226 | } \ No newline at end of file |