diff options
Merge branch 'ubitwork' into avination
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 203 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs | 3 |
2 files changed, 206 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; | |||
33 | using HttpServer; | 33 | using HttpServer; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | 35 | ||
36 | |||
37 | /* | ||
36 | namespace OpenSim.Framework.Servers.HttpServer | 38 | namespace 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 | |||
164 | using System.IO; | ||
165 | using System.Text; | ||
166 | using System.Collections.Generic; | ||
167 | |||
168 | namespace 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 | |||
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs index b39185f..7cd27e5 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 | |||
28 | using System; | 30 | using System; |
29 | using System.Collections; | 31 | using System.Collections; |
30 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
@@ -128,3 +130,4 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
128 | } | 130 | } |
129 | } | 131 | } |
130 | } | 132 | } |
133 | */ \ No newline at end of file | ||