aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs
diff options
context:
space:
mode:
authorMW2009-02-24 16:13:16 +0000
committerMW2009-02-24 16:13:16 +0000
commit98178b4e9f5637eed9ab5ebb7c44f2eb71c30093 (patch)
tree7602f67161fcf14990a840b57c672e2f24d9d0ae /OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs
parentAdded OpenSim.Grid.GridServer.Modules, for the GridServer modules/components. (diff)
downloadopensim-SC_OLD-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.zip
opensim-SC_OLD-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.tar.gz
opensim-SC_OLD-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.tar.bz2
opensim-SC_OLD-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.tar.xz
Same treatment for the MessagingServer... added OpenSim.Grid.MessagingServer.Modules for the modules/components of it.
Diffstat (limited to 'OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs')
-rw-r--r--OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs213
1 files changed, 213 insertions, 0 deletions
diff --git a/OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs b/OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs
new file mode 100644
index 0000000..f77ef4b
--- /dev/null
+++ b/OpenSim/Grid/MessagingServer.Modules/MessageRegionModule.cs
@@ -0,0 +1,213 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using System.Threading;
34using System.Timers;
35using log4net;
36using Nwc.XmlRpc;
37using OpenMetaverse;
38using OpenSim.Data;
39using OpenSim.Framework;
40using OpenSim.Grid.Framework;
41using Timer = System.Timers.Timer;
42
43namespace OpenSim.Grid.MessagingServer.Modules
44{
45 public class MessageRegionModule : IMessageRegionService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private MessageServerConfig m_cfg;
50
51 private IMessageUserServerService m_userServerModule;
52
53 private IUGAIMCore m_messageCore;
54
55 // a dictionary of all current regions this server knows about
56 private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong, RegionProfileData>();
57
58 public MessageRegionModule(MessageServerConfig config, IUGAIMCore messageCore)
59 {
60 m_cfg = config;
61 m_messageCore = messageCore;
62 }
63
64 public void Initialise()
65 {
66 m_messageCore.RegisterInterface<IMessageRegionService>(this);
67 }
68
69 public void PostInitialise()
70 {
71 IMessageUserServerService messageUserServer;
72 if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer))
73 {
74 m_userServerModule = messageUserServer;
75 }
76 }
77
78 public void RegisterHandlers()
79 {
80 //have these in separate method as some servers restart the http server and reregister all the handlers.
81
82 }
83
84 /// <summary>
85 /// Gets and caches a RegionInfo object from the gridserver based on regionhandle
86 /// if the regionhandle is already cached, use the cached values
87 /// Gets called by lots of threads!!!!!
88 /// </summary>
89 /// <param name="regionhandle">handle to the XY of the region we're looking for</param>
90 /// <returns>A RegionInfo object to stick in the presence info</returns>
91 public RegionProfileData GetRegionInfo(ulong regionhandle)
92 {
93 RegionProfileData regionInfo = null;
94
95 lock (m_regionInfoCache)
96 {
97 m_regionInfoCache.TryGetValue(regionhandle, out regionInfo);
98 }
99
100 if (regionInfo == null) // not found in cache
101 {
102 regionInfo = RequestRegionInfo(regionhandle);
103
104 if (regionInfo != null) // lookup was successful
105 {
106 lock (m_regionInfoCache)
107 {
108 m_regionInfoCache[regionhandle] = regionInfo;
109 }
110 }
111 }
112
113 return regionInfo;
114 }
115
116 public int ClearRegionCache()
117 {
118 int cachecount = 0;
119
120 lock (m_regionInfoCache)
121 {
122 cachecount = m_regionInfoCache.Count;
123 m_regionInfoCache.Clear();
124 }
125
126 return cachecount;
127 }
128
129 /// <summary>
130 /// Get RegionProfileData from the GridServer.
131 /// We'll cache this information in GetRegionInfo and use it for presence updates
132 /// </summary>
133 /// <param name="regionHandle"></param>
134 /// <returns></returns>
135 public RegionProfileData RequestRegionInfo(ulong regionHandle)
136 {
137 RegionProfileData regionProfile = null;
138 try
139 {
140 Hashtable requestData = new Hashtable();
141 requestData["region_handle"] = regionHandle.ToString();
142 requestData["authkey"] = m_cfg.GridSendKey;
143
144 ArrayList SendParams = new ArrayList();
145 SendParams.Add(requestData);
146
147 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
148
149 XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000);
150
151 Hashtable responseData = (Hashtable)GridResp.Value;
152
153 if (responseData.ContainsKey("error"))
154 {
155 m_log.Error("[GRID]: error received from grid server" + responseData["error"]);
156 return null;
157 }
158
159 uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
160 uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
161 string internalIpStr = (string)responseData["sim_ip"];
162
163 regionProfile = new RegionProfileData();
164 regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]);
165 regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/";
166 regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize));
167 regionProfile.regionLocX = regX;
168 regionProfile.regionLocY = regY;
169
170 regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
171 regionProfile.UUID = new UUID((string)responseData["region_UUID"]);
172 regionProfile.regionName = (string)responseData["region_name"];
173 }
174 catch (WebException)
175 {
176 m_log.Error("[GRID]: " +
177 "Region lookup failed for: " + regionHandle.ToString() +
178 " - Is the GridServer down?");
179 }
180
181 return regionProfile;
182 }
183
184 public XmlRpcResponse RegionStartup(XmlRpcRequest request)
185 {
186 Hashtable requestData = (Hashtable)request.Params[0];
187 Hashtable result = new Hashtable();
188 result["success"] = "FALSE";
189
190 if (m_userServerModule.SendToUserServer(requestData, "region_startup"))
191 result["success"] = "TRUE";
192
193 XmlRpcResponse response = new XmlRpcResponse();
194 response.Value = result;
195 return response;
196 }
197
198 public XmlRpcResponse RegionShutdown(XmlRpcRequest request)
199 {
200 Hashtable requestData = (Hashtable)request.Params[0];
201 Hashtable result = new Hashtable();
202 result["success"] = "FALSE";
203
204 if (m_userServerModule.SendToUserServer(requestData, "region_shutdown"))
205 result["success"] = "TRUE";
206
207 XmlRpcResponse response = new XmlRpcResponse();
208 response.Value = result;
209 return response;
210 }
211
212 }
213}