diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs | 84 |
1 files changed, 7 insertions, 77 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs index 1528330..10b83e6 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs | |||
@@ -27,7 +27,6 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | ||
31 | using System.Reflection; | 30 | using System.Reflection; |
32 | using log4net; | 31 | using log4net; |
33 | using Mono.Addins; | 32 | using Mono.Addins; |
@@ -37,8 +36,6 @@ using OpenMetaverse.StructuredData; | |||
37 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
38 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
39 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
40 | using OpenSim.Services.Interfaces; | ||
41 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
42 | 39 | ||
43 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | 40 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups |
44 | { | 41 | { |
@@ -48,7 +45,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
49 | 46 | ||
50 | private List<Scene> m_sceneList = new List<Scene>(); | 47 | private List<Scene> m_sceneList = new List<Scene>(); |
51 | private IPresenceService m_presenceService; | ||
52 | 48 | ||
53 | private IMessageTransferModule m_msgTransferModule = null; | 49 | private IMessageTransferModule m_msgTransferModule = null; |
54 | 50 | ||
@@ -58,27 +54,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
58 | private bool m_groupMessagingEnabled = false; | 54 | private bool m_groupMessagingEnabled = false; |
59 | private bool m_debugEnabled = true; | 55 | private bool m_debugEnabled = true; |
60 | 56 | ||
61 | /// <summary> | ||
62 | /// If enabled, module only tries to send group IMs to online users by querying cached presence information. | ||
63 | /// </summary> | ||
64 | private bool m_messageOnlineAgentsOnly; | ||
65 | |||
66 | /// <summary> | ||
67 | /// Cache for online users. | ||
68 | /// </summary> | ||
69 | /// <remarks> | ||
70 | /// Group ID is key, presence information for online members is value. | ||
71 | /// Will only be non-null if m_messageOnlineAgentsOnly = true | ||
72 | /// We cache here so that group messages don't constantly have to re-request the online user list to avoid | ||
73 | /// attempted expensive sending of messages to offline users. | ||
74 | /// The tradeoff is that a user that comes online will not receive messages consistently from all other users | ||
75 | /// until caches have updated. | ||
76 | /// Therefore, we set the cache expiry to just 20 seconds. | ||
77 | /// </remarks> | ||
78 | private ExpiringCache<UUID, PresenceInfo[]> m_usersOnlineCache; | ||
79 | |||
80 | private int m_usersOnlineCacheExpirySeconds = 20; | ||
81 | |||
82 | #region IRegionModuleBase Members | 57 | #region IRegionModuleBase Members |
83 | 58 | ||
84 | public void Initialise(IConfigSource config) | 59 | public void Initialise(IConfigSource config) |
@@ -108,17 +83,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
108 | return; | 83 | return; |
109 | } | 84 | } |
110 | 85 | ||
111 | m_messageOnlineAgentsOnly = groupsConfig.GetBoolean("MessageOnlineUsersOnly", false); | ||
112 | |||
113 | if (m_messageOnlineAgentsOnly) | ||
114 | m_usersOnlineCache = new ExpiringCache<UUID, PresenceInfo[]>(); | ||
115 | |||
116 | m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true); | 86 | m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true); |
117 | } | 87 | } |
118 | 88 | ||
119 | m_log.InfoFormat( | 89 | m_log.Info("[GROUPS-MESSAGING]: GroupsMessagingModule starting up"); |
120 | "[GROUPS-MESSAGING]: GroupsMessagingModule enabled with MessageOnlineOnly = {0}, DebugEnabled = {1}", | ||
121 | m_messageOnlineAgentsOnly, m_debugEnabled); | ||
122 | } | 90 | } |
123 | 91 | ||
124 | public void AddRegion(Scene scene) | 92 | public void AddRegion(Scene scene) |
@@ -158,8 +126,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
158 | return; | 126 | return; |
159 | } | 127 | } |
160 | 128 | ||
161 | if (m_presenceService == null) | ||
162 | m_presenceService = scene.PresenceService; | ||
163 | 129 | ||
164 | m_sceneList.Add(scene); | 130 | m_sceneList.Add(scene); |
165 | 131 | ||
@@ -241,42 +207,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
241 | public void SendMessageToGroup(GridInstantMessage im, UUID groupID) | 207 | public void SendMessageToGroup(GridInstantMessage im, UUID groupID) |
242 | { | 208 | { |
243 | List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers(new UUID(im.fromAgentID), groupID); | 209 | List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers(new UUID(im.fromAgentID), groupID); |
244 | int groupMembersCount = groupMembers.Count; | 210 | |
245 | 211 | if (m_debugEnabled) | |
246 | if (m_messageOnlineAgentsOnly) | 212 | m_log.DebugFormat( |
247 | { | 213 | "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members", |
248 | string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray(); | 214 | groupID, groupMembers.Count); |
249 | 215 | ||
250 | // We cache in order not to overwhlem the presence service on large grids with many groups. This does | ||
251 | // mean that members coming online will not see all group members until after m_usersOnlineCacheExpirySeconds has elapsed. | ||
252 | // (assuming this is the same across all grid simulators). | ||
253 | PresenceInfo[] onlineAgents; | ||
254 | if (!m_usersOnlineCache.TryGetValue(groupID, out onlineAgents)) | ||
255 | { | ||
256 | onlineAgents = m_presenceService.GetAgents(t1); | ||
257 | m_usersOnlineCache.Add(groupID, onlineAgents, m_usersOnlineCacheExpirySeconds); | ||
258 | } | ||
259 | |||
260 | HashSet<string> onlineAgentsUuidSet = new HashSet<string>(); | ||
261 | Array.ForEach<PresenceInfo>(onlineAgents, pi => onlineAgentsUuidSet.Add(pi.UserID)); | ||
262 | |||
263 | groupMembers = groupMembers.Where(gmd => onlineAgentsUuidSet.Contains(gmd.AgentID.ToString())).ToList(); | ||
264 | |||
265 | // if (m_debugEnabled) | ||
266 | // m_log.DebugFormat( | ||
267 | // "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members, {2} online", | ||
268 | // groupID, groupMembersCount, groupMembers.Count()); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | if (m_debugEnabled) | ||
273 | m_log.DebugFormat( | ||
274 | "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members", | ||
275 | groupID, groupMembers.Count); | ||
276 | } | ||
277 | |||
278 | int requestStartTick = Environment.TickCount; | ||
279 | |||
280 | foreach (GroupMembersData member in groupMembers) | 216 | foreach (GroupMembersData member in groupMembers) |
281 | { | 217 | { |
282 | if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID, groupID)) | 218 | if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID, groupID)) |
@@ -318,12 +254,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
318 | ProcessMessageFromGroupSession(msg); | 254 | ProcessMessageFromGroupSession(msg); |
319 | } | 255 | } |
320 | } | 256 | } |
321 | |||
322 | // Temporary for assessing how long it still takes to send messages to large online groups. | ||
323 | if (m_messageOnlineAgentsOnly) | ||
324 | m_log.DebugFormat( | ||
325 | "[GROUPS-MESSAGING]: SendMessageToGroup for group {0} with {1} visible members, {2} online took {3}ms", | ||
326 | groupID, groupMembersCount, groupMembers.Count(), Environment.TickCount - requestStartTick); | ||
327 | } | 257 | } |
328 | 258 | ||
329 | #region SimGridEventHandlers | 259 | #region SimGridEventHandlers |