aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/MessagingServer
diff options
context:
space:
mode:
authorTeravus Ovares2008-06-02 16:16:07 +0000
committerTeravus Ovares2008-06-02 16:16:07 +0000
commit3991908db5b50e764112d30e5750447db67795b5 (patch)
treebc5c47d6c26b87dd04c550ed24d5597e686e7663 /OpenSim/Grid/MessagingServer
parentFixed half completed comment in OpenSim.ini.example. (diff)
downloadopensim-SC_OLD-3991908db5b50e764112d30e5750447db67795b5.zip
opensim-SC_OLD-3991908db5b50e764112d30e5750447db67795b5.tar.gz
opensim-SC_OLD-3991908db5b50e764112d30e5750447db67795b5.tar.bz2
opensim-SC_OLD-3991908db5b50e764112d30e5750447db67795b5.tar.xz
* This update enables grid wide presence updates.
* You'll need to start-up the MessageingServer and set it up. It sets up like any of the other grid servers. * All user presence data is kept in memory for speed, while the agent is online. That means if you shutdown the messaging server or the messaging server crashes, it forgets who's online/offline. * Occasionally the region-cache will get stale if regions move around a lot. if it gets stale, run clear-cache on the messaging server console to clear the region cache.
Diffstat (limited to 'OpenSim/Grid/MessagingServer')
-rw-r--r--OpenSim/Grid/MessagingServer/Main.cs22
-rw-r--r--OpenSim/Grid/MessagingServer/MessageService.cs155
-rw-r--r--OpenSim/Grid/MessagingServer/PresenceInformer.cs81
-rw-r--r--OpenSim/Grid/MessagingServer/UserPresenceData.cs1
4 files changed, 229 insertions, 30 deletions
diff --git a/OpenSim/Grid/MessagingServer/Main.cs b/OpenSim/Grid/MessagingServer/Main.cs
index d2fa659..91f2101 100644
--- a/OpenSim/Grid/MessagingServer/Main.cs
+++ b/OpenSim/Grid/MessagingServer/Main.cs
@@ -31,7 +31,9 @@ using System.Reflection;
31using libsecondlife; 31using libsecondlife;
32using log4net; 32using log4net;
33using log4net.Config; 33using log4net.Config;
34
34using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Framework.Communications.Cache;
35using OpenSim.Framework.Console; 37using OpenSim.Framework.Console;
36using OpenSim.Framework.Servers; 38using OpenSim.Framework.Servers;
37 39
@@ -88,6 +90,8 @@ namespace OpenSim.Grid.MessagingServer
88 m_log.Info("[REGION]: Starting HTTP process"); 90 m_log.Info("[REGION]: Starting HTTP process");
89 m_httpServer = new BaseHttpServer(Cfg.HttpPort); 91 m_httpServer = new BaseHttpServer(Cfg.HttpPort);
90 92
93
94
91 msgsvc = new MessageService(Cfg); 95 msgsvc = new MessageService(Cfg);
92 96
93 if (msgsvc.registerWithUserServer()) 97 if (msgsvc.registerWithUserServer())
@@ -144,6 +148,24 @@ namespace OpenSim.Grid.MessagingServer
144 } 148 }
145 } 149 }
146 150
151 public override void RunCmd(string cmd, string[] cmdparams)
152 {
153 base.RunCmd(cmd, cmdparams);
154
155 switch (cmd)
156 {
157 case "help":
158 m_console.Notice("clear-cache - Clears region cache. Should be done when regions change position. The region cache gets stale after a while.");
159 break;
160 case "clear-cache":
161 int entries = msgsvc.ClearRegionCache();
162 m_console.Notice("Region cache cleared! Cleared " + entries.ToString() + " entries");
163 break;
164 }
165
166
167 }
168
147 public override void Shutdown() 169 public override void Shutdown()
148 { 170 {
149 msgsvc.deregisterWithUserServer(); 171 msgsvc.deregisterWithUserServer();
diff --git a/OpenSim/Grid/MessagingServer/MessageService.cs b/OpenSim/Grid/MessagingServer/MessageService.cs
index e1beef1..59fef7e 100644
--- a/OpenSim/Grid/MessagingServer/MessageService.cs
+++ b/OpenSim/Grid/MessagingServer/MessageService.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Grid.MessagingServer
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 private MessageServerConfig m_cfg; 48 private MessageServerConfig m_cfg;
49 private UserManager m_userManager;
49 50
50 //A hashtable of all current presences this server knows about 51 //A hashtable of all current presences this server knows about
51 private Hashtable m_presences = new Hashtable(); 52 private Hashtable m_presences = new Hashtable();
@@ -62,11 +63,16 @@ namespace OpenSim.Grid.MessagingServer
62 public MessageService(MessageServerConfig cfg) 63 public MessageService(MessageServerConfig cfg)
63 { 64 {
64 m_cfg = cfg; 65 m_cfg = cfg;
66 m_userManager = new UserManager();
67 UserConfig uc = new UserConfig();
68 uc.DatabaseConnect = cfg.DatabaseConnect;
69 uc.DatabaseProvider = cfg.DatabaseProvider;
70
71 m_userManager._config = uc;
72 m_userManager.AddPlugin(cfg.DatabaseProvider, cfg.DatabaseConnect);
65 } 73 }
66 74
67 #region RegionComms Methods 75
68
69 #endregion
70 76
71 #region FriendList Methods 77 #region FriendList Methods
72 78
@@ -123,11 +129,27 @@ namespace OpenSim.Grid.MessagingServer
123 { 129 {
124 // we need to send out online status update, but the user is already subscribed 130 // we need to send out online status update, but the user is already subscribed
125 } 131 }
126 PresenceInformer friendlistupdater = new PresenceInformer(); 132 UserAgentData p2Handle = m_userManager.GetUserAgentData(userpresence.agentData.AgentID);
127 friendlistupdater.presence1 = friendpresence; 133 if (p2Handle != null)
128 friendlistupdater.presence2 = userpresence; 134 {
129 WaitCallback cb = new WaitCallback(friendlistupdater.go); 135
130 ThreadPool.QueueUserWorkItem(cb); 136 userpresence.regionData.regionHandle = p2Handle.Handle;
137 PresenceInformer friendlistupdater = new PresenceInformer();
138 friendlistupdater.presence1 = friendpresence;
139 //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
140 //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
141 //friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
142 friendlistupdater.presence2 = userpresence;
143 friendlistupdater.OnGetRegionData += GetRegionInfo;
144 friendlistupdater.OnDone += PresenceUpdateDone;
145 WaitCallback cb = new WaitCallback(friendlistupdater.go);
146 ThreadPool.QueueUserWorkItem(cb);
147
148 }
149 else
150 {
151 // Skip because we can't find any data on the user
152 }
131 153
132 //SendRegionPresenceUpdate(friendpresence, userpresence); 154 //SendRegionPresenceUpdate(friendpresence, userpresence);
133 } 155 }
@@ -143,12 +165,30 @@ namespace OpenSim.Grid.MessagingServer
143 { 165 {
144 // we need to send out online status update, but the user is already subscribed 166 // we need to send out online status update, but the user is already subscribed
145 } 167 }
146 PresenceInformer friendlistupdater = new PresenceInformer(); 168
147 friendlistupdater.presence1 = userpresence; 169 UserAgentData p2Handle = m_userManager.GetUserAgentData(friendpresence.agentData.AgentID);
148 friendlistupdater.presence2 = friendpresence;
149 170
150 WaitCallback cb2 = new WaitCallback(friendlistupdater.go); 171 if (p2Handle != null)
151 ThreadPool.QueueUserWorkItem(cb2); 172 {
173
174 friendpresence.regionData.regionHandle = p2Handle.Handle;
175 PresenceInformer friendlistupdater = new PresenceInformer();
176 friendlistupdater.presence1 = userpresence;
177 friendlistupdater.presence2 = friendpresence;
178 //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
179 //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
180 //friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
181 friendlistupdater.OnGetRegionData += GetRegionInfo;
182 friendlistupdater.OnDone += PresenceUpdateDone;
183 WaitCallback cb2 = new WaitCallback(friendlistupdater.go);
184 ThreadPool.QueueUserWorkItem(cb2);
185 }
186 else
187 {
188 // skip, agent doesn't appear to exist anymore
189 }
190
191
152 192
153 //SendRegionPresenceUpdate(userpresence, friendpresence); 193 //SendRegionPresenceUpdate(userpresence, friendpresence);
154 } 194 }
@@ -209,6 +249,7 @@ namespace OpenSim.Grid.MessagingServer
209 /// <param name="AgentID"></param> 249 /// <param name="AgentID"></param>
210 private void ProcessLogOff(LLUUID AgentID) 250 private void ProcessLogOff(LLUUID AgentID)
211 { 251 {
252 m_log.Info("[LOGOFF]: Processing Logoff");
212 UserPresenceData AgentData = null; 253 UserPresenceData AgentData = null;
213 List<LLUUID> AgentsNeedingNotification = new List<LLUUID>(); 254 List<LLUUID> AgentsNeedingNotification = new List<LLUUID>();
214 UserPresenceData friendd = null; 255 UserPresenceData friendd = null;
@@ -223,6 +264,7 @@ namespace OpenSim.Grid.MessagingServer
223 if (AgentData != null) 264 if (AgentData != null)
224 { 265 {
225 AgentsNeedingNotification = AgentData.subscriptionData; 266 AgentsNeedingNotification = AgentData.subscriptionData;
267 AgentData.OnlineYN = false;
226 //lock (m_presence_BackReferences) 268 //lock (m_presence_BackReferences)
227 //{ 269 //{
228 //if (m_presence_BackReferences.Contains(AgentID)) 270 //if (m_presence_BackReferences.Contains(AgentID))
@@ -262,13 +304,33 @@ namespace OpenSim.Grid.MessagingServer
262 m_presences[AgentsNeedingNotification[i]] = friendd; 304 m_presences[AgentsNeedingNotification[i]] = friendd;
263 } 305 }
264 306
265 PresenceInformer friendlistupdater = new PresenceInformer(); 307 UserAgentData p2Handle = m_userManager.GetUserAgentData(friendd.agentData.AgentID);
266 friendlistupdater.presence1 = AgentData; 308 if (p2Handle != null)
267 friendlistupdater.presence2 = friendd; 309 {
310
311
312 friendd.regionData.regionHandle = p2Handle.Handle;
313 PresenceInformer friendlistupdater = new PresenceInformer();
314 friendlistupdater.presence1 = AgentData;
315 friendlistupdater.presence2 = friendd;
316
317 //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
318 //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
319 //friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
320
321 friendlistupdater.OnGetRegionData += GetRegionInfo;
322 friendlistupdater.OnDone += PresenceUpdateDone;
323
324 WaitCallback cb3 = new WaitCallback(friendlistupdater.go);
325 ThreadPool.QueueUserWorkItem(cb3);
268 326
269 WaitCallback cb3 = new WaitCallback(friendlistupdater.go); 327
270 ThreadPool.QueueUserWorkItem(cb3);
271 328
329 }
330 else
331 {
332 // skip, agent can't be found
333 }
272 //SendRegionPresenceUpdate(AgentData, friendd); 334 //SendRegionPresenceUpdate(AgentData, friendd);
273 335
274 //removeBackReference(AgentID, AgentsNeedingNotification[i]); 336 //removeBackReference(AgentID, AgentsNeedingNotification[i]);
@@ -279,6 +341,12 @@ namespace OpenSim.Grid.MessagingServer
279 341
280 #endregion 342 #endregion
281 343
344 public void PresenceUpdateDone(PresenceInformer obj)
345 {
346 obj.OnGetRegionData -= GetRegionInfo;
347 obj.OnDone -= PresenceUpdateDone;
348 }
349
282 #region UserServer Comms 350 #region UserServer Comms
283 351
284 /// <summary> 352 /// <summary>
@@ -393,7 +461,7 @@ namespace OpenSim.Grid.MessagingServer
393 up.friendData = flData; 461 up.friendData = flData;
394 RegionProfileData riData = GetRegionInfo(regionHandle); 462 RegionProfileData riData = GetRegionInfo(regionHandle);
395 up.regionData = riData; 463 up.regionData = riData;
396 464 up.OnlineYN = true;
397 ProcessFriendListSubscriptions(up); 465 ProcessFriendListSubscriptions(up);
398 466
399 return new XmlRpcResponse(); 467 return new XmlRpcResponse();
@@ -407,6 +475,7 @@ namespace OpenSim.Grid.MessagingServer
407 /// <returns></returns> 475 /// <returns></returns>
408 public XmlRpcResponse UserLoggedOff(XmlRpcRequest request) 476 public XmlRpcResponse UserLoggedOff(XmlRpcRequest request)
409 { 477 {
478 m_log.Info("[USERLOGOFF]: User logged off called");
410 Hashtable requestData = (Hashtable)request.Params[0]; 479 Hashtable requestData = (Hashtable)request.Params[0];
411 480
412 LLUUID AgentID = new LLUUID((string)requestData["agentid"]); 481 LLUUID AgentID = new LLUUID((string)requestData["agentid"]);
@@ -423,23 +492,64 @@ namespace OpenSim.Grid.MessagingServer
423 /// <summary> 492 /// <summary>
424 /// Gets and caches a RegionInfo object from the gridserver based on regionhandle 493 /// Gets and caches a RegionInfo object from the gridserver based on regionhandle
425 /// if the regionhandle is already cached, use the cached values 494 /// if the regionhandle is already cached, use the cached values
495 /// Gets called by lots of threads!!!!!
426 /// </summary> 496 /// </summary>
427 /// <param name="regionhandle">handle to the XY of the region we're looking for</param> 497 /// <param name="regionhandle">handle to the XY of the region we're looking for</param>
428 /// <returns>A RegionInfo object to stick in the presence info</returns> 498 /// <returns>A RegionInfo object to stick in the presence info</returns>
429 public RegionProfileData GetRegionInfo(ulong regionhandle) 499 public RegionProfileData GetRegionInfo(ulong regionhandle)
430 { 500 {
431 RegionProfileData regionInfo = null; 501 RegionProfileData regionInfo = null;
432 if (m_regionInfoCache.Contains(regionhandle)) 502 bool lookup = false;
503
504 lock (m_regionInfoCache)
433 { 505 {
434 regionInfo = (RegionProfileData)m_regionInfoCache[regionhandle]; 506 if (m_regionInfoCache.Contains(regionhandle))
507 {
508 regionInfo = (RegionProfileData)m_regionInfoCache[regionhandle];
509 }
510 else
511 {
512 // Don't lock the cache while we're looking up the region!
513 lookup = true;
514 }
435 } 515 }
436 else 516
517 if (lookup)
437 { 518 {
438 regionInfo = RequestRegionInfo(regionhandle); 519 regionInfo = RequestRegionInfo(regionhandle);
520
521 if (regionInfo != null)
522 {
523 lock (m_regionInfoCache)
524 {
525 if (m_regionInfoCache.Contains(regionhandle))
526 {
527 m_regionInfoCache[regionhandle] = regionInfo;
528 }
529 else
530 {
531 m_regionInfoCache.Add(regionhandle, regionInfo);
532 }
533 }
534 }
439 } 535 }
536
440 return regionInfo; 537 return regionInfo;
441 } 538 }
442 539
540 public int ClearRegionCache()
541 {
542 int cachecount = 0;
543
544 lock (m_regionInfoCache)
545 {
546 cachecount = m_regionInfoCache.Count;
547 m_regionInfoCache.Clear();
548 }
549
550 return cachecount;
551 }
552
443 /// <summary> 553 /// <summary>
444 /// Get RegionProfileData from the GridServer 554 /// Get RegionProfileData from the GridServer
445 /// We'll Cache this information and use it for presence updates 555 /// We'll Cache this information and use it for presence updates
@@ -541,6 +651,7 @@ namespace OpenSim.Grid.MessagingServer
541 // Process Response 651 // Process Response
542 if (GridRespData.ContainsKey("responsestring")) 652 if (GridRespData.ContainsKey("responsestring"))
543 { 653 {
654
544 return true; 655 return true;
545 } 656 }
546 else 657 else
diff --git a/OpenSim/Grid/MessagingServer/PresenceInformer.cs b/OpenSim/Grid/MessagingServer/PresenceInformer.cs
index 59d0e13..050d88a 100644
--- a/OpenSim/Grid/MessagingServer/PresenceInformer.cs
+++ b/OpenSim/Grid/MessagingServer/PresenceInformer.cs
@@ -27,16 +27,31 @@
27 27
28using System.Collections; 28using System.Collections;
29using System.Reflection; 29using System.Reflection;
30using System.Net;
30using log4net; 31using log4net;
31using Nwc.XmlRpc; 32using Nwc.XmlRpc;
32using OpenSim.Data; 33using OpenSim.Data;
33 34
34namespace OpenSim.Grid.MessagingServer 35namespace OpenSim.Grid.MessagingServer
35{ 36{
37 public delegate RegionProfileData GetRegionData(ulong region_handle);
38 public delegate void Done(PresenceInformer obj);
39
40
36 public class PresenceInformer 41 public class PresenceInformer
37 { 42 {
43 public event GetRegionData OnGetRegionData;
44 public event Done OnDone;
45
46 private GetRegionData handlerGetRegionData = null;
47 private Done handlerDone = null;
48
38 public UserPresenceData presence1 = null; 49 public UserPresenceData presence1 = null;
39 public UserPresenceData presence2 = null; 50 public UserPresenceData presence2 = null;
51 public string gridserverurl, gridserversendkey, gridserverrecvkey;
52 public bool lookupRegion = true;
53 //public methodGroup
54
40 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 56
42 public PresenceInformer() 57 public PresenceInformer()
@@ -60,18 +75,68 @@ namespace OpenSim.Grid.MessagingServer
60 public void SendRegionPresenceUpdate(UserPresenceData TalkingAbout, UserPresenceData UserToUpdate) 75 public void SendRegionPresenceUpdate(UserPresenceData TalkingAbout, UserPresenceData UserToUpdate)
61 { 76 {
62 // TODO: Fill in pertenant Presence Data from 'TalkingAbout' 77 // TODO: Fill in pertenant Presence Data from 'TalkingAbout'
78 RegionProfileData whichRegion = new RegionProfileData();
79 if (lookupRegion)
80 {
81 handlerGetRegionData = OnGetRegionData;
82 if (handlerGetRegionData != null)
83 {
84 whichRegion = handlerGetRegionData(UserToUpdate.regionData.regionHandle);
85 }
86 //RegionProfileData rp = RegionProfileData.RequestSimProfileData(UserToUpdate.regionData.regionHandle, gridserverurl, gridserversendkey, gridserverrecvkey);
63 87
64 RegionProfileData whichRegion = UserToUpdate.regionData; 88 //whichRegion = rp;
89 }
90 else
91 {
92 whichRegion = UserToUpdate.regionData;
93 }
65 //whichRegion.httpServerURI 94 //whichRegion.httpServerURI
66 95
67 Hashtable PresenceParams = new Hashtable(); 96 if (whichRegion != null)
68 ArrayList SendParams = new ArrayList(); 97 {
69 SendParams.Add(PresenceParams); 98
99
100 Hashtable PresenceParams = new Hashtable();
101 PresenceParams.Add("agent_id",TalkingAbout.agentData.AgentID.ToString());
102 PresenceParams.Add("notify_id",UserToUpdate.agentData.AgentID.ToString());
103 if (TalkingAbout.OnlineYN)
104 PresenceParams.Add("status","TRUE");
105 else
106 PresenceParams.Add("status","FALSE");
107
108
109
110
111 ArrayList SendParams = new ArrayList();
112 SendParams.Add(PresenceParams);
113
114
115 m_log.Info("[PRESENCE]: Informing " + whichRegion.regionName + " at " + whichRegion.httpServerURI);
116 // Send
117 XmlRpcRequest RegionReq = new XmlRpcRequest("presence_update", SendParams);
118 try
119 {
120
121 XmlRpcResponse RegionResp = RegionReq.Send(whichRegion.httpServerURI, 6000);
122 }
123 catch (WebException)
124 {
125 m_log.WarnFormat("[INFORM]: failed notifying region {0} containing user {1} about {2}", whichRegion.regionName, UserToUpdate.agentData.firstname + " " + UserToUpdate.agentData.lastname, TalkingAbout.agentData.firstname + " " + TalkingAbout.agentData.lastname);
126 }
127 }
128 else
129 {
130 m_log.Info("[PRESENCEUPDATER]: Region data was null skipping");
131
132 }
133
134 handlerDone = OnDone;
135 if (handlerDone != null)
136 {
137 handlerDone(this);
138 }
70 139
71 m_log.Info("[PRESENCE]: Informing " + whichRegion.regionName + " at " + whichRegion.httpServerURI);
72 // Send
73 XmlRpcRequest RegionReq = new XmlRpcRequest("presence_update", SendParams);
74 XmlRpcResponse RegionResp = RegionReq.Send(whichRegion.httpServerURI, 6000);
75 } 140 }
76 } 141 }
77} 142}
diff --git a/OpenSim/Grid/MessagingServer/UserPresenceData.cs b/OpenSim/Grid/MessagingServer/UserPresenceData.cs
index 7188201..74a6032 100644
--- a/OpenSim/Grid/MessagingServer/UserPresenceData.cs
+++ b/OpenSim/Grid/MessagingServer/UserPresenceData.cs
@@ -40,6 +40,7 @@ namespace OpenSim.Grid.MessagingServer
40 public string httpURI = String.Empty; 40 public string httpURI = String.Empty;
41 public List<FriendListItem> friendData = new List<FriendListItem> (); 41 public List<FriendListItem> friendData = new List<FriendListItem> ();
42 public List<LLUUID> subscriptionData = new List<LLUUID>(); 42 public List<LLUUID> subscriptionData = new List<LLUUID>();
43 public bool OnlineYN = false;
43 44
44 public UserPresenceData() 45 public UserPresenceData()
45 { 46 {