aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
diff options
context:
space:
mode:
authorUbitUmarov2012-07-01 01:33:20 +0100
committerUbitUmarov2012-07-01 01:33:20 +0100
commitd3f1fc79e50edb9ef851bdedfa83e9f5c13b4519 (patch)
tree50f3e51b8ef04880e7392d0f5629665877f7e01c /OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
parentMerge branch 'avination' into ubitwork (diff)
downloadopensim-SC_OLD-d3f1fc79e50edb9ef851bdedfa83e9f5c13b4519.zip
opensim-SC_OLD-d3f1fc79e50edb9ef851bdedfa83e9f5c13b4519.tar.gz
opensim-SC_OLD-d3f1fc79e50edb9ef851bdedfa83e9f5c13b4519.tar.bz2
opensim-SC_OLD-d3f1fc79e50edb9ef851bdedfa83e9f5c13b4519.tar.xz
*TO CHECK/REVIEW/REVERT/TEST whatever* pollService new requests get enqueued to unified requests queue directly. Retries get into that every 100ms. 3 working threads as before plus another that only does retries timming.
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs203
1 files changed, 203 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index c3e1a79..e488b38 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);
@@ -156,3 +159,203 @@ namespace OpenSim.Framework.Servers.HttpServer
156 } 159 }
157 } 160 }
158} 161}
162 */
163
164using System.IO;
165using System.Text;
166using System.Collections.Generic;
167
168namespace OpenSim.Framework.Servers.HttpServer
169{
170 public class PollServiceRequestManager
171 {
172 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
173
174 private readonly BaseHttpServer m_server;
175
176 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
177 private static Queue<PollServiceHttpRequest> m_retry_requests = new Queue<PollServiceHttpRequest>();
178
179 private uint m_WorkerThreadCount = 0;
180 private Thread[] m_workerThreads;
181 private Thread m_retrysThread;
182
183 private bool m_running = true;
184
185 private int m_timeout = 250;
186
187 public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout)
188 {
189 m_server = pSrv;
190 m_WorkerThreadCount = pWorkerThreadCount;
191 m_workerThreads = new Thread[m_WorkerThreadCount];
192
193 //startup worker threads
194 for (uint i = 0; i < m_WorkerThreadCount; i++)
195 {
196 m_workerThreads[i]
197 = Watchdog.StartThread(
198 poolWorkerJob,
199 String.Format("PollServiceWorkerThread{0}", i),
200 ThreadPriority.Normal,
201 false,
202 true,
203 int.MaxValue);
204 }
205
206 m_retrysThread = Watchdog.StartThread(
207 this.CheckRetries,
208 "PollServiceWatcherThread",
209 ThreadPriority.Normal,
210 false,
211 true,
212 1000 * 60 * 10);
213 }
214
215
216 private void ReQueueEvent(PollServiceHttpRequest req)
217 {
218 if (m_running)
219 {
220 lock (m_retry_requests)
221 m_retry_requests.Enqueue(req);
222 }
223 }
224
225 public void Enqueue(PollServiceHttpRequest req)
226 {
227 if (m_running)
228 m_requests.Enqueue(req);
229 }
230
231 private void CheckRetries()
232 {
233 while (m_running)
234 {
235 Thread.Sleep(100); // let the world move
236 Watchdog.UpdateThread();
237 lock (m_retry_requests)
238 {
239 while (m_retry_requests.Count > 0 && m_running)
240 Enqueue(m_retry_requests.Dequeue());
241 }
242 }
243 }
244
245 ~PollServiceRequestManager()
246 {
247 m_running = false;
248 m_timeout = -10000; // cause all to expire
249 Thread.Sleep(1000); // let the world move
250
251 foreach (Thread t in m_workerThreads)
252 {
253 try
254 {
255 t.Abort();
256 }
257 catch
258 {
259 }
260 }
261
262 try
263 {
264 foreach (PollServiceHttpRequest req in m_retry_requests)
265 {
266 m_server.DoHTTPGruntWork(
267 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
268 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
269 }
270 }
271 catch
272 {
273 }
274
275 PollServiceHttpRequest wreq;
276 m_retry_requests.Clear();
277
278 while (m_requests.Count() > 0)
279 {
280 try
281 {
282 wreq = m_requests.Dequeue(0);
283 m_server.DoHTTPGruntWork(
284 wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id),
285 new OSHttpResponse(new HttpResponse(wreq.HttpContext, wreq.Request), wreq.HttpContext));
286 }
287 catch
288 {
289 }
290 }
291
292 m_requests.Clear();
293 }
294
295 // work threads
296
297 private void poolWorkerJob()
298 {
299 PollServiceHttpRequest req;
300 StreamReader str;
301
302 while (true)
303 {
304 req = m_requests.Dequeue(5000);
305
306 Watchdog.UpdateThread();
307 if (req != null)
308 {
309 try
310 {
311 if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
312 {
313 try
314 {
315 str = new StreamReader(req.Request.Body);
316 }
317 catch (System.ArgumentException)
318 {
319 // Stream was not readable means a child agent
320 // was closed due to logout, leaving the
321 // Event Queue request orphaned.
322 continue;
323 }
324
325 try
326 {
327 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd());
328 m_server.DoHTTPGruntWork(responsedata,
329 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
330 }
331 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
332 {
333 // Ignore it, no need to reply
334 }
335
336 str.Close();
337
338 }
339 else
340 {
341 if ((Environment.TickCount - req.RequestTime) > m_timeout)
342 {
343 m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
344 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
345 }
346 else
347 {
348 ReQueueEvent(req);
349 }
350 }
351 }
352 catch (Exception e)
353 {
354 m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
355 }
356 }
357 }
358 }
359 }
360}
361