diff options
author | Teravus Ovares | 2009-07-29 02:15:45 +0000 |
---|---|---|
committer | Teravus Ovares | 2009-07-29 02:15:45 +0000 |
commit | 032aeb8b5d05f5f5a8ef8c6e0fe572a321717c35 (patch) | |
tree | 63d21eaa99b003b47f8eceb09e21b6c4f32ae4f7 /OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |
parent | Add the missing block to the alert message (diff) | |
download | opensim-SC_OLD-032aeb8b5d05f5f5a8ef8c6e0fe572a321717c35.zip opensim-SC_OLD-032aeb8b5d05f5f5a8ef8c6e0fe572a321717c35.tar.gz opensim-SC_OLD-032aeb8b5d05f5f5a8ef8c6e0fe572a321717c35.tar.bz2 opensim-SC_OLD-032aeb8b5d05f5f5a8ef8c6e0fe572a321717c35.tar.xz |
* Adds the ability to have a thread efficient long poll service (such as the eventqueue)
* If this doesn't melt the Http Server, this will significantly reduce the number of threads in use on regions with many users.
* Adds AddPollServiceHTTPHandler, and RemovePollServiceHTTPHandler to BaseHttpServer
* Generic enough to be used for many long poll services, not only the EventQueue.
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 95 |
1 files changed, 90 insertions, 5 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 4532e76..369d7d4 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -64,6 +64,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
64 | protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); | 64 | protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); |
65 | protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); | 65 | protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); |
66 | 66 | ||
67 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = | ||
68 | new Dictionary<string, PollServiceEventArgs>(); | ||
69 | |||
67 | protected uint m_port; | 70 | protected uint m_port; |
68 | protected uint m_sslport; | 71 | protected uint m_sslport; |
69 | protected bool m_ssl; | 72 | protected bool m_ssl; |
@@ -72,6 +75,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
72 | 75 | ||
73 | protected IPAddress m_listenIPAddress = IPAddress.Any; | 76 | protected IPAddress m_listenIPAddress = IPAddress.Any; |
74 | 77 | ||
78 | private PollServiceRequestManager m_PollServiceManager; | ||
79 | |||
75 | public uint SSLPort | 80 | public uint SSLPort |
76 | { | 81 | { |
77 | get { return m_sslport; } | 82 | get { return m_sslport; } |
@@ -189,6 +194,26 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
189 | return false; | 194 | return false; |
190 | } | 195 | } |
191 | 196 | ||
197 | public bool AddPollServiceHTTPHandler(string methodName, GenericHTTPMethod handler, PollServiceEventArgs args) | ||
198 | { | ||
199 | bool pollHandlerResult = false; | ||
200 | lock (m_pollHandlers) | ||
201 | { | ||
202 | if (!m_pollHandlers.ContainsKey( methodName)) | ||
203 | { | ||
204 | m_pollHandlers.Add(methodName,args); | ||
205 | pollHandlerResult = true; | ||
206 | |||
207 | } | ||
208 | } | ||
209 | |||
210 | if (pollHandlerResult) | ||
211 | return AddHTTPHandler(methodName, handler); | ||
212 | |||
213 | return false; | ||
214 | |||
215 | } | ||
216 | |||
192 | // Note that the agent string is provided simply to differentiate | 217 | // Note that the agent string is provided simply to differentiate |
193 | // the handlers - it is NOT required to be an actual agent header | 218 | // the handlers - it is NOT required to be an actual agent header |
194 | // value. | 219 | // value. |
@@ -230,8 +255,19 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
230 | { | 255 | { |
231 | IHttpClientContext context = (IHttpClientContext)source; | 256 | IHttpClientContext context = (IHttpClientContext)source; |
232 | IHttpRequest request = args.Request; | 257 | IHttpRequest request = args.Request; |
258 | |||
233 | 259 | ||
234 | OnHandleRequestIOThread(context,request); | 260 | PollServiceEventArgs psEvArgs; |
261 | if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) | ||
262 | { | ||
263 | |||
264 | m_PollServiceManager.Enqueue(new PollServiceHttpRequest(psEvArgs, context, request)); | ||
265 | //DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request))); | ||
266 | } | ||
267 | else | ||
268 | { | ||
269 | OnHandleRequestIOThread(context, request); | ||
270 | } | ||
235 | 271 | ||
236 | } | 272 | } |
237 | 273 | ||
@@ -341,7 +377,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
341 | string requestBody = reader.ReadToEnd(); | 377 | string requestBody = reader.ReadToEnd(); |
342 | 378 | ||
343 | reader.Close(); | 379 | reader.Close(); |
344 | requestStream.Close(); | 380 | //requestStream.Close(); |
345 | 381 | ||
346 | Hashtable keysvals = new Hashtable(); | 382 | Hashtable keysvals = new Hashtable(); |
347 | Hashtable headervals = new Hashtable(); | 383 | Hashtable headervals = new Hashtable(); |
@@ -527,6 +563,36 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
527 | } | 563 | } |
528 | } | 564 | } |
529 | 565 | ||
566 | private bool TryGetPollServiceHTTPHandler(string handlerKey, out PollServiceEventArgs oServiceEventArgs) | ||
567 | { | ||
568 | string bestMatch = null; | ||
569 | |||
570 | lock (m_pollHandlers) | ||
571 | { | ||
572 | foreach (string pattern in m_pollHandlers.Keys) | ||
573 | { | ||
574 | if (handlerKey.StartsWith(pattern)) | ||
575 | { | ||
576 | if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) | ||
577 | { | ||
578 | bestMatch = pattern; | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | |||
583 | if (String.IsNullOrEmpty(bestMatch)) | ||
584 | { | ||
585 | oServiceEventArgs = null; | ||
586 | return false; | ||
587 | } | ||
588 | else | ||
589 | { | ||
590 | oServiceEventArgs = m_pollHandlers[bestMatch]; | ||
591 | return true; | ||
592 | } | ||
593 | } | ||
594 | } | ||
595 | |||
530 | private bool TryGetHTTPHandler(string handlerKey, out GenericHTTPMethod HTTPHandler) | 596 | private bool TryGetHTTPHandler(string handlerKey, out GenericHTTPMethod HTTPHandler) |
531 | { | 597 | { |
532 | //m_log.DebugFormat("[BASE HTTP HANDLER]: Looking for HTTP handler for {0}", handlerKey); | 598 | //m_log.DebugFormat("[BASE HTTP HANDLER]: Looking for HTTP handler for {0}", handlerKey); |
@@ -822,7 +888,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
822 | { | 888 | { |
823 | response.Send(); | 889 | response.Send(); |
824 | response.OutputStream.Flush(); | 890 | response.OutputStream.Flush(); |
825 | response.OutputStream.Close(); | 891 | //response.OutputStream.Close(); |
826 | } | 892 | } |
827 | catch (IOException e) | 893 | catch (IOException e) |
828 | { | 894 | { |
@@ -1237,7 +1303,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1237 | } | 1303 | } |
1238 | } | 1304 | } |
1239 | 1305 | ||
1240 | private static void DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) | 1306 | internal void DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) |
1241 | { | 1307 | { |
1242 | //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); | 1308 | //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); |
1243 | int responsecode = (int)responsedata["int_response_code"]; | 1309 | int responsecode = (int)responsedata["int_response_code"]; |
@@ -1261,7 +1327,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1261 | } | 1327 | } |
1262 | //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this | 1328 | //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this |
1263 | //and should check for NullReferenceExceptions | 1329 | //and should check for NullReferenceExceptions |
1264 | 1330 | ||
1265 | if (string.IsNullOrEmpty(contentType)) | 1331 | if (string.IsNullOrEmpty(contentType)) |
1266 | { | 1332 | { |
1267 | contentType = "text/html"; | 1333 | contentType = "text/html"; |
@@ -1402,6 +1468,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1402 | //m_workerThread.Start(); | 1468 | //m_workerThread.Start(); |
1403 | //ThreadTracker.Add(m_workerThread); | 1469 | //ThreadTracker.Add(m_workerThread); |
1404 | StartHTTP(); | 1470 | StartHTTP(); |
1471 | |||
1472 | |||
1405 | } | 1473 | } |
1406 | 1474 | ||
1407 | private void StartHTTP() | 1475 | private void StartHTTP() |
@@ -1434,6 +1502,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1434 | m_httpListener2.RequestReceived += OnRequest; | 1502 | m_httpListener2.RequestReceived += OnRequest; |
1435 | //m_httpListener.Start(); | 1503 | //m_httpListener.Start(); |
1436 | m_httpListener2.Start(64); | 1504 | m_httpListener2.Start(64); |
1505 | |||
1506 | // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events | ||
1507 | m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); | ||
1437 | HTTPDRunning = true; | 1508 | HTTPDRunning = true; |
1438 | 1509 | ||
1439 | //HttpListenerContext context; | 1510 | //HttpListenerContext context; |
@@ -1514,6 +1585,20 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1514 | } | 1585 | } |
1515 | } | 1586 | } |
1516 | 1587 | ||
1588 | public void RemovePollServiceHTTPHandler(string httpMethod, string path) | ||
1589 | { | ||
1590 | lock (m_pollHandlers) | ||
1591 | { | ||
1592 | if (m_pollHandlers.ContainsKey(httpMethod)) | ||
1593 | { | ||
1594 | m_pollHandlers.Remove(httpMethod); | ||
1595 | } | ||
1596 | } | ||
1597 | |||
1598 | RemoveHTTPHandler(httpMethod, path); | ||
1599 | |||
1600 | } | ||
1601 | |||
1517 | public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) | 1602 | public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) |
1518 | { | 1603 | { |
1519 | try | 1604 | try |