diff options
Diffstat (limited to 'OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs')
-rw-r--r-- | OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs | 203 |
1 files changed, 0 insertions, 203 deletions
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs deleted file mode 100644 index 3dad902..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Region.ScriptEngine.Shared; | ||
37 | using OpenSim.ScriptEngine.Shared; | ||
38 | using EventParams=OpenSim.ScriptEngine.Shared.EventParams; | ||
39 | |||
40 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
41 | { | ||
42 | public partial class ScriptManager: IScriptExecutor | ||
43 | { | ||
44 | private const int NoWorkSleepMs = 50; | ||
45 | private const int NoWorkSleepMsInc = 1; // How much time to increase wait with on every iteration | ||
46 | private const int NoWorkSleepMsIncMax = 300; // Max time to wait | ||
47 | |||
48 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | public string Name { get { return "SECS.DotNetEngine.ScriptManager"; } } | ||
50 | private static Thread ScriptLoadUnloadThread; | ||
51 | public Dictionary<uint, Dictionary<UUID, ScriptStructure>> Scripts = new Dictionary<uint, Dictionary<UUID, ScriptStructure>>(); | ||
52 | |||
53 | private RegionInfoStructure CurrentRegion; | ||
54 | public void Initialize(RegionInfoStructure currentRegion) | ||
55 | { | ||
56 | CurrentRegion = currentRegion; | ||
57 | } | ||
58 | |||
59 | public ScriptManager() | ||
60 | { | ||
61 | ScriptLoadUnloadThread = new Thread(LoadUnloadLoop); | ||
62 | ScriptLoadUnloadThread.Name = "ScriptLoadUnloadThread"; | ||
63 | ScriptLoadUnloadThread.IsBackground = true; | ||
64 | ScriptLoadUnloadThread.Start(); | ||
65 | } | ||
66 | public void Close() { } | ||
67 | |||
68 | private void LoadUnloadLoop () | ||
69 | { | ||
70 | int _NoWorkSleepMsInc = 0; | ||
71 | while (true) | ||
72 | { | ||
73 | if (DoScriptLoadUnload()) | ||
74 | { | ||
75 | // We found work, reset counter | ||
76 | _NoWorkSleepMsInc = NoWorkSleepMs; | ||
77 | } else | ||
78 | { | ||
79 | // We didn't find work | ||
80 | // Sleep | ||
81 | Thread.Sleep(NoWorkSleepMs + NoWorkSleepMsInc); | ||
82 | // Increase sleep delay | ||
83 | _NoWorkSleepMsInc += NoWorkSleepMsInc; | ||
84 | // Make sure we don't exceed max | ||
85 | if (_NoWorkSleepMsInc > NoWorkSleepMsIncMax) | ||
86 | _NoWorkSleepMsInc = NoWorkSleepMsIncMax; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #region Add/Remove/Find script functions for our Script memory structure | ||
92 | private void MemAddScript(ScriptStructure script) | ||
93 | { | ||
94 | lock (scriptLock) | ||
95 | { | ||
96 | // Create object if it doesn't exist | ||
97 | if (!Scripts.ContainsKey(script.LocalID)) | ||
98 | Scripts.Add(script.LocalID, new Dictionary<UUID, ScriptStructure>()); | ||
99 | |||
100 | // Delete script if it exists | ||
101 | Dictionary<UUID, ScriptStructure> Obj; | ||
102 | if (Scripts.TryGetValue(script.LocalID, out Obj)) | ||
103 | if (Obj.ContainsKey(script.ItemID) == true) | ||
104 | Obj.Remove(script.ItemID); | ||
105 | |||
106 | // Add to object | ||
107 | Obj.Add(script.ItemID, script); | ||
108 | } | ||
109 | } | ||
110 | private void MemRemoveScript(uint LocalID, UUID ItemID) | ||
111 | { | ||
112 | // TODO: Also clean up command queue and async commands for object | ||
113 | lock (scriptLock) | ||
114 | { | ||
115 | // Create object if it doesn't exist | ||
116 | if (!Scripts.ContainsKey(LocalID)) | ||
117 | return; | ||
118 | |||
119 | // Delete script if it exists | ||
120 | Dictionary<UUID, ScriptStructure> Obj; | ||
121 | if (Scripts.TryGetValue(LocalID, out Obj)) | ||
122 | if (Obj.ContainsKey(ItemID) == true) | ||
123 | Obj.Remove(ItemID); | ||
124 | |||
125 | // Empty? | ||
126 | if (Obj.Count == 0) | ||
127 | Scripts.Remove(LocalID); | ||
128 | |||
129 | } | ||
130 | } | ||
131 | public bool TryGetScript(uint localID, UUID itemID, ref ScriptStructure script) | ||
132 | { | ||
133 | lock (scriptLock) | ||
134 | { | ||
135 | |||
136 | if (Scripts.ContainsKey(localID) == false) | ||
137 | return false; | ||
138 | |||
139 | Dictionary<UUID, ScriptStructure> Obj; | ||
140 | if (Scripts.TryGetValue(localID, out Obj)) | ||
141 | if (Obj.ContainsKey(itemID) == false) | ||
142 | return false; | ||
143 | |||
144 | // Get script | ||
145 | return Obj.TryGetValue(itemID, out script); | ||
146 | } | ||
147 | } | ||
148 | public ScriptStructure GetScript(uint localID, UUID itemID) | ||
149 | { | ||
150 | lock (scriptLock) | ||
151 | { | ||
152 | |||
153 | if (Scripts.ContainsKey(localID) == false) | ||
154 | throw new Exception("No script with LocalID " + localID + " was found."); | ||
155 | |||
156 | Dictionary<UUID, ScriptStructure> Obj; | ||
157 | if (Scripts.TryGetValue(localID, out Obj)) | ||
158 | if (Obj.ContainsKey(itemID) == false) | ||
159 | throw new Exception("No script with ItemID " + itemID + " was found."); | ||
160 | |||
161 | // Get script | ||
162 | return Obj[itemID]; | ||
163 | } | ||
164 | } | ||
165 | public bool TryGetScripts(uint localID, ref Dictionary<UUID, ScriptStructure> returnList) | ||
166 | { | ||
167 | Dictionary<UUID, ScriptStructure> getList = GetScripts(localID); | ||
168 | if (getList != null) | ||
169 | { | ||
170 | returnList = getList; | ||
171 | return true; | ||
172 | } | ||
173 | return false; | ||
174 | } | ||
175 | public Dictionary<UUID, ScriptStructure> GetScripts(uint localID) | ||
176 | { | ||
177 | lock (scriptLock) | ||
178 | { | ||
179 | |||
180 | if (Scripts.ContainsKey(localID) == false) | ||
181 | return null; | ||
182 | return Scripts[localID]; | ||
183 | } | ||
184 | } | ||
185 | #endregion | ||
186 | |||
187 | public void ExecuteCommand(EventParams p) | ||
188 | { | ||
189 | ScriptStructure ss = new ScriptStructure(); | ||
190 | if (TryGetScript(p.LocalID, p.ItemID, ref ss)) | ||
191 | ExecuteCommand(ref ss, p); | ||
192 | } | ||
193 | |||
194 | public void ExecuteCommand(ref ScriptStructure scriptContainer, EventParams p) | ||
195 | { | ||
196 | m_log.DebugFormat("[{0}] ######################################################", Name); | ||
197 | m_log.DebugFormat("[{0}] Command execution ItemID {1}: \"{2}\".", Name, scriptContainer.ItemID, p.EventName); | ||
198 | scriptContainer.ExecuteEvent(p); | ||
199 | m_log.DebugFormat("[{0}] ######################################################", Name); | ||
200 | } | ||
201 | |||
202 | } | ||
203 | } | ||