aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs14
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs236
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs3
3 files changed, 251 insertions, 2 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
index 3089351..bb43cd2 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
@@ -45,17 +45,27 @@ namespace OpenSim.Framework.Servers.HttpServer
45 public NoEventsMethod NoEvents; 45 public NoEventsMethod NoEvents;
46 public RequestMethod Request; 46 public RequestMethod Request;
47 public UUID Id; 47 public UUID Id;
48 public int TimeOutms;
49 public EventType Type;
50
51 public enum EventType : int
52 {
53 Normal = 0,
54 LslHttp = 1
55 }
48 56
49 public PollServiceEventArgs( 57 public PollServiceEventArgs(
50 RequestMethod pRequest, 58 RequestMethod pRequest,
51 HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, 59 HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,
52 UUID pId) 60 UUID pId, int pTimeOutms)
53 { 61 {
54 Request = pRequest; 62 Request = pRequest;
55 HasEvents = pHasEvents; 63 HasEvents = pHasEvents;
56 GetEvents = pGetEvents; 64 GetEvents = pGetEvents;
57 NoEvents = pNoEvents; 65 NoEvents = pNoEvents;
58 Id = pId; 66 Id = pId;
67 TimeOutms = pTimeOutms;
68 Type = EventType.Normal;
59 } 69 }
60 } 70 }
61} \ No newline at end of file 71}
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 5bc85ff..3a14b6f 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -33,8 +33,11 @@ using log4net;
33using HttpServer; 33using HttpServer;
34using OpenSim.Framework; 34using OpenSim.Framework;
35 35
36
37/*
36namespace OpenSim.Framework.Servers.HttpServer 38namespace OpenSim.Framework.Servers.HttpServer
37{ 39{
40
38 public class PollServiceRequestManager 41 public class PollServiceRequestManager
39 { 42 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -158,3 +161,236 @@ namespace OpenSim.Framework.Servers.HttpServer
158 } 161 }
159 } 162 }
160} 163}
164 */
165
166using System.IO;
167using System.Text;
168using System.Collections.Generic;
169
170namespace OpenSim.Framework.Servers.HttpServer
171{
172 public class PollServiceRequestManager
173 {
174 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
175
176 private readonly BaseHttpServer m_server;
177
178 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
179 private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
180 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
181
182 private uint m_WorkerThreadCount = 0;
183 private Thread[] m_workerThreads;
184 private Thread m_retrysThread;
185
186 private bool m_running = true;
187 private int slowCount = 0;
188
189 // private int m_timeout = 250; // increase timeout 250; now use the event one
190
191 public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout)
192 {
193 m_server = pSrv;
194 m_WorkerThreadCount = pWorkerThreadCount;
195 m_workerThreads = new Thread[m_WorkerThreadCount];
196
197 //startup worker threads
198 for (uint i = 0; i < m_WorkerThreadCount; i++)
199 {
200 m_workerThreads[i]
201 = Watchdog.StartThread(
202 PoolWorkerJob,
203 String.Format("PollServiceWorkerThread{0}", i),
204 ThreadPriority.Normal,
205 false,
206 true,
207 null,
208 int.MaxValue);
209 }
210
211 m_retrysThread = Watchdog.StartThread(
212 this.CheckRetries,
213 "PollServiceWatcherThread",
214 ThreadPriority.Normal,
215 false,
216 true,
217 null,
218 1000 * 60 * 10);
219 }
220
221
222 private void ReQueueEvent(PollServiceHttpRequest req)
223 {
224 if (m_running)
225 {
226 lock (m_retryRequests)
227 m_retryRequests.Enqueue(req);
228 }
229 }
230
231 public void Enqueue(PollServiceHttpRequest req)
232 {
233 if (m_running)
234 {
235 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp)
236 {
237 m_requests.Enqueue(req);
238 }
239 else
240 {
241 lock (m_slowRequests)
242 m_slowRequests.Enqueue(req);
243 }
244 }
245 }
246
247 private void CheckRetries()
248 {
249 while (m_running)
250 {
251 Thread.Sleep(100); // let the world move .. back to faster rate
252 Watchdog.UpdateThread();
253 lock (m_retryRequests)
254 {
255 while (m_retryRequests.Count > 0 && m_running)
256 m_requests.Enqueue(m_retryRequests.Dequeue());
257 }
258 slowCount++;
259 if (slowCount >= 10)
260 {
261 slowCount = 0;
262
263 lock (m_slowRequests)
264 {
265 while (m_slowRequests.Count > 0 && m_running)
266 m_requests.Enqueue(m_slowRequests.Dequeue());
267 }
268 }
269 }
270 }
271
272 ~PollServiceRequestManager()
273 {
274 m_running = false;
275// m_timeout = -10000; // cause all to expire
276 Thread.Sleep(1000); // let the world move
277
278 foreach (Thread t in m_workerThreads)
279 {
280 try
281 {
282 t.Abort();
283 }
284 catch
285 {
286 }
287 }
288
289 try
290 {
291 foreach (PollServiceHttpRequest req in m_retryRequests)
292 {
293 m_server.DoHTTPGruntWork(
294 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
295 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
296 }
297 }
298 catch
299 {
300 }
301
302 PollServiceHttpRequest wreq;
303 m_retryRequests.Clear();
304
305 lock (m_slowRequests)
306 {
307 while (m_slowRequests.Count > 0 && m_running)
308 m_requests.Enqueue(m_slowRequests.Dequeue());
309 }
310
311 while (m_requests.Count() > 0)
312 {
313 try
314 {
315 wreq = m_requests.Dequeue(0);
316 m_server.DoHTTPGruntWork(
317 wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id),
318 new OSHttpResponse(new HttpResponse(wreq.HttpContext, wreq.Request), wreq.HttpContext));
319 }
320 catch
321 {
322 }
323 }
324
325 m_requests.Clear();
326 }
327
328 // work threads
329
330 private void PoolWorkerJob()
331 {
332 PollServiceHttpRequest req;
333 StreamReader str;
334
335// while (true)
336 while (m_running)
337 {
338 req = m_requests.Dequeue(5000);
339
340 Watchdog.UpdateThread();
341 if (req != null)
342 {
343 try
344 {
345 if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
346 {
347 try
348 {
349 str = new StreamReader(req.Request.Body);
350 }
351 catch (System.ArgumentException)
352 {
353 // Stream was not readable means a child agent
354 // was closed due to logout, leaving the
355 // Event Queue request orphaned.
356 continue;
357 }
358
359 try
360 {
361 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd());
362 m_server.DoHTTPGruntWork(responsedata,
363 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
364 }
365 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
366 {
367 // Ignore it, no need to reply
368 }
369
370 str.Close();
371
372 }
373 else
374 {
375 // if ((Environment.TickCount - req.RequestTime) > m_timeout)
376 if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
377 {
378 m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
379 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
380 }
381 else
382 {
383 ReQueueEvent(req);
384 }
385 }
386 }
387 catch (Exception e)
388 {
389 m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
390 }
391 }
392 }
393 }
394 }
395}
396
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
index d305782..1e3fbf0 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
@@ -25,6 +25,8 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28/* Ubit work moved to PollServiceRequestManager
29
28using System; 30using System;
29using System.Collections; 31using System.Collections;
30using System.Collections.Generic; 32using System.Collections.Generic;
@@ -169,3 +171,4 @@ namespace OpenSim.Framework.Servers.HttpServer
169 } 171 }
170 } 172 }
171} 173}
174*/ \ No newline at end of file