diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | 141 |
1 files changed, 99 insertions, 42 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs index 2a60b00..79b9a16 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 | ||
@@ -40,7 +41,9 @@ using OpenMetaverse; | |||
40 | using OpenMetaverse.StructuredData; | 41 | using OpenMetaverse.StructuredData; |
41 | 42 | ||
42 | using OpenSim.Framework; | 43 | using OpenSim.Framework; |
44 | using OpenSim.Framework.Communications; | ||
43 | using OpenSim.Region.Framework.Interfaces; | 45 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Services.Interfaces; | ||
44 | 47 | ||
45 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | 48 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups |
46 | { | 49 | { |
@@ -66,6 +69,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
66 | private string m_groupReadKey = string.Empty; | 69 | private string m_groupReadKey = string.Empty; |
67 | private string m_groupWriteKey = string.Empty; | 70 | private string m_groupWriteKey = string.Empty; |
68 | 71 | ||
72 | private IUserAccountService m_accountService = null; | ||
73 | |||
74 | private ExpiringCache<string, XmlRpcResponse> m_memoryCache; | ||
75 | private int m_cacheTimeout = 30; | ||
69 | 76 | ||
70 | // 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 |
71 | // Should be reset per agent, on logon | 78 | // Should be reset per agent, on logon |
@@ -108,7 +115,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
108 | return; | 115 | return; |
109 | } | 116 | } |
110 | 117 | ||
111 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Initializing {0}", this.Name); | 118 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name); |
112 | 119 | ||
113 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); | 120 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); |
114 | if ((m_groupsServerURI == null) || | 121 | if ((m_groupsServerURI == null) || |
@@ -124,23 +131,39 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
124 | m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); | 131 | m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); |
125 | m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); | 132 | m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); |
126 | 133 | ||
127 | |||
128 | 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 | } | ||
129 | 144 | ||
130 | // If we got all the config options we need, lets start'er'up | 145 | // If we got all the config options we need, lets start'er'up |
146 | m_memoryCache = new ExpiringCache<string, XmlRpcResponse>(); | ||
131 | m_connectorEnabled = true; | 147 | m_connectorEnabled = true; |
132 | } | 148 | } |
133 | } | 149 | } |
134 | 150 | ||
135 | public void Close() | 151 | public void Close() |
136 | { | 152 | { |
137 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Closing {0}", this.Name); | 153 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Closing {0}", this.Name); |
138 | } | 154 | } |
139 | 155 | ||
140 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) | 156 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) |
141 | { | 157 | { |
142 | if (m_connectorEnabled) | 158 | if (m_connectorEnabled) |
143 | { | 159 | { |
160 | |||
161 | if (m_accountService == null) | ||
162 | { | ||
163 | m_accountService = scene.UserAccountService; | ||
164 | } | ||
165 | |||
166 | |||
144 | scene.RegisterModuleInterface<IGroupsServicesConnector>(this); | 167 | scene.RegisterModuleInterface<IGroupsServicesConnector>(this); |
145 | } | 168 | } |
146 | } | 169 | } |
@@ -909,50 +932,84 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
909 | /// </summary> | 932 | /// </summary> |
910 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) | 933 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) |
911 | { | 934 | { |
912 | string UserService; | 935 | XmlRpcResponse resp = null; |
913 | UUID SessionID; | 936 | string CacheKey = null; |
914 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | 937 | |
915 | param.Add("requestingAgentID", requestingAgentID.ToString()); | 938 | // Only bother with the cache if it isn't disabled. |
916 | param.Add("RequestingAgentUserService", UserService); | 939 | if (m_cacheTimeout > 0) |
917 | param.Add("RequestingSessionID", SessionID.ToString()); | 940 | { |
918 | 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 | } | ||
919 | 960 | ||
920 | param.Add("ReadKey", m_groupReadKey); | 961 | } |
921 | 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()); | ||
922 | 971 | ||
923 | 972 | ||
924 | IList parameters = new ArrayList(); | 973 | param.Add("ReadKey", m_groupReadKey); |
925 | parameters.Add(param); | 974 | param.Add("WriteKey", m_groupWriteKey); |
926 | 975 | ||
927 | ConfigurableKeepAliveXmlRpcRequest req; | ||
928 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); | ||
929 | 976 | ||
930 | XmlRpcResponse resp = null; | 977 | IList parameters = new ArrayList(); |
978 | parameters.Add(param); | ||
931 | 979 | ||
932 | try | 980 | ConfigurableKeepAliveXmlRpcRequest req; |
933 | { | 981 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); |
934 | resp = req.Send(m_groupsServerURI, 10000); | ||
935 | } | ||
936 | catch (Exception e) | ||
937 | { | ||
938 | |||
939 | 982 | ||
940 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); | ||
941 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString()); | ||
942 | 983 | ||
943 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine },StringSplitOptions.None)) | 984 | try |
944 | { | 985 | { |
945 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", ResponseLine); | 986 | resp = req.Send(m_groupsServerURI, 10000); |
946 | } | ||
947 | 987 | ||
948 | foreach (string key in param.Keys) | 988 | if ((m_cacheTimeout > 0) && (CacheKey != null)) |
989 | { | ||
990 | m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout)); | ||
991 | } | ||
992 | |||
993 | } | ||
994 | catch (Exception e) | ||
949 | { | 995 | { |
950 | 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; | ||
951 | } | 1012 | } |
952 | |||
953 | Hashtable respData = new Hashtable(); | ||
954 | respData.Add("error", e.ToString()); | ||
955 | return respData; | ||
956 | } | 1013 | } |
957 | 1014 | ||
958 | if (resp.Value is Hashtable) | 1015 | if (resp.Value is Hashtable) |
@@ -966,21 +1023,21 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
966 | return respData; | 1023 | return respData; |
967 | } | 1024 | } |
968 | 1025 | ||
969 | 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()); |
970 | 1027 | ||
971 | if (resp.Value is ArrayList) | 1028 | if (resp.Value is ArrayList) |
972 | { | 1029 | { |
973 | ArrayList al = (ArrayList)resp.Value; | 1030 | ArrayList al = (ArrayList)resp.Value; |
974 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Contains {0} elements", al.Count); | 1031 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count); |
975 | 1032 | ||
976 | foreach (object o in al) | 1033 | foreach (object o in al) |
977 | { | 1034 | { |
978 | 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()); |
979 | } | 1036 | } |
980 | } | 1037 | } |
981 | else | 1038 | else |
982 | { | 1039 | { |
983 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Function returned: {0}", resp.Value.ToString()); | 1040 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString()); |
984 | } | 1041 | } |
985 | 1042 | ||
986 | Hashtable error = new Hashtable(); | 1043 | Hashtable error = new Hashtable(); |
@@ -990,16 +1047,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
990 | 1047 | ||
991 | private void LogRespDataToConsoleError(Hashtable respData) | 1048 | private void LogRespDataToConsoleError(Hashtable respData) |
992 | { | 1049 | { |
993 | m_log.Error("[XMLRPCGROUPDATA]: Error:"); | 1050 | m_log.Error("[XMLRPC-GROUPS-CONNECTOR]: Error:"); |
994 | 1051 | ||
995 | foreach (string key in respData.Keys) | 1052 | foreach (string key in respData.Keys) |
996 | { | 1053 | { |
997 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Key: {0}", key); | 1054 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Key: {0}", key); |
998 | 1055 | ||
999 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); | 1056 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); |
1000 | foreach (string line in lines) | 1057 | foreach (string line in lines) |
1001 | { | 1058 | { |
1002 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0}", line); | 1059 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}", line); |
1003 | } | 1060 | } |
1004 | 1061 | ||
1005 | } | 1062 | } |