diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs | 183 |
1 files changed, 122 insertions, 61 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs index 4867c01..9363205 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs | |||
@@ -167,6 +167,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
167 | 167 | ||
168 | private bool m_debugEnabled = false; | 168 | private bool m_debugEnabled = false; |
169 | 169 | ||
170 | private ExpiringCache<string, OSDMap> m_memoryCache; | ||
171 | private int m_cacheTimeout = 30; | ||
172 | |||
170 | // private IUserAccountService m_accountService = null; | 173 | // private IUserAccountService m_accountService = null; |
171 | 174 | ||
172 | 175 | ||
@@ -203,17 +206,33 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
203 | return; | 206 | return; |
204 | } | 207 | } |
205 | 208 | ||
206 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Initializing {0}", this.Name); | 209 | m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR]: Initializing {0}", this.Name); |
207 | 210 | ||
208 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); | 211 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); |
209 | if ((m_groupsServerURI == null) || | 212 | if ((m_groupsServerURI == null) || |
210 | (m_groupsServerURI == string.Empty)) | 213 | (m_groupsServerURI == string.Empty)) |
211 | { | 214 | { |
212 | m_log.ErrorFormat("Please specify a valid Simian Server for GroupsServerURI in OpenSim.ini, [Groups]"); | 215 | m_log.ErrorFormat("Please specify a valid Simian Server for GroupsServerURI in OpenSim.ini, [Groups]"); |
213 | m_connectorEnabled = false; | 216 | m_connectorEnabled = false; |
214 | return; | 217 | return; |
215 | } | 218 | } |
216 | 219 | ||
220 | |||
221 | m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30); | ||
222 | if (m_cacheTimeout == 0) | ||
223 | { | ||
224 | m_log.WarnFormat("[SIMIAN-GROUPS-CONNECTOR] Groups Cache Disabled."); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR] Groups Cache Timeout set to {0}.", m_cacheTimeout); | ||
229 | } | ||
230 | |||
231 | |||
232 | |||
233 | m_memoryCache = new ExpiringCache<string,OSDMap>(); | ||
234 | |||
235 | |||
217 | // If we got all the config options we need, lets start'er'up | 236 | // If we got all the config options we need, lets start'er'up |
218 | m_connectorEnabled = true; | 237 | m_connectorEnabled = true; |
219 | 238 | ||
@@ -224,7 +243,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
224 | 243 | ||
225 | public void Close() | 244 | public void Close() |
226 | { | 245 | { |
227 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Closing {0}", this.Name); | 246 | m_log.InfoFormat("[SIMIAN-GROUPS-CONNECTOR]: Closing {0}", this.Name); |
228 | } | 247 | } |
229 | 248 | ||
230 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) | 249 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) |
@@ -657,7 +676,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
657 | }; | 676 | }; |
658 | 677 | ||
659 | 678 | ||
660 | OSDMap response = WebUtil.PostToService(m_groupsServerURI, requestArgs); | 679 | OSDMap response = CachedPostRequest(requestArgs); |
661 | if (response["Success"].AsBoolean() && response["Entries"] is OSDArray) | 680 | if (response["Success"].AsBoolean() && response["Entries"] is OSDArray) |
662 | { | 681 | { |
663 | OSDArray entryArray = (OSDArray)response["Entries"]; | 682 | OSDArray entryArray = (OSDArray)response["Entries"]; |
@@ -1000,53 +1019,53 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1000 | SimianAddGeneric(groupID, "GroupNotice", noticeID.ToString(), Notice); | 1019 | SimianAddGeneric(groupID, "GroupNotice", noticeID.ToString(), Notice); |
1001 | 1020 | ||
1002 | } | 1021 | } |
1003 | #endregion | 1022 | #endregion |
1004 | 1023 | ||
1005 | #region GroupSessionTracking | 1024 | #region GroupSessionTracking |
1006 | 1025 | ||
1007 | public void ResetAgentGroupChatSessions(UUID agentID) | 1026 | public void ResetAgentGroupChatSessions(UUID agentID) |
1008 | { | 1027 | { |
1009 | Dictionary<string, OSDMap> agentSessions; | 1028 | Dictionary<string, OSDMap> agentSessions; |
1010 | 1029 | ||
1011 | if (SimianGetGenericEntries(agentID, "GroupSessionDropped", out agentSessions)) | 1030 | if (SimianGetGenericEntries(agentID, "GroupSessionDropped", out agentSessions)) |
1012 | { | 1031 | { |
1013 | foreach (string GroupID in agentSessions.Keys) | 1032 | foreach (string GroupID in agentSessions.Keys) |
1014 | { | 1033 | { |
1015 | SimianRemoveGenericEntry(agentID, "GroupSessionDropped", GroupID); | 1034 | SimianRemoveGenericEntry(agentID, "GroupSessionDropped", GroupID); |
1016 | } | 1035 | } |
1017 | } | 1036 | } |
1018 | 1037 | ||
1019 | if (SimianGetGenericEntries(agentID, "GroupSessionInvited", out agentSessions)) | 1038 | if (SimianGetGenericEntries(agentID, "GroupSessionInvited", out agentSessions)) |
1020 | { | 1039 | { |
1021 | foreach (string GroupID in agentSessions.Keys) | 1040 | foreach (string GroupID in agentSessions.Keys) |
1022 | { | 1041 | { |
1023 | SimianRemoveGenericEntry(agentID, "GroupSessionInvited", GroupID); | 1042 | SimianRemoveGenericEntry(agentID, "GroupSessionInvited", GroupID); |
1024 | } | 1043 | } |
1025 | } | 1044 | } |
1026 | } | 1045 | } |
1027 | 1046 | ||
1028 | public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID) | 1047 | public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID) |
1029 | { | 1048 | { |
1030 | OSDMap session; | 1049 | OSDMap session; |
1031 | return SimianGetGenericEntry(agentID, "GroupSessionDropped", groupID.ToString(), out session); | 1050 | return SimianGetGenericEntry(agentID, "GroupSessionDropped", groupID.ToString(), out session); |
1032 | } | 1051 | } |
1033 | 1052 | ||
1034 | public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID) | 1053 | public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID) |
1035 | { | 1054 | { |
1036 | SimianAddGeneric(agentID, "GroupSessionDropped", groupID.ToString(), new OSDMap()); | 1055 | SimianAddGeneric(agentID, "GroupSessionDropped", groupID.ToString(), new OSDMap()); |
1037 | } | 1056 | } |
1038 | 1057 | ||
1039 | public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID) | 1058 | public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID) |
1040 | { | 1059 | { |
1041 | SimianAddGeneric(agentID, "GroupSessionInvited", groupID.ToString(), new OSDMap()); | 1060 | SimianAddGeneric(agentID, "GroupSessionInvited", groupID.ToString(), new OSDMap()); |
1042 | } | 1061 | } |
1043 | 1062 | ||
1044 | public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID) | 1063 | public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID) |
1045 | { | 1064 | { |
1046 | OSDMap session; | 1065 | OSDMap session; |
1047 | return SimianGetGenericEntry(agentID, "GroupSessionDropped", groupID.ToString(), out session); | 1066 | return SimianGetGenericEntry(agentID, "GroupSessionDropped", groupID.ToString(), out session); |
1048 | } | 1067 | } |
1049 | 1068 | ||
1050 | #endregion | 1069 | #endregion |
1051 | 1070 | ||
1052 | private void EnsureRoleNotSelectedByMember(UUID groupID, UUID roleID, UUID userID) | 1071 | private void EnsureRoleNotSelectedByMember(UUID groupID, UUID roleID, UUID userID) |
@@ -1086,7 +1105,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1086 | }; | 1105 | }; |
1087 | 1106 | ||
1088 | 1107 | ||
1089 | OSDMap Response = WebUtil.PostToService(m_groupsServerURI, RequestArgs); | 1108 | OSDMap Response = CachedPostRequest(RequestArgs); |
1090 | if (Response["Success"].AsBoolean()) | 1109 | if (Response["Success"].AsBoolean()) |
1091 | { | 1110 | { |
1092 | return true; | 1111 | return true; |
@@ -1113,7 +1132,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1113 | }; | 1132 | }; |
1114 | 1133 | ||
1115 | 1134 | ||
1116 | OSDMap Response = WebUtil.PostToService(m_groupsServerURI, RequestArgs); | 1135 | OSDMap Response = CachedPostRequest(RequestArgs); |
1117 | if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray) | 1136 | if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray) |
1118 | { | 1137 | { |
1119 | OSDArray entryArray = (OSDArray)Response["Entries"]; | 1138 | OSDArray entryArray = (OSDArray)Response["Entries"]; |
@@ -1153,7 +1172,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1153 | }; | 1172 | }; |
1154 | 1173 | ||
1155 | 1174 | ||
1156 | OSDMap Response = WebUtil.PostToService(m_groupsServerURI, RequestArgs); | 1175 | OSDMap Response = CachedPostRequest(RequestArgs); |
1157 | if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray) | 1176 | if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray) |
1158 | { | 1177 | { |
1159 | OSDArray entryArray = (OSDArray)Response["Entries"]; | 1178 | OSDArray entryArray = (OSDArray)Response["Entries"]; |
@@ -1194,7 +1213,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1194 | }; | 1213 | }; |
1195 | 1214 | ||
1196 | 1215 | ||
1197 | OSDMap Response = WebUtil.PostToService(m_groupsServerURI, RequestArgs); | 1216 | OSDMap Response = CachedPostRequest(RequestArgs); |
1198 | if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray) | 1217 | if (Response["Success"].AsBoolean() && Response["Entries"] is OSDArray) |
1199 | { | 1218 | { |
1200 | OSDArray entryArray = (OSDArray)Response["Entries"]; | 1219 | OSDArray entryArray = (OSDArray)Response["Entries"]; |
@@ -1234,7 +1253,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1234 | 1253 | ||
1235 | 1254 | ||
1236 | 1255 | ||
1237 | OSDMap response = WebUtil.PostToService(m_groupsServerURI, requestArgs); | 1256 | OSDMap response = CachedPostRequest(requestArgs); |
1238 | if (response["Success"].AsBoolean() && response["Entries"] is OSDArray) | 1257 | if (response["Success"].AsBoolean() && response["Entries"] is OSDArray) |
1239 | { | 1258 | { |
1240 | maps = new Dictionary<string, OSDMap>(); | 1259 | maps = new Dictionary<string, OSDMap>(); |
@@ -1272,7 +1291,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1272 | 1291 | ||
1273 | 1292 | ||
1274 | 1293 | ||
1275 | OSDMap response = WebUtil.PostToService(m_groupsServerURI, requestArgs); | 1294 | OSDMap response = CachedPostRequest(requestArgs); |
1276 | if (response["Success"].AsBoolean() && response["Entries"] is OSDArray) | 1295 | if (response["Success"].AsBoolean() && response["Entries"] is OSDArray) |
1277 | { | 1296 | { |
1278 | maps = new Dictionary<UUID, OSDMap>(); | 1297 | maps = new Dictionary<UUID, OSDMap>(); |
@@ -1310,7 +1329,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1310 | }; | 1329 | }; |
1311 | 1330 | ||
1312 | 1331 | ||
1313 | OSDMap response = WebUtil.PostToService(m_groupsServerURI, requestArgs); | 1332 | OSDMap response = CachedPostRequest(requestArgs); |
1314 | if (response["Success"].AsBoolean()) | 1333 | if (response["Success"].AsBoolean()) |
1315 | { | 1334 | { |
1316 | return true; | 1335 | return true; |
@@ -1321,8 +1340,50 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1321 | return false; | 1340 | return false; |
1322 | } | 1341 | } |
1323 | } | 1342 | } |
1324 | #endregion | 1343 | #endregion |
1325 | 1344 | ||
1345 | #region CheesyCache | ||
1346 | OSDMap CachedPostRequest(NameValueCollection requestArgs) | ||
1347 | { | ||
1348 | // Immediately forward the request if the cache is disabled. | ||
1349 | if (m_cacheTimeout == 0) | ||
1350 | { | ||
1351 | return WebUtil.PostToService(m_groupsServerURI, requestArgs); | ||
1352 | } | ||
1353 | |||
1354 | // Check if this is an update or a request | ||
1355 | if ( requestArgs["RequestMethod"] == "RemoveGeneric" | ||
1356 | || requestArgs["RequestMethod"] == "AddGeneric" | ||
1357 | ) | ||
1358 | |||
1359 | { | ||
1360 | // Any and all updates cause the cache to clear | ||
1361 | m_memoryCache.Clear(); | ||
1362 | |||
1363 | // Send update to server, return the response without caching it | ||
1364 | return WebUtil.PostToService(m_groupsServerURI, requestArgs); | ||
1365 | |||
1366 | } | ||
1367 | |||
1368 | // If we're not doing an update, we must be requesting data | ||
1369 | |||
1370 | // Create the cache key for the request and see if we have it cached | ||
1371 | string CacheKey = WebUtil.BuildQueryString(requestArgs); | ||
1372 | OSDMap response = null; | ||
1373 | if (!m_memoryCache.TryGetValue(CacheKey, out response)) | ||
1374 | { | ||
1375 | // if it wasn't in the cache, pass the request to the Simian Grid Services | ||
1376 | response = WebUtil.PostToService(m_groupsServerURI, requestArgs); | ||
1377 | |||
1378 | // and cache the response | ||
1379 | m_memoryCache.AddOrUpdate(CacheKey, response, TimeSpan.FromSeconds(m_cacheTimeout)); | ||
1380 | } | ||
1381 | |||
1382 | // return cached response | ||
1383 | return response; | ||
1384 | } | ||
1385 | #endregion | ||
1386 | |||
1326 | } | 1387 | } |
1327 | 1388 | ||
1328 | } | 1389 | } |