diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | 131 |
1 files changed, 89 insertions, 42 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs index 523dfbe..e7967d1 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 | ||
@@ -70,6 +71,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
70 | 71 | ||
71 | private IUserAccountService m_accountService = null; | 72 | private IUserAccountService m_accountService = null; |
72 | 73 | ||
74 | private ExpiringCache<string, XmlRpcResponse> m_memoryCache; | ||
75 | private int m_cacheTimeout = 30; | ||
76 | |||
73 | // Used to track which agents are have dropped from a group chat session | 77 | // Used to track which agents are have dropped from a group chat session |
74 | // Should be reset per agent, on logon | 78 | // Should be reset per agent, on logon |
75 | // TODO: move this to Flotsam XmlRpc Service | 79 | // TODO: move this to Flotsam XmlRpc Service |
@@ -111,7 +115,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
111 | return; | 115 | return; |
112 | } | 116 | } |
113 | 117 | ||
114 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Initializing {0}", this.Name); | 118 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name); |
115 | 119 | ||
116 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); | 120 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); |
117 | if ((m_groupsServerURI == null) || | 121 | if ((m_groupsServerURI == null) || |
@@ -127,7 +131,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
127 | m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); | 131 | m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); |
128 | m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); | 132 | m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); |
129 | 133 | ||
130 | 134 | ||
135 | m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30); | ||
136 | if (m_cacheTimeout == 0) | ||
137 | { | ||
138 | m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled."); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout); | ||
143 | } | ||
131 | 144 | ||
132 | 145 | ||
133 | // If we got all the config options we need, lets start'er'up | 146 | // If we got all the config options we need, lets start'er'up |
@@ -137,7 +150,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
137 | 150 | ||
138 | public void Close() | 151 | public void Close() |
139 | { | 152 | { |
140 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Closing {0}", this.Name); | 153 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Closing {0}", this.Name); |
141 | } | 154 | } |
142 | 155 | ||
143 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) | 156 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) |
@@ -919,50 +932,84 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
919 | /// </summary> | 932 | /// </summary> |
920 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) | 933 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) |
921 | { | 934 | { |
922 | string UserService; | 935 | XmlRpcResponse resp = null; |
923 | UUID SessionID; | 936 | string CacheKey = null; |
924 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | 937 | |
925 | param.Add("requestingAgentID", requestingAgentID.ToString()); | 938 | // Only bother with the cache if it isn't disabled. |
926 | param.Add("RequestingAgentUserService", UserService); | 939 | if (m_cacheTimeout > 0) |
927 | param.Add("RequestingSessionID", SessionID.ToString()); | 940 | { |
928 | 941 | if (!function.StartsWith("groups.get")) | |
942 | { | ||
943 | // Any and all updates cause the cache to clear | ||
944 | m_memoryCache.Clear(); | ||
945 | } | ||
946 | else | ||
947 | { | ||
948 | StringBuilder sb = new StringBuilder(requestingAgentID + function); | ||
949 | foreach (object key in param.Keys) | ||
950 | { | ||
951 | if (param[key] != null) | ||
952 | { | ||
953 | sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString()); | ||
954 | } | ||
955 | } | ||
956 | |||
957 | CacheKey = sb.ToString(); | ||
958 | m_memoryCache.TryGetValue(CacheKey, out resp); | ||
959 | } | ||
929 | 960 | ||
930 | param.Add("ReadKey", m_groupReadKey); | 961 | } |
931 | param.Add("WriteKey", m_groupWriteKey); | 962 | |
963 | if( resp == null ) | ||
964 | { | ||
965 | string UserService; | ||
966 | UUID SessionID; | ||
967 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | ||
968 | param.Add("requestingAgentID", requestingAgentID.ToString()); | ||
969 | param.Add("RequestingAgentUserService", UserService); | ||
970 | param.Add("RequestingSessionID", SessionID.ToString()); | ||
932 | 971 | ||
933 | 972 | ||
934 | IList parameters = new ArrayList(); | 973 | param.Add("ReadKey", m_groupReadKey); |
935 | parameters.Add(param); | 974 | param.Add("WriteKey", m_groupWriteKey); |
936 | 975 | ||
937 | ConfigurableKeepAliveXmlRpcRequest req; | ||
938 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); | ||
939 | 976 | ||
940 | XmlRpcResponse resp = null; | 977 | IList parameters = new ArrayList(); |
978 | parameters.Add(param); | ||
941 | 979 | ||
942 | try | 980 | ConfigurableKeepAliveXmlRpcRequest req; |
943 | { | 981 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); |
944 | resp = req.Send(m_groupsServerURI, 10000); | ||
945 | } | ||
946 | catch (Exception e) | ||
947 | { | ||
948 | |||
949 | 982 | ||
950 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); | ||
951 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString()); | ||
952 | 983 | ||
953 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine },StringSplitOptions.None)) | 984 | try |
954 | { | 985 | { |
955 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", ResponseLine); | 986 | resp = req.Send(m_groupsServerURI, 10000); |
956 | } | 987 | |
988 | if ((m_cacheTimeout > 0) && (CacheKey != null)) | ||
989 | { | ||
990 | m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout)); | ||
991 | } | ||
957 | 992 | ||
958 | foreach (string key in param.Keys) | 993 | } |
994 | catch (Exception e) | ||
959 | { | 995 | { |
960 | m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", key, param[key].ToString()); | 996 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); |
997 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", e.ToString()); | ||
998 | |||
999 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) | ||
1000 | { | ||
1001 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine); | ||
1002 | } | ||
1003 | |||
1004 | foreach (string key in param.Keys) | ||
1005 | { | ||
1006 | m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString()); | ||
1007 | } | ||
1008 | |||
1009 | Hashtable respData = new Hashtable(); | ||
1010 | respData.Add("error", e.ToString()); | ||
1011 | return respData; | ||
961 | } | 1012 | } |
962 | |||
963 | Hashtable respData = new Hashtable(); | ||
964 | respData.Add("error", e.ToString()); | ||
965 | return respData; | ||
966 | } | 1013 | } |
967 | 1014 | ||
968 | if (resp.Value is Hashtable) | 1015 | if (resp.Value is Hashtable) |
@@ -976,21 +1023,21 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
976 | return respData; | 1023 | return respData; |
977 | } | 1024 | } |
978 | 1025 | ||
979 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString()); | 1026 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString()); |
980 | 1027 | ||
981 | if (resp.Value is ArrayList) | 1028 | if (resp.Value is ArrayList) |
982 | { | 1029 | { |
983 | ArrayList al = (ArrayList)resp.Value; | 1030 | ArrayList al = (ArrayList)resp.Value; |
984 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Contains {0} elements", al.Count); | 1031 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count); |
985 | 1032 | ||
986 | foreach (object o in al) | 1033 | foreach (object o in al) |
987 | { | 1034 | { |
988 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} :: {1}", o.GetType().ToString(), o.ToString()); | 1035 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString()); |
989 | } | 1036 | } |
990 | } | 1037 | } |
991 | else | 1038 | else |
992 | { | 1039 | { |
993 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Function returned: {0}", resp.Value.ToString()); | 1040 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString()); |
994 | } | 1041 | } |
995 | 1042 | ||
996 | Hashtable error = new Hashtable(); | 1043 | Hashtable error = new Hashtable(); |
@@ -1000,16 +1047,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1000 | 1047 | ||
1001 | private void LogRespDataToConsoleError(Hashtable respData) | 1048 | private void LogRespDataToConsoleError(Hashtable respData) |
1002 | { | 1049 | { |
1003 | m_log.Error("[XMLRPCGROUPDATA]: Error:"); | 1050 | m_log.Error("[XMLRPC-GROUPS-CONNECTOR]: Error:"); |
1004 | 1051 | ||
1005 | foreach (string key in respData.Keys) | 1052 | foreach (string key in respData.Keys) |
1006 | { | 1053 | { |
1007 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Key: {0}", key); | 1054 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Key: {0}", key); |
1008 | 1055 | ||
1009 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); | 1056 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); |
1010 | foreach (string line in lines) | 1057 | foreach (string line in lines) |
1011 | { | 1058 | { |
1012 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0}", line); | 1059 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}", line); |
1013 | } | 1060 | } |
1014 | 1061 | ||
1015 | } | 1062 | } |