aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-25 05:13:44 +0000
committerMelanie Thielker2008-09-25 05:13:44 +0000
commitf3c8963c86dbc969541ede80ae37eb59d26b7809 (patch)
treeff1e5cea74e9d5c2b73c476320a7bddf11d93766 /OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs
parentMantis#2123. Thank you kindly, Idb for a patch that solves: (diff)
downloadopensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.zip
opensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.tar.gz
opensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.tar.bz2
opensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.tar.xz
Convergence is almost complete. This brings the diff between the API to < 10k
and makes it use a common set of types in both engine. Fixes the issues with running both engines and HTTP requests / listens / timers etc.. Also fixes a couple of minor Scene issues and a CTB by nullref.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs234
1 files changed, 0 insertions, 234 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs
deleted file mode 100644
index 5fa6010..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs
+++ /dev/null
@@ -1,234 +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 OpenSim 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
28using System.Collections;
29using System.Threading;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins;
34using Timer=OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins.Timer;
35
36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
37{
38 /// <summary>
39 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
40 /// </summary>
41 public class AsyncCommandManager : iScriptEngineFunctionModule
42 {
43 private static Thread cmdHandlerThread;
44 private static int cmdHandlerThreadCycleSleepms;
45
46 public ScriptEngine m_ScriptEngine;
47
48 private Timer m_Timer;
49 private HttpRequest m_HttpRequest;
50 private Listener m_Listener;
51 private SensorRepeat m_SensorRepeat;
52 private XmlRequest m_XmlRequest;
53 private Dataserver m_Dataserver;
54
55 public Dataserver DataserverPlugin
56 {
57 get { return m_Dataserver; }
58 }
59
60 public Timer TimerPlugin
61 {
62 get { return m_Timer; }
63 }
64
65 public HttpRequest HttpRequestPlugin
66 {
67 get { return m_HttpRequest; }
68 }
69
70 public Listener ListenerPlugin
71 {
72 get { return m_Listener; }
73 }
74
75 public SensorRepeat SensorRepeatPlugin
76 {
77 get { return m_SensorRepeat; }
78 }
79
80 public XmlRequest XmlRequestPlugin
81 {
82 get { return m_XmlRequest; }
83 }
84
85 public AsyncCommandManager(ScriptEngine _ScriptEngine)
86 {
87 m_ScriptEngine = _ScriptEngine;
88 ReadConfig();
89
90 // Create instances of all plugins
91 m_Timer = new Timer(this);
92 m_HttpRequest = new HttpRequest(this);
93 m_Listener = new Listener(this);
94 m_SensorRepeat = new SensorRepeat(this);
95 m_XmlRequest = new XmlRequest(this);
96 m_Dataserver = new Dataserver(this);
97
98 StartThread();
99 }
100
101 private static void StartThread()
102 {
103 if (cmdHandlerThread == null)
104 {
105 // Start the thread that will be doing the work
106 cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
107 cmdHandlerThread.Name = "AsyncLSLCmdHandlerThread";
108 cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
109 cmdHandlerThread.IsBackground = true;
110 cmdHandlerThread.Start();
111 ThreadTracker.Add(cmdHandlerThread);
112 }
113 }
114
115 public void ReadConfig()
116 {
117 cmdHandlerThreadCycleSleepms = m_ScriptEngine.ScriptConfigSource.GetInt("AsyncLLCommandLoopms", 100);
118 }
119
120 ~AsyncCommandManager()
121 {
122 // Shut down thread
123 try
124 {
125 if (cmdHandlerThread != null)
126 {
127 if (cmdHandlerThread.IsAlive == true)
128 {
129 cmdHandlerThread.Abort();
130 //cmdHandlerThread.Join();
131 }
132 }
133 }
134 catch
135 {
136 }
137 }
138
139 private static void CmdHandlerThreadLoop()
140 {
141 while (true)
142 {
143 try
144 {
145 while (true)
146 {
147 Thread.Sleep(cmdHandlerThreadCycleSleepms);
148 //lock (ScriptEngine.ScriptEngines)
149 //{
150 foreach (ScriptEngine se in new ArrayList(ScriptEngine.ScriptEngines))
151 {
152 se.m_ASYNCLSLCommandManager.DoOneCmdHandlerPass();
153 }
154 //}
155 // Sleep before next cycle
156 //Thread.Sleep(cmdHandlerThreadCycleSleepms);
157 }
158 }
159 catch
160 {
161 }
162 }
163 }
164
165 internal void DoOneCmdHandlerPass()
166 {
167 // Check timers
168 m_Timer.CheckTimerEvents();
169 // Check HttpRequests
170 m_HttpRequest.CheckHttpRequests();
171 // Check XMLRPCRequests
172 m_XmlRequest.CheckXMLRPCRequests();
173 // Check Listeners
174 m_Listener.CheckListeners();
175 // Check Sensors
176 m_SensorRepeat.CheckSenseRepeaterEvents();
177 // Check dataserver
178 m_Dataserver.ExpireRequests();
179 }
180
181 /// <summary>
182 /// Remove a specific script (and all its pending commands)
183 /// </summary>
184 /// <param name="localID"></param>
185 /// <param name="itemID"></param>
186 public void RemoveScript(uint localID, UUID itemID)
187 {
188 // Remove a specific script
189
190 // Remove from: Timers
191 m_Timer.UnSetTimerEvents(localID, itemID);
192
193 // Remove from: HttpRequest
194 IHttpRequests iHttpReq =
195 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
196 iHttpReq.StopHttpRequest(localID, itemID);
197
198 IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
199 comms.DeleteListener(itemID);
200
201 IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
202 xmlrpc.DeleteChannels(itemID);
203 xmlrpc.CancelSRDRequests(itemID);
204
205 // Remove Sensors
206 m_SensorRepeat.UnSetSenseRepeaterEvents(localID, itemID);
207
208 // Remove queries
209 m_Dataserver.RemoveEvents(localID, itemID);
210
211 }
212
213
214 #region Check llRemoteData channels
215
216
217 #endregion
218
219 #region Check llListeners
220
221
222 #endregion
223
224 /// <summary>
225 /// If set to true then threads and stuff should try to make a graceful exit
226 /// </summary>
227 public bool PleaseShutdown
228 {
229 get { return _PleaseShutdown; }
230 set { _PleaseShutdown = value; }
231 }
232 private bool _PleaseShutdown = false;
233 }
234}