diff options
author | Melanie | 2013-06-11 21:03:02 +0100 |
---|---|---|
committer | Melanie | 2013-06-11 21:03:02 +0100 |
commit | 162dfd8a381999cf5883f4886b9b9aee3a3ad149 (patch) | |
tree | c1c20d043ede7be76e7131218585336ad9df0219 /OpenSim/Framework/Servers/HttpServer | |
parent | Merge branch 'master' into careminster (diff) | |
parent | Put the "script saved" and "notecard saved" messages back into the bottom (diff) | |
download | opensim-SC-162dfd8a381999cf5883f4886b9b9aee3a3ad149.zip opensim-SC-162dfd8a381999cf5883f4886b9b9aee3a3ad149.tar.gz opensim-SC-162dfd8a381999cf5883f4886b9b9aee3a3ad149.tar.bz2 opensim-SC-162dfd8a381999cf5883f4886b9b9aee3a3ad149.tar.xz |
Merge branch 'avination-current' into careminster
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 144 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs | 175 |
2 files changed, 0 insertions, 319 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 | { |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs deleted file mode 100644 index 1c529b6..0000000 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs +++ /dev/null | |||
@@ -1,175 +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 OpenSimulator 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 | |||
28 | /* Ubit work moved to PollServiceRequestManager | ||
29 | |||
30 | using System; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.IO; | ||
34 | using System.Text; | ||
35 | using HttpServer; | ||
36 | using OpenMetaverse; | ||
37 | using System.Reflection; | ||
38 | using log4net; | ||
39 | using OpenSim.Framework.Monitoring; | ||
40 | |||
41 | namespace OpenSim.Framework.Servers.HttpServer | ||
42 | { | ||
43 | public delegate void ReQueuePollServiceItem(PollServiceHttpRequest req); | ||
44 | |||
45 | public class PollServiceWorkerThread | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | public event ReQueuePollServiceItem ReQueue; | ||
52 | |||
53 | private readonly BaseHttpServer m_server; | ||
54 | private BlockingQueue<PollServiceHttpRequest> m_request; | ||
55 | private bool m_running = true; | ||
56 | private int m_timeout = 250; | ||
57 | |||
58 | public PollServiceWorkerThread(BaseHttpServer pSrv, int pTimeout) | ||
59 | { | ||
60 | m_request = new BlockingQueue<PollServiceHttpRequest>(); | ||
61 | m_server = pSrv; | ||
62 | m_timeout = pTimeout; | ||
63 | } | ||
64 | |||
65 | public void ThreadStart() | ||
66 | { | ||
67 | Run(); | ||
68 | } | ||
69 | |||
70 | public void Run() | ||
71 | { | ||
72 | while (m_running) | ||
73 | { | ||
74 | PollServiceHttpRequest req = m_request.Dequeue(); | ||
75 | |||
76 | Watchdog.UpdateThread(); | ||
77 | |||
78 | try | ||
79 | { | ||
80 | if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) | ||
81 | { | ||
82 | StreamReader str; | ||
83 | try | ||
84 | { | ||
85 | str = new StreamReader(req.Request.Body); | ||
86 | } | ||
87 | catch (System.ArgumentException) | ||
88 | { | ||
89 | // Stream was not readable means a child agent | ||
90 | // was closed due to logout, leaving the | ||
91 | // Event Queue request orphaned. | ||
92 | continue; | ||
93 | } | ||
94 | |||
95 | try | ||
96 | { | ||
97 | Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); | ||
98 | DoHTTPGruntWork(m_server, req, responsedata); | ||
99 | } | ||
100 | catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream | ||
101 | { | ||
102 | // Ignore it, no need to reply | ||
103 | } | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | if ((Environment.TickCount - req.RequestTime) > m_timeout) | ||
108 | { | ||
109 | DoHTTPGruntWork( | ||
110 | m_server, | ||
111 | req, | ||
112 | req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | ReQueuePollServiceItem reQueueItem = ReQueue; | ||
117 | if (reQueueItem != null) | ||
118 | reQueueItem(req); | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | catch (Exception e) | ||
123 | { | ||
124 | m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | internal void Enqueue(PollServiceHttpRequest pPollServiceHttpRequest) | ||
130 | { | ||
131 | m_request.Enqueue(pPollServiceHttpRequest); | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// FIXME: This should be part of BaseHttpServer | ||
136 | /// </summary> | ||
137 | internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata) | ||
138 | { | ||
139 | OSHttpResponse response | ||
140 | = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext); | ||
141 | |||
142 | byte[] buffer = server.DoHTTPGruntWork(responsedata, response); | ||
143 | |||
144 | response.SendChunked = false; | ||
145 | response.ContentLength64 = buffer.Length; | ||
146 | response.ContentEncoding = Encoding.UTF8; | ||
147 | |||
148 | try | ||
149 | { | ||
150 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
151 | } | ||
152 | catch (Exception ex) | ||
153 | { | ||
154 | m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex)); | ||
155 | } | ||
156 | finally | ||
157 | { | ||
158 | //response.OutputStream.Close(); | ||
159 | try | ||
160 | { | ||
161 | response.OutputStream.Flush(); | ||
162 | response.Send(); | ||
163 | |||
164 | //if (!response.KeepAlive && response.ReuseContext) | ||
165 | // response.FreeContext(); | ||
166 | } | ||
167 | catch (Exception e) | ||
168 | { | ||
169 | m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e)); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | */ \ No newline at end of file | ||