diff options
author | Melanie Thielker | 2008-11-22 18:54:58 +0000 |
---|---|---|
committer | Melanie Thielker | 2008-11-22 18:54:58 +0000 |
commit | 26cbe5649d1b18122e0ce2aed3acb3121875878c (patch) | |
tree | 8457281a3a40e584e7a30e53e51cab195785e12f | |
parent | Enclose the inter-region IM sending in a try-catch for now to find possibly m... (diff) | |
download | opensim-SC-26cbe5649d1b18122e0ce2aed3acb3121875878c.zip opensim-SC-26cbe5649d1b18122e0ce2aed3acb3121875878c.tar.gz opensim-SC-26cbe5649d1b18122e0ce2aed3acb3121875878c.tar.bz2 opensim-SC-26cbe5649d1b18122e0ce2aed3acb3121875878c.tar.xz |
Move user server -> message server notifications into a separate thread
to make the user server more responsive
-rw-r--r-- | OpenSim/Grid/UserServer/MessageServersConnector.cs | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/OpenSim/Grid/UserServer/MessageServersConnector.cs b/OpenSim/Grid/UserServer/MessageServersConnector.cs index 8fecd5b..61f125e 100644 --- a/OpenSim/Grid/UserServer/MessageServersConnector.cs +++ b/OpenSim/Grid/UserServer/MessageServersConnector.cs | |||
@@ -32,19 +32,49 @@ using System.Reflection; | |||
32 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using log4net; | 33 | using log4net; |
34 | using Nwc.XmlRpc; | 34 | using Nwc.XmlRpc; |
35 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Servers; | 36 | using OpenSim.Framework.Servers; |
37 | using System.Threading; | ||
36 | 38 | ||
37 | namespace OpenSim.Grid.UserServer | 39 | namespace OpenSim.Grid.UserServer |
38 | { | 40 | { |
41 | public enum NotificationRequest : int | ||
42 | { | ||
43 | Login = 0, | ||
44 | Logout = 1, | ||
45 | Shutdown = 2 | ||
46 | } | ||
47 | |||
48 | public struct PresenceNotification | ||
49 | { | ||
50 | public NotificationRequest request; | ||
51 | public UUID agentID; | ||
52 | public UUID sessionID; | ||
53 | public UUID RegionID; | ||
54 | public ulong regionhandle; | ||
55 | public float positionX; | ||
56 | public float positionY; | ||
57 | public float positionZ; | ||
58 | public string firstname; | ||
59 | public string lastname; | ||
60 | }; | ||
61 | |||
39 | public class MessageServersConnector | 62 | public class MessageServersConnector |
40 | { | 63 | { |
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 64 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 65 | ||
43 | public Dictionary<string, MessageServerInfo> MessageServers; | 66 | public Dictionary<string, MessageServerInfo> MessageServers; |
44 | 67 | ||
68 | private BlockingQueue<PresenceNotification> m_NotifyQueue = | ||
69 | new BlockingQueue<PresenceNotification>(); | ||
70 | |||
71 | Thread m_NotifyThread; | ||
72 | |||
45 | public MessageServersConnector() | 73 | public MessageServersConnector() |
46 | { | 74 | { |
47 | MessageServers = new Dictionary<string, MessageServerInfo>(); | 75 | MessageServers = new Dictionary<string, MessageServerInfo>(); |
76 | m_NotifyThread = new Thread(new ThreadStart(NotifyQueueRunner)); | ||
77 | m_NotifyThread.Start(); | ||
48 | } | 78 | } |
49 | 79 | ||
50 | public void RegisterMessageServer(string URI, MessageServerInfo serverData) | 80 | public void RegisterMessageServer(string URI, MessageServerInfo serverData) |
@@ -159,6 +189,26 @@ namespace OpenSim.Grid.UserServer | |||
159 | ulong regionhandle, float positionX, float positionY, | 189 | ulong regionhandle, float positionX, float positionY, |
160 | float positionZ, string firstname, string lastname) | 190 | float positionZ, string firstname, string lastname) |
161 | { | 191 | { |
192 | PresenceNotification notification = new PresenceNotification(); | ||
193 | |||
194 | notification.request = NotificationRequest.Login; | ||
195 | notification.agentID = agentID; | ||
196 | notification.sessionID = sessionID; | ||
197 | notification.RegionID = RegionID; | ||
198 | notification.regionhandle = regionhandle; | ||
199 | notification.positionX = positionX; | ||
200 | notification.positionY = positionY; | ||
201 | notification.positionZ = positionZ; | ||
202 | notification.firstname = firstname; | ||
203 | notification.lastname = lastname; | ||
204 | |||
205 | m_NotifyQueue.Enqueue(notification); | ||
206 | } | ||
207 | |||
208 | private void TellMessageServersAboutUserInternal(UUID agentID, UUID sessionID, UUID RegionID, | ||
209 | ulong regionhandle, float positionX, float positionY, | ||
210 | float positionZ, string firstname, string lastname) | ||
211 | { | ||
162 | // Loop over registered Message Servers (AND THERE WILL BE MORE THEN ONE :D) | 212 | // Loop over registered Message Servers (AND THERE WILL BE MORE THEN ONE :D) |
163 | lock (MessageServers) | 213 | lock (MessageServers) |
164 | { | 214 | { |
@@ -179,7 +229,7 @@ namespace OpenSim.Grid.UserServer | |||
179 | } | 229 | } |
180 | } | 230 | } |
181 | 231 | ||
182 | public void TellMessageServersAboutUserLogoff(UUID agentID) | 232 | private void TellMessageServersAboutUserLogoffInternal(UUID agentID) |
183 | { | 233 | { |
184 | lock (MessageServers) | 234 | lock (MessageServers) |
185 | { | 235 | { |
@@ -198,6 +248,16 @@ namespace OpenSim.Grid.UserServer | |||
198 | } | 248 | } |
199 | } | 249 | } |
200 | 250 | ||
251 | public void TellMessageServersAboutUserLogoff(UUID agentID) | ||
252 | { | ||
253 | PresenceNotification notification = new PresenceNotification(); | ||
254 | |||
255 | notification.request = NotificationRequest.Logout; | ||
256 | notification.agentID = agentID; | ||
257 | |||
258 | m_NotifyQueue.Enqueue(notification); | ||
259 | } | ||
260 | |||
201 | private void NotifyMessageServerAboutUserLogoff(MessageServerInfo serv, UUID agentID) | 261 | private void NotifyMessageServerAboutUserLogoff(MessageServerInfo serv, UUID agentID) |
202 | { | 262 | { |
203 | Hashtable reqparams = new Hashtable(); | 263 | Hashtable reqparams = new Hashtable(); |
@@ -252,5 +312,30 @@ namespace OpenSim.Grid.UserServer | |||
252 | } | 312 | } |
253 | 313 | ||
254 | } | 314 | } |
315 | |||
316 | private void NotifyQueueRunner() | ||
317 | { | ||
318 | while (true) | ||
319 | { | ||
320 | PresenceNotification presence = m_NotifyQueue.Dequeue(); | ||
321 | |||
322 | if (presence.request == NotificationRequest.Shutdown) | ||
323 | return; | ||
324 | |||
325 | if (presence.request == NotificationRequest.Login) | ||
326 | { | ||
327 | TellMessageServersAboutUserInternal(presence.agentID, | ||
328 | presence.sessionID, presence.RegionID, | ||
329 | presence.regionhandle, presence.positionX, | ||
330 | presence.positionY, presence.positionZ, | ||
331 | presence.firstname, presence.lastname); | ||
332 | } | ||
333 | |||
334 | if (presence.request == NotificationRequest.Logout) | ||
335 | { | ||
336 | TellMessageServersAboutUserLogoffInternal(presence.agentID); | ||
337 | } | ||
338 | } | ||
339 | } | ||
255 | } | 340 | } |
256 | } | 341 | } |