diff options
author | Justin Clark-Casey (justincc) | 2010-06-08 20:31:39 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-06-08 20:31:39 +0100 |
commit | 8b3b89ecf40ebe4e78ca77ccc5e14b2632829119 (patch) | |
tree | dac98391c08771590c1ac81baed405f26cc15f7f /OpenSim/Region/OptionalModules/Avatar | |
parent | remove references to OpenSim.Framework.Commuications.Tests.dll since all rele... (diff) | |
download | opensim-SC-8b3b89ecf40ebe4e78ca77ccc5e14b2632829119.zip opensim-SC-8b3b89ecf40ebe4e78ca77ccc5e14b2632829119.tar.gz opensim-SC-8b3b89ecf40ebe4e78ca77ccc5e14b2632829119.tar.bz2 opensim-SC-8b3b89ecf40ebe4e78ca77ccc5e14b2632829119.tar.xz |
backport xmlrpcgroups cache from master
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | 135 |
1 files changed, 91 insertions, 44 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs index 861731c..e64c9a7 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Text; | ||
32 | 33 | ||
33 | using Nwc.XmlRpc; | 34 | using Nwc.XmlRpc; |
34 | 35 | ||
@@ -42,6 +43,7 @@ using OpenMetaverse.StructuredData; | |||
42 | using OpenSim.Framework; | 43 | using OpenSim.Framework; |
43 | using OpenSim.Framework.Communications; | 44 | using OpenSim.Framework.Communications; |
44 | using OpenSim.Region.Framework.Interfaces; | 45 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Services.Interfaces; | ||
45 | 47 | ||
46 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | 48 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups |
47 | { | 49 | { |
@@ -72,7 +74,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
72 | 74 | ||
73 | private bool m_debugEnabled = false; | 75 | private bool m_debugEnabled = false; |
74 | 76 | ||
75 | 77 | private ExpiringCache<string, XmlRpcResponse> m_memoryCache; | |
78 | private int m_cacheTimeout = 30; | ||
79 | |||
76 | // Used to track which agents are have dropped from a group chat session | 80 | // Used to track which agents are have dropped from a group chat session |
77 | // Should be reset per agent, on logon | 81 | // Should be reset per agent, on logon |
78 | // TODO: move this to Flotsam XmlRpc Service | 82 | // TODO: move this to Flotsam XmlRpc Service |
@@ -132,8 +136,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
132 | 136 | ||
133 | m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true); | 137 | m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true); |
134 | 138 | ||
135 | 139 | m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30); | |
140 | if (m_cacheTimeout == 0) | ||
141 | { | ||
142 | m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled."); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout); | ||
147 | } | ||
148 | |||
136 | // If we got all the config options we need, lets start'er'up | 149 | // If we got all the config options we need, lets start'er'up |
150 | m_memoryCache = new ExpiringCache<string, XmlRpcResponse>(); | ||
137 | m_connectorEnabled = true; | 151 | m_connectorEnabled = true; |
138 | } | 152 | } |
139 | } | 153 | } |
@@ -921,61 +935,94 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
921 | /// </summary> | 935 | /// </summary> |
922 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) | 936 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) |
923 | { | 937 | { |
924 | string UserService; | 938 | XmlRpcResponse resp = null; |
925 | UUID SessionID; | 939 | string CacheKey = null; |
926 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | ||
927 | param.Add("RequestingAgentID", requestingAgentID.ToString()); | ||
928 | param.Add("RequestingAgentUserService", UserService); | ||
929 | param.Add("RequestingSessionID", SessionID.ToString()); | ||
930 | |||
931 | |||
932 | param.Add("ReadKey", m_groupReadKey); | ||
933 | param.Add("WriteKey", m_groupWriteKey); | ||
934 | 940 | ||
935 | if (m_debugEnabled) | 941 | // Only bother with the cache if it isn't disabled. |
942 | if (m_cacheTimeout > 0) | ||
936 | { | 943 | { |
937 | m_log.Debug("[XMLRPCGROUPDATA] XmlRpcCall Params:"); | 944 | if (!function.StartsWith("groups.get")) |
938 | foreach (string key in param.Keys) | ||
939 | { | 945 | { |
940 | m_log.DebugFormat("[XMLRPCGROUPDATA] {0} : {1}", key, param[key]); | 946 | // Any and all updates cause the cache to clear |
947 | m_memoryCache.Clear(); | ||
941 | } | 948 | } |
942 | } | 949 | else |
943 | 950 | { | |
944 | IList parameters = new ArrayList(); | 951 | StringBuilder sb = new StringBuilder(requestingAgentID + function); |
945 | parameters.Add(param); | 952 | foreach (object key in param.Keys) |
946 | 953 | { | |
947 | ConfigurableKeepAliveXmlRpcRequest req; | 954 | if (param[key] != null) |
948 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); | 955 | { |
949 | 956 | sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString()); | |
950 | XmlRpcResponse resp = null; | 957 | } |
958 | } | ||
951 | 959 | ||
952 | try | 960 | CacheKey = sb.ToString(); |
953 | { | 961 | m_memoryCache.TryGetValue(CacheKey, out resp); |
954 | resp = req.Send(m_groupsServerURI, 10000); | 962 | } |
955 | } | 963 | } |
956 | catch (Exception e) | 964 | |
965 | if (resp == null) | ||
957 | { | 966 | { |
967 | string UserService; | ||
968 | UUID SessionID; | ||
969 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | ||
970 | param.Add("RequestingAgentID", requestingAgentID.ToString()); | ||
971 | param.Add("RequestingAgentUserService", UserService); | ||
972 | param.Add("RequestingSessionID", SessionID.ToString()); | ||
958 | 973 | ||
959 | 974 | ||
960 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); | 975 | param.Add("ReadKey", m_groupReadKey); |
961 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString()); | 976 | param.Add("WriteKey", m_groupWriteKey); |
962 | 977 | ||
963 | if ((req != null) && (req.RequestResponse != null)) | 978 | if (m_debugEnabled) |
964 | { | ||
965 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) | ||
966 | { | 979 | { |
967 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", ResponseLine); | 980 | m_log.Debug("[XMLRPCGROUPDATA] XmlRpcCall Params:"); |
981 | foreach (string key in param.Keys) | ||
982 | { | ||
983 | m_log.DebugFormat("[XMLRPCGROUPDATA] {0} : {1}", key, param[key]); | ||
984 | } | ||
968 | } | 985 | } |
986 | |||
987 | IList parameters = new ArrayList(); | ||
988 | parameters.Add(param); | ||
989 | |||
990 | ConfigurableKeepAliveXmlRpcRequest req; | ||
991 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); | ||
992 | |||
993 | try | ||
994 | { | ||
995 | resp = req.Send(m_groupsServerURI, 10000); | ||
996 | |||
997 | if ((m_cacheTimeout > 0) && (CacheKey != null)) | ||
998 | { | ||
999 | m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout)); | ||
1000 | } | ||
969 | } | 1001 | } |
970 | 1002 | catch (Exception e) | |
971 | foreach (string key in param.Keys) | ||
972 | { | 1003 | { |
973 | m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", key, param[key].ToString()); | 1004 | |
1005 | |||
1006 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); | ||
1007 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString()); | ||
1008 | |||
1009 | if ((req != null) && (req.RequestResponse != null)) | ||
1010 | { | ||
1011 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) | ||
1012 | { | ||
1013 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", ResponseLine); | ||
1014 | } | ||
1015 | } | ||
1016 | |||
1017 | foreach (string key in param.Keys) | ||
1018 | { | ||
1019 | m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", key, param[key].ToString()); | ||
1020 | } | ||
1021 | |||
1022 | Hashtable respData = new Hashtable(); | ||
1023 | respData.Add("error", e.ToString()); | ||
1024 | return respData; | ||
974 | } | 1025 | } |
975 | |||
976 | Hashtable respData = new Hashtable(); | ||
977 | respData.Add("error", e.ToString()); | ||
978 | return respData; | ||
979 | } | 1026 | } |
980 | 1027 | ||
981 | 1028 | ||