aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
diff options
context:
space:
mode:
authorTedd Hansen2007-08-18 18:18:14 +0000
committerTedd Hansen2007-08-18 18:18:14 +0000
commit1284369a329d3ae621c0ef0596d01d67e8c70e62 (patch)
treeb6243963c10008b7aeb4ce9e2260becd3c2b21d0 /OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
parentWhen teleporting to distant region, you can now go to the point you want to g... (diff)
downloadopensim-SC-1284369a329d3ae621c0ef0596d01d67e8c70e62.zip
opensim-SC-1284369a329d3ae621c0ef0596d01d67e8c70e62.tar.gz
opensim-SC-1284369a329d3ae621c0ef0596d01d67e8c70e62.tar.bz2
opensim-SC-1284369a329d3ae621c0ef0596d01d67e8c70e62.tar.xz
Started on AppDomains for ScriptEngine. Moved llFunctions in LSL_BaseClass.cs to LSL_BuiltIn_Commands.cs. Changed how scripts are loaded.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs115
1 files changed, 115 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
new file mode 100644
index 0000000..1e20547
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
@@ -0,0 +1,115 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Reflection;
5using System.Threading;
6using System.Runtime.Remoting;
7using System.IO;
8
9namespace OpenSim.Region.ScriptEngine.DotNetEngine
10{
11 public class AppDomainManager
12 {
13 private int MaxScriptsPerAppDomain = 10;
14 private List<AppDomainStructure> AppDomains = new List<AppDomainStructure>();
15 private struct AppDomainStructure
16 {
17 /// <summary>
18 /// The AppDomain itself
19 /// </summary>
20 public AppDomain CurrentAppDomain;
21 /// <summary>
22 /// Number of scripts loaded into AppDomain
23 /// </summary>
24 public int ScriptsLoaded;
25 /// <summary>
26 /// Number of dead scripts
27 /// </summary>
28 public int ScriptsWaitingUnload;
29 }
30 private AppDomainStructure CurrentAD;
31 private object GetLock = new object();
32
33 private ScriptEngine m_scriptEngine;
34 public AppDomainManager(ScriptEngine scriptEngine)
35 {
36 m_scriptEngine = scriptEngine;
37 }
38
39 internal AppDomain GetFreeAppDomain()
40 {
41 lock(GetLock) {
42 // No current or current full?
43 if (CurrentAD.CurrentAppDomain == null || CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain)
44 {
45 // Create a new current AppDomain
46 CurrentAD = new AppDomainStructure();
47 CurrentAD.ScriptsWaitingUnload = 0; // to avoid compile warning for not in use
48 CurrentAD.CurrentAppDomain = PrepareNewAppDomain();
49 AppDomains.Add(CurrentAD);
50
51 }
52
53 // Increase number of scripts loaded
54 CurrentAD.ScriptsLoaded++;
55 // Return AppDomain
56 return CurrentAD.CurrentAppDomain;
57 } // lock
58 }
59
60 private int AppDomainNameCount;
61 private AppDomain PrepareNewAppDomain()
62 {
63 // Create and prepare a new AppDomain
64 AppDomainNameCount++;
65 // TODO: Currently security and configuration match current appdomain
66
67 // Construct and initialize settings for a second AppDomain.
68 AppDomainSetup ads = new AppDomainSetup();
69 ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
70 //Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
71 //ads.ApplicationName = "DotNetScriptEngine";
72 //ads.DynamicBase = ads.ApplicationBase;
73
74 Console.WriteLine("AppDomain BaseDirectory: " + ads.ApplicationBase);
75 ads.DisallowBindingRedirects = false;
76 ads.DisallowCodeDownload = true;
77 ads.ShadowCopyFiles = "true";
78
79 ads.ConfigurationFile =
80 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
81
82 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads);
83 foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
84 {
85 //Console.WriteLine("Loading: " + a.GetName(true));
86 try
87 {
88 AD.Load(a.GetName(true));
89
90 }
91 catch (Exception e)
92 {
93 //Console.WriteLine("FAILED load");
94 }
95
96 }
97
98 Console.WriteLine("Assembly file: " + this.GetType().Assembly.CodeBase);
99 Console.WriteLine("Assembly name: " + this.GetType().ToString());
100 //AD.CreateInstanceFrom(this.GetType().Assembly.CodeBase, "OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine");
101
102 //AD.Load(this.GetType().Assembly.CodeBase);
103
104 Console.WriteLine("Done preparing new appdomain.");
105 return AD;
106
107 }
108
109 public class NOOP : MarshalByRefType
110 {
111 public NOOP() {
112 }
113 }
114 }
115}