diff options
First step in giving the messaging server the modular refactoring treatment. As with the other two servers, this is very much a work in progress.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageRegionModule.cs | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/OpenSim/Grid/MessagingServer/MessageRegionModule.cs b/OpenSim/Grid/MessagingServer/MessageRegionModule.cs new file mode 100644 index 0000000..b3fd7ae --- /dev/null +++ b/OpenSim/Grid/MessagingServer/MessageRegionModule.cs | |||
@@ -0,0 +1,212 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Threading; | ||
34 | using System.Timers; | ||
35 | using log4net; | ||
36 | using Nwc.XmlRpc; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Data; | ||
39 | using OpenSim.Framework; | ||
40 | using Timer = System.Timers.Timer; | ||
41 | |||
42 | namespace OpenSim.Grid.MessagingServer | ||
43 | { | ||
44 | public class MessageRegionModule : IMessageRegionService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private MessageServerConfig m_cfg; | ||
49 | |||
50 | private IMessageUserServerService m_userServerModule; | ||
51 | |||
52 | private IUGAIMCore m_messageCore; | ||
53 | |||
54 | // a dictionary of all current regions this server knows about | ||
55 | private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong, RegionProfileData>(); | ||
56 | |||
57 | public MessageRegionModule(MessageServerConfig config, IUGAIMCore messageCore) | ||
58 | { | ||
59 | m_cfg = config; | ||
60 | m_messageCore = messageCore; | ||
61 | } | ||
62 | |||
63 | public void Initialise() | ||
64 | { | ||
65 | m_messageCore.RegisterInterface<IMessageRegionService>(this); | ||
66 | } | ||
67 | |||
68 | public void PostInitialise() | ||
69 | { | ||
70 | IMessageUserServerService messageUserServer; | ||
71 | if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer)) | ||
72 | { | ||
73 | m_userServerModule = messageUserServer; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public void RegisterHandlers() | ||
78 | { | ||
79 | //have these in separate method as some servers restart the http server and reregister all the handlers. | ||
80 | |||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Gets and caches a RegionInfo object from the gridserver based on regionhandle | ||
85 | /// if the regionhandle is already cached, use the cached values | ||
86 | /// Gets called by lots of threads!!!!! | ||
87 | /// </summary> | ||
88 | /// <param name="regionhandle">handle to the XY of the region we're looking for</param> | ||
89 | /// <returns>A RegionInfo object to stick in the presence info</returns> | ||
90 | public RegionProfileData GetRegionInfo(ulong regionhandle) | ||
91 | { | ||
92 | RegionProfileData regionInfo = null; | ||
93 | |||
94 | lock (m_regionInfoCache) | ||
95 | { | ||
96 | m_regionInfoCache.TryGetValue(regionhandle, out regionInfo); | ||
97 | } | ||
98 | |||
99 | if (regionInfo == null) // not found in cache | ||
100 | { | ||
101 | regionInfo = RequestRegionInfo(regionhandle); | ||
102 | |||
103 | if (regionInfo != null) // lookup was successful | ||
104 | { | ||
105 | lock (m_regionInfoCache) | ||
106 | { | ||
107 | m_regionInfoCache[regionhandle] = regionInfo; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | return regionInfo; | ||
113 | } | ||
114 | |||
115 | public int ClearRegionCache() | ||
116 | { | ||
117 | int cachecount = 0; | ||
118 | |||
119 | lock (m_regionInfoCache) | ||
120 | { | ||
121 | cachecount = m_regionInfoCache.Count; | ||
122 | m_regionInfoCache.Clear(); | ||
123 | } | ||
124 | |||
125 | return cachecount; | ||
126 | } | ||
127 | |||
128 | /// <summary> | ||
129 | /// Get RegionProfileData from the GridServer. | ||
130 | /// We'll cache this information in GetRegionInfo and use it for presence updates | ||
131 | /// </summary> | ||
132 | /// <param name="regionHandle"></param> | ||
133 | /// <returns></returns> | ||
134 | public RegionProfileData RequestRegionInfo(ulong regionHandle) | ||
135 | { | ||
136 | RegionProfileData regionProfile = null; | ||
137 | try | ||
138 | { | ||
139 | Hashtable requestData = new Hashtable(); | ||
140 | requestData["region_handle"] = regionHandle.ToString(); | ||
141 | requestData["authkey"] = m_cfg.GridSendKey; | ||
142 | |||
143 | ArrayList SendParams = new ArrayList(); | ||
144 | SendParams.Add(requestData); | ||
145 | |||
146 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); | ||
147 | |||
148 | XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000); | ||
149 | |||
150 | Hashtable responseData = (Hashtable)GridResp.Value; | ||
151 | |||
152 | if (responseData.ContainsKey("error")) | ||
153 | { | ||
154 | m_log.Error("[GRID]: error received from grid server" + responseData["error"]); | ||
155 | return null; | ||
156 | } | ||
157 | |||
158 | uint regX = Convert.ToUInt32((string)responseData["region_locx"]); | ||
159 | uint regY = Convert.ToUInt32((string)responseData["region_locy"]); | ||
160 | string internalIpStr = (string)responseData["sim_ip"]; | ||
161 | |||
162 | regionProfile = new RegionProfileData(); | ||
163 | regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]); | ||
164 | regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/"; | ||
165 | regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize)); | ||
166 | regionProfile.regionLocX = regX; | ||
167 | regionProfile.regionLocY = regY; | ||
168 | |||
169 | regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); | ||
170 | regionProfile.UUID = new UUID((string)responseData["region_UUID"]); | ||
171 | regionProfile.regionName = (string)responseData["region_name"]; | ||
172 | } | ||
173 | catch (WebException) | ||
174 | { | ||
175 | m_log.Error("[GRID]: " + | ||
176 | "Region lookup failed for: " + regionHandle.ToString() + | ||
177 | " - Is the GridServer down?"); | ||
178 | } | ||
179 | |||
180 | return regionProfile; | ||
181 | } | ||
182 | |||
183 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) | ||
184 | { | ||
185 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
186 | Hashtable result = new Hashtable(); | ||
187 | result["success"] = "FALSE"; | ||
188 | |||
189 | if (m_userServerModule.SendToUserServer(requestData, "region_startup")) | ||
190 | result["success"] = "TRUE"; | ||
191 | |||
192 | XmlRpcResponse response = new XmlRpcResponse(); | ||
193 | response.Value = result; | ||
194 | return response; | ||
195 | } | ||
196 | |||
197 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) | ||
198 | { | ||
199 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
200 | Hashtable result = new Hashtable(); | ||
201 | result["success"] = "FALSE"; | ||
202 | |||
203 | if (m_userServerModule.SendToUserServer(requestData, "region_shutdown")) | ||
204 | result["success"] = "TRUE"; | ||
205 | |||
206 | XmlRpcResponse response = new XmlRpcResponse(); | ||
207 | response.Value = result; | ||
208 | return response; | ||
209 | } | ||
210 | |||
211 | } | ||
212 | } | ||