diff options
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c2254c4..98789be 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | |||
@@ -34,143 +34,6 @@ using HttpServer; | |||
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Monitoring; | 35 | using OpenSim.Framework.Monitoring; |
36 | using Amib.Threading; | 36 | using Amib.Threading; |
37 | |||
38 | |||
39 | /* | ||
40 | namespace OpenSim.Framework.Servers.HttpServer | ||
41 | { | ||
42 | |||
43 | public class PollServiceRequestManager | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private readonly BaseHttpServer m_server; | ||
48 | private static Queue m_requests = Queue.Synchronized(new Queue()); | ||
49 | private static ManualResetEvent m_ev = new ManualResetEvent(false); | ||
50 | private uint m_WorkerThreadCount = 0; | ||
51 | private Thread[] m_workerThreads; | ||
52 | private PollServiceWorkerThread[] m_PollServiceWorkerThreads; | ||
53 | private volatile bool m_running = true; | ||
54 | private int m_pollTimeout; | ||
55 | |||
56 | public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) | ||
57 | { | ||
58 | m_server = pSrv; | ||
59 | m_WorkerThreadCount = pWorkerThreadCount; | ||
60 | m_pollTimeout = pTimeout; | ||
61 | } | ||
62 | |||
63 | public void Start() | ||
64 | { | ||
65 | m_running = true; | ||
66 | m_workerThreads = new Thread[m_WorkerThreadCount]; | ||
67 | m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount]; | ||
68 | |||
69 | //startup worker threads | ||
70 | for (uint i = 0; i < m_WorkerThreadCount; i++) | ||
71 | { | ||
72 | m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, m_pollTimeout); | ||
73 | m_PollServiceWorkerThreads[i].ReQueue += ReQueueEvent; | ||
74 | |||
75 | m_workerThreads[i] | ||
76 | = Watchdog.StartThread( | ||
77 | m_PollServiceWorkerThreads[i].ThreadStart, | ||
78 | String.Format("PollServiceWorkerThread{0}", i), | ||
79 | ThreadPriority.Normal, | ||
80 | false, | ||
81 | true, | ||
82 | int.MaxValue); | ||
83 | } | ||
84 | |||
85 | Watchdog.StartThread( | ||
86 | this.ThreadStart, | ||
87 | "PollServiceWatcherThread", | ||
88 | ThreadPriority.Normal, | ||
89 | false, | ||
90 | true, | ||
91 | 1000 * 60 * 10); | ||
92 | } | ||
93 | |||
94 | internal void ReQueueEvent(PollServiceHttpRequest req) | ||
95 | { | ||
96 | // Do accounting stuff here | ||
97 | Enqueue(req); | ||
98 | } | ||
99 | |||
100 | public void Enqueue(PollServiceHttpRequest req) | ||
101 | { | ||
102 | lock (m_requests) | ||
103 | m_requests.Enqueue(req); | ||
104 | m_ev.Set(); | ||
105 | } | ||
106 | |||
107 | public void ThreadStart() | ||
108 | { | ||
109 | while (m_running) | ||
110 | { | ||
111 | m_ev.WaitOne(1000); | ||
112 | m_ev.Reset(); | ||
113 | Watchdog.UpdateThread(); | ||
114 | ProcessQueuedRequests(); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | private void ProcessQueuedRequests() | ||
119 | { | ||
120 | lock (m_requests) | ||
121 | { | ||
122 | if (m_requests.Count == 0) | ||
123 | return; | ||
124 | |||
125 | // m_log.DebugFormat("[POLL SERVICE REQUEST MANAGER]: Processing {0} requests", m_requests.Count); | ||
126 | |||
127 | int reqperthread = (int) (m_requests.Count/m_WorkerThreadCount) + 1; | ||
128 | |||
129 | // For Each WorkerThread | ||
130 | for (int tc = 0; tc < m_WorkerThreadCount && m_requests.Count > 0; tc++) | ||
131 | { | ||
132 | //Loop over number of requests each thread handles. | ||
133 | for (int i = 0; i < reqperthread && m_requests.Count > 0; i++) | ||
134 | { | ||
135 | try | ||
136 | { | ||
137 | m_PollServiceWorkerThreads[tc].Enqueue((PollServiceHttpRequest)m_requests.Dequeue()); | ||
138 | } | ||
139 | catch (InvalidOperationException) | ||
140 | { | ||
141 | // The queue is empty, we did our calculations wrong! | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | } | ||
150 | |||
151 | public void Stop() | ||
152 | { | ||
153 | m_running = false; | ||
154 | |||
155 | foreach (object o in m_requests) | ||
156 | { | ||
157 | PollServiceHttpRequest req = (PollServiceHttpRequest) o; | ||
158 | m_server.DoHTTPGruntWork( | ||
159 | req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), | ||
160 | new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); | ||
161 | } | ||
162 | |||
163 | m_requests.Clear(); | ||
164 | |||
165 | foreach (Thread t in m_workerThreads) | ||
166 | { | ||
167 | t.Abort(); | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | */ | ||
173 | |||
174 | using System.IO; | 37 | using System.IO; |
175 | using System.Text; | 38 | using System.Text; |
176 | using System.Collections.Generic; | 39 | using System.Collections.Generic; |
@@ -196,8 +59,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
196 | 59 | ||
197 | private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); | 60 | private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); |
198 | 61 | ||
199 | // private int m_timeout = 1000; // increase timeout 250; now use the event one | ||
200 | |||
201 | public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) | 62 | public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) |
202 | { | 63 | { |
203 | m_server = pSrv; | 64 | m_server = pSrv; |
@@ -284,7 +145,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
284 | public void Stop() | 145 | public void Stop() |
285 | { | 146 | { |
286 | m_running = false; | 147 | m_running = false; |
287 | // m_timeout = -10000; // cause all to expire | ||
288 | Thread.Sleep(1000); // let the world move | 148 | Thread.Sleep(1000); // let the world move |
289 | 149 | ||
290 | foreach (Thread t in m_workerThreads) | 150 | foreach (Thread t in m_workerThreads) |
@@ -420,14 +280,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
420 | } | 280 | } |
421 | finally | 281 | finally |
422 | { | 282 | { |
423 | //response.OutputStream.Close(); | ||
424 | try | 283 | try |
425 | { | 284 | { |
426 | response.OutputStream.Flush(); | 285 | response.OutputStream.Flush(); |
427 | response.Send(); | 286 | response.Send(); |
428 | |||
429 | //if (!response.KeepAlive && response.ReuseContext) | ||
430 | // response.FreeContext(); | ||
431 | } | 287 | } |
432 | catch (Exception e) | 288 | catch (Exception e) |
433 | { | 289 | { |