aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
authorMelanie2011-10-26 01:27:24 +0100
committerMelanie2011-10-26 01:27:24 +0100
commitfd22159d0c7d7b149d35747cbaa436f3b1e6f579 (patch)
treebbe8cdc63dd1f98346a6afb844f4b4d3caf336a8 /OpenSim/Framework/Servers
parentMerge commit 'e14cb45b9bc4c78300cb804833cb66c1c2e62187' into bigmerge (diff)
parentRestart the event queue worker threads that I accidentally disabled earlier t... (diff)
downloadopensim-SC-fd22159d0c7d7b149d35747cbaa436f3b1e6f579.zip
opensim-SC-fd22159d0c7d7b149d35747cbaa436f3b1e6f579.tar.gz
opensim-SC-fd22159d0c7d7b149d35747cbaa436f3b1e6f579.tar.bz2
opensim-SC-fd22159d0c7d7b149d35747cbaa436f3b1e6f579.tar.xz
Merge branch 'master' into bigmerge
Conflicts: OpenSim/Framework/Watchdog.cs
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs30
-rw-r--r--OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs4
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs40
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs2
-rw-r--r--OpenSim/Framework/Servers/MainServer.cs81
5 files changed, 138 insertions, 19 deletions
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 64b9c3e..66d0813 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -192,6 +192,15 @@ namespace OpenSim.Framework.Servers
192 m_console.Commands.AddCommand("base", false, "show version", 192 m_console.Commands.AddCommand("base", false, "show version",
193 "show version", 193 "show version",
194 "Show server version", HandleShow); 194 "Show server version", HandleShow);
195
196 m_console.Commands.AddCommand("base", false, "threads abort",
197 "threads abort <thread-id>",
198 "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
199
200 m_console.Commands.AddCommand("base", false, "threads show",
201 "threads show",
202 "Show thread status. Synonym for \"show threads\"",
203 (string module, string[] args) => Notice(GetThreadsReport()));
195 } 204 }
196 } 205 }
197 206
@@ -395,6 +404,27 @@ namespace OpenSim.Framework.Servers
395 break; 404 break;
396 } 405 }
397 } 406 }
407
408 public virtual void HandleThreadsAbort(string module, string[] cmd)
409 {
410 if (cmd.Length != 3)
411 {
412 MainConsole.Instance.Output("Usage: threads abort <thread-id>");
413 return;
414 }
415
416 int threadId;
417 if (!int.TryParse(cmd[2], out threadId))
418 {
419 MainConsole.Instance.Output("ERROR: Thread id must be an integer");
420 return;
421 }
422
423 if (Watchdog.AbortThread(threadId))
424 MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId);
425 else
426 MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId);
427 }
398 428
399 protected void ShowInfo() 429 protected void ShowInfo()
400 { 430 {
diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs
index 65b1eb5..fd77984 100644
--- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs
@@ -49,7 +49,7 @@ namespace OpenSim.Framework.Servers.HttpServer
49 /// <summary> 49 /// <summary>
50 /// Add a handler for an HTTP request. 50 /// Add a handler for an HTTP request.
51 /// </summary> 51 /// </summary>
52 /// 52 /// <remarks>
53 /// This handler can actually be invoked either as 53 /// This handler can actually be invoked either as
54 /// 54 ///
55 /// http://<hostname>:<port>/?method=<methodName> 55 /// http://<hostname>:<port>/?method=<methodName>
@@ -70,7 +70,7 @@ namespace OpenSim.Framework.Servers.HttpServer
70 /// In addition, the handler invoked by the HTTP server for any request is the one when best matches the request 70 /// In addition, the handler invoked by the HTTP server for any request is the one when best matches the request
71 /// URI. So if a handler for "/myapp/" is registered and a request for "/myapp/page" is received, then 71 /// URI. So if a handler for "/myapp/" is registered and a request for "/myapp/page" is received, then
72 /// the "/myapp/" handler is invoked if no "/myapp/page" handler exists. 72 /// the "/myapp/" handler is invoked if no "/myapp/page" handler exists.
73 /// 73 /// </remarks>
74 /// <param name="methodName"></param> 74 /// <param name="methodName"></param>
75 /// <param name="handler"></param> 75 /// <param name="handler"></param>
76 /// <returns> 76 /// <returns>
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 0840a9d..d9965b6 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -31,6 +31,7 @@ using System.Threading;
31using System.Reflection; 31using System.Reflection;
32using log4net; 32using log4net;
33using HttpServer; 33using HttpServer;
34using OpenSim.Framework;
34 35
35namespace OpenSim.Framework.Servers.HttpServer 36namespace OpenSim.Framework.Servers.HttpServer
36{ 37{
@@ -54,21 +55,27 @@ namespace OpenSim.Framework.Servers.HttpServer
54 m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount]; 55 m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount];
55 56
56 //startup worker threads 57 //startup worker threads
57 for (uint i=0;i<m_WorkerThreadCount;i++) 58 for (uint i = 0; i < m_WorkerThreadCount; i++)
58 { 59 {
59 m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, pTimeout); 60 m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, pTimeout);
60 m_PollServiceWorkerThreads[i].ReQueue += ReQueueEvent; 61 m_PollServiceWorkerThreads[i].ReQueue += ReQueueEvent;
61 62
62 m_workerThreads[i] = new Thread(m_PollServiceWorkerThreads[i].ThreadStart); 63 m_workerThreads[i]
63 m_workerThreads[i].Name = String.Format("PollServiceWorkerThread{0}",i); 64 = Watchdog.StartThread(
64 //Can't add to thread Tracker here Referencing OpenSim.Framework creates circular reference 65 m_PollServiceWorkerThreads[i].ThreadStart,
65 m_workerThreads[i].Start(); 66 String.Format("PollServiceWorkerThread{0}", i),
67 ThreadPriority.Normal,
68 false,
69 int.MaxValue);
66 } 70 }
67 71
68 //start watcher threads 72 m_watcherThread
69 m_watcherThread = new Thread(ThreadStart); 73 = Watchdog.StartThread(
70 m_watcherThread.Name = "PollServiceWatcherThread"; 74 this.ThreadStart,
71 m_watcherThread.Start(); 75 "PollServiceWatcherThread",
76 ThreadPriority.Normal,
77 false,
78 1000 * 60 * 10);
72 } 79 }
73 80
74 internal void ReQueueEvent(PollServiceHttpRequest req) 81 internal void ReQueueEvent(PollServiceHttpRequest req)
@@ -83,10 +90,11 @@ namespace OpenSim.Framework.Servers.HttpServer
83 m_requests.Enqueue(req); 90 m_requests.Enqueue(req);
84 } 91 }
85 92
86 public void ThreadStart(object o) 93 public void ThreadStart()
87 { 94 {
88 while (m_running) 95 while (m_running)
89 { 96 {
97 Watchdog.UpdateThread();
90 ProcessQueuedRequests(); 98 ProcessQueuedRequests();
91 Thread.Sleep(1000); 99 Thread.Sleep(1000);
92 } 100 }
@@ -107,7 +115,7 @@ namespace OpenSim.Framework.Servers.HttpServer
107 for (int tc = 0; tc < m_WorkerThreadCount && m_requests.Count > 0; tc++) 115 for (int tc = 0; tc < m_WorkerThreadCount && m_requests.Count > 0; tc++)
108 { 116 {
109 //Loop over number of requests each thread handles. 117 //Loop over number of requests each thread handles.
110 for (int i=0;i<reqperthread && m_requests.Count > 0;i++) 118 for (int i = 0; i < reqperthread && m_requests.Count > 0; i++)
111 { 119 {
112 try 120 try
113 { 121 {
@@ -125,14 +133,14 @@ namespace OpenSim.Framework.Servers.HttpServer
125 133
126 } 134 }
127 135
128
129
130 ~PollServiceRequestManager() 136 ~PollServiceRequestManager()
131 { 137 {
132 foreach (object o in m_requests) 138 foreach (object o in m_requests)
133 { 139 {
134 PollServiceHttpRequest req = (PollServiceHttpRequest) o; 140 PollServiceHttpRequest req = (PollServiceHttpRequest) o;
135 m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); 141 m_server.DoHTTPGruntWork(
142 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
143 new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
136 } 144 }
137 145
138 m_requests.Clear(); 146 m_requests.Clear();
@@ -144,4 +152,4 @@ namespace OpenSim.Framework.Servers.HttpServer
144 m_running = false; 152 m_running = false;
145 } 153 }
146 } 154 }
147} 155} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
index b91496b..16e56d2 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Framework.Servers.HttpServer
59 m_timeout = pTimeout; 59 m_timeout = pTimeout;
60 } 60 }
61 61
62 public void ThreadStart(object o) 62 public void ThreadStart()
63 { 63 {
64 Run(); 64 Run();
65 } 65 }
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs
new file mode 100644
index 0000000..b8ab8d9
--- /dev/null
+++ b/OpenSim/Framework/Servers/MainServer.cs
@@ -0,0 +1,81 @@
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
28using System.Collections.Generic;
29using System.Reflection;
30using System.Net;
31using log4net;
32using OpenSim.Framework.Servers.HttpServer;
33
34namespace OpenSim.Framework.Servers
35{
36 public class MainServer
37 {
38 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39
40 private static BaseHttpServer instance = null;
41 private static Dictionary<uint, BaseHttpServer> m_Servers =
42 new Dictionary<uint, BaseHttpServer>();
43
44 public static BaseHttpServer Instance
45 {
46 get { return instance; }
47 set { instance = value; }
48 }
49
50 public static IHttpServer GetHttpServer(uint port)
51 {
52 return GetHttpServer(port,null);
53 }
54
55 public static void AddHttpServer(BaseHttpServer server)
56 {
57 m_Servers.Add(server.Port, server);
58 }
59
60 public static IHttpServer GetHttpServer(uint port, IPAddress ipaddr)
61 {
62 if (port == 0)
63 return Instance;
64 if (instance != null && port == Instance.Port)
65 return Instance;
66
67 if (m_Servers.ContainsKey(port))
68 return m_Servers[port];
69
70 m_Servers[port] = new BaseHttpServer(port);
71
72 if (ipaddr != null)
73 m_Servers[port].ListenIPAddress = ipaddr;
74
75 m_log.InfoFormat("[MAIN HTTP SERVER]: Starting main http server on port {0}", port);
76 m_Servers[port].Start();
77
78 return m_Servers[port];
79 }
80 }
81}