From 26cbe5649d1b18122e0ce2aed3acb3121875878c Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 22 Nov 2008 18:54:58 +0000 Subject: Move user server -> message server notifications into a separate thread to make the user server more responsive --- OpenSim/Grid/UserServer/MessageServersConnector.cs | 87 +++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'OpenSim/Grid') 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; using OpenMetaverse; using log4net; using Nwc.XmlRpc; +using OpenSim.Framework; using OpenSim.Framework.Servers; +using System.Threading; namespace OpenSim.Grid.UserServer { + public enum NotificationRequest : int + { + Login = 0, + Logout = 1, + Shutdown = 2 + } + + public struct PresenceNotification + { + public NotificationRequest request; + public UUID agentID; + public UUID sessionID; + public UUID RegionID; + public ulong regionhandle; + public float positionX; + public float positionY; + public float positionZ; + public string firstname; + public string lastname; + }; + public class MessageServersConnector { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public Dictionary MessageServers; + private BlockingQueue m_NotifyQueue = + new BlockingQueue(); + + Thread m_NotifyThread; + public MessageServersConnector() { MessageServers = new Dictionary(); + m_NotifyThread = new Thread(new ThreadStart(NotifyQueueRunner)); + m_NotifyThread.Start(); } public void RegisterMessageServer(string URI, MessageServerInfo serverData) @@ -159,6 +189,26 @@ namespace OpenSim.Grid.UserServer ulong regionhandle, float positionX, float positionY, float positionZ, string firstname, string lastname) { + PresenceNotification notification = new PresenceNotification(); + + notification.request = NotificationRequest.Login; + notification.agentID = agentID; + notification.sessionID = sessionID; + notification.RegionID = RegionID; + notification.regionhandle = regionhandle; + notification.positionX = positionX; + notification.positionY = positionY; + notification.positionZ = positionZ; + notification.firstname = firstname; + notification.lastname = lastname; + + m_NotifyQueue.Enqueue(notification); + } + + private void TellMessageServersAboutUserInternal(UUID agentID, UUID sessionID, UUID RegionID, + ulong regionhandle, float positionX, float positionY, + float positionZ, string firstname, string lastname) + { // Loop over registered Message Servers (AND THERE WILL BE MORE THEN ONE :D) lock (MessageServers) { @@ -179,7 +229,7 @@ namespace OpenSim.Grid.UserServer } } - public void TellMessageServersAboutUserLogoff(UUID agentID) + private void TellMessageServersAboutUserLogoffInternal(UUID agentID) { lock (MessageServers) { @@ -198,6 +248,16 @@ namespace OpenSim.Grid.UserServer } } + public void TellMessageServersAboutUserLogoff(UUID agentID) + { + PresenceNotification notification = new PresenceNotification(); + + notification.request = NotificationRequest.Logout; + notification.agentID = agentID; + + m_NotifyQueue.Enqueue(notification); + } + private void NotifyMessageServerAboutUserLogoff(MessageServerInfo serv, UUID agentID) { Hashtable reqparams = new Hashtable(); @@ -252,5 +312,30 @@ namespace OpenSim.Grid.UserServer } } + + private void NotifyQueueRunner() + { + while (true) + { + PresenceNotification presence = m_NotifyQueue.Dequeue(); + + if (presence.request == NotificationRequest.Shutdown) + return; + + if (presence.request == NotificationRequest.Login) + { + TellMessageServersAboutUserInternal(presence.agentID, + presence.sessionID, presence.RegionID, + presence.regionhandle, presence.positionX, + presence.positionY, presence.positionZ, + presence.firstname, presence.lastname); + } + + if (presence.request == NotificationRequest.Logout) + { + TellMessageServersAboutUserLogoffInternal(presence.agentID); + } + } + } } } -- cgit v1.1