diff options
Merge branch 'ubitwork' into avination
3 files changed, 244 insertions, 11 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 | ||
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 286c7f0..6c72324 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -302,6 +302,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
302 | 302 | ||
303 | // split static geometry collision into a grid as before | 303 | // split static geometry collision into a grid as before |
304 | private IntPtr[,] staticPrimspace; | 304 | private IntPtr[,] staticPrimspace; |
305 | private IntPtr[] staticPrimspaceOffRegion; | ||
305 | 306 | ||
306 | public Object OdeLock; | 307 | public Object OdeLock; |
307 | private static Object SimulationLock; | 308 | private static Object SimulationLock; |
@@ -551,6 +552,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
551 | // create all spaces now | 552 | // create all spaces now |
552 | int i, j; | 553 | int i, j; |
553 | IntPtr newspace; | 554 | IntPtr newspace; |
555 | |||
554 | for (i = 0; i < spaceGridMaxX; i++) | 556 | for (i = 0; i < spaceGridMaxX; i++) |
555 | for (j = 0; j < spaceGridMaxY; j++) | 557 | for (j = 0; j < spaceGridMaxY; j++) |
556 | { | 558 | { |
@@ -573,6 +575,29 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
573 | // let this now be real maximum values | 575 | // let this now be real maximum values |
574 | spaceGridMaxX--; | 576 | spaceGridMaxX--; |
575 | spaceGridMaxY--; | 577 | spaceGridMaxY--; |
578 | |||
579 | // create 4 off world spaces (x<0,x>max,y<0,y>max) | ||
580 | staticPrimspaceOffRegion = new IntPtr[4]; | ||
581 | |||
582 | for (i = 0; i < 4; i++) | ||
583 | { | ||
584 | newspace = d.HashSpaceCreate(StaticSpace); | ||
585 | d.GeomSetCategoryBits(newspace, (int)CollisionCategories.Space); | ||
586 | waitForSpaceUnlock(newspace); | ||
587 | d.SpaceSetSublevel(newspace, 2); | ||
588 | d.HashSpaceSetLevels(newspace, -2, 8); | ||
589 | d.GeomSetCategoryBits(newspace, (uint)(CollisionCategories.Space | | ||
590 | CollisionCategories.Geom | | ||
591 | CollisionCategories.Land | | ||
592 | CollisionCategories.Water | | ||
593 | CollisionCategories.Phantom | | ||
594 | CollisionCategories.VolumeDtc | ||
595 | )); | ||
596 | d.GeomSetCollideBits(newspace, 0); | ||
597 | |||
598 | staticPrimspaceOffRegion[i] = newspace; | ||
599 | } | ||
600 | |||
576 | m_lastframe = DateTime.UtcNow; | 601 | m_lastframe = DateTime.UtcNow; |
577 | } | 602 | } |
578 | 603 | ||
@@ -1650,20 +1675,22 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1650 | public IntPtr calculateSpaceForGeom(Vector3 pos) | 1675 | public IntPtr calculateSpaceForGeom(Vector3 pos) |
1651 | { | 1676 | { |
1652 | int x, y; | 1677 | int x, y; |
1653 | x = (int)(pos.X * spacesPerMeter); | ||
1654 | if (x < 0) | ||
1655 | x = 0; | ||
1656 | else if (x > spaceGridMaxX) | ||
1657 | x = spaceGridMaxX; | ||
1658 | 1678 | ||
1679 | if (pos.X < 0) | ||
1680 | return staticPrimspaceOffRegion[0]; | ||
1681 | |||
1682 | if (pos.Y < 0) | ||
1683 | return staticPrimspaceOffRegion[2]; | ||
1684 | |||
1685 | x = (int)(pos.X * spacesPerMeter); | ||
1686 | if (x > spaceGridMaxX) | ||
1687 | return staticPrimspaceOffRegion[1]; | ||
1688 | |||
1659 | y = (int)(pos.Y * spacesPerMeter); | 1689 | y = (int)(pos.Y * spacesPerMeter); |
1660 | if (y < 0) | 1690 | if (y > spaceGridMaxY) |
1661 | y = 0; | 1691 | return staticPrimspaceOffRegion[3]; |
1662 | else if (y >spaceGridMaxY) | ||
1663 | y = spaceGridMaxY; | ||
1664 | 1692 | ||
1665 | IntPtr tmpSpace = staticPrimspace[x, y]; | 1693 | return staticPrimspace[x, y]; |
1666 | return tmpSpace; | ||
1667 | } | 1694 | } |
1668 | 1695 | ||
1669 | #endregion | 1696 | #endregion |