clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 OpenSimulator 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 log4net; |
||
29 | using Mono.Addins; |
||
30 | using System; |
||
31 | using System.Collections; |
||
32 | using System.Collections.Generic; |
||
33 | using System.Reflection; |
||
34 | using Nini.Config; |
||
35 | using OpenMetaverse; |
||
36 | |||
37 | using OpenSim.Framework; |
||
38 | using OpenSim.Services.Connectors; |
||
39 | using OpenSim.Region.Framework.Interfaces; |
||
40 | using OpenSim.Region.Framework.Scenes; |
||
41 | using OpenSim.Server.Base; |
||
42 | using OpenSim.Services.Interfaces; |
||
43 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
44 | |||
45 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid |
||
46 | { |
||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteGridServicesConnector")] |
||
48 | public class RemoteGridServicesConnector : ISharedRegionModule, IGridService |
||
49 | { |
||
50 | private static readonly ILog m_log = |
||
51 | LogManager.GetLogger( |
||
52 | MethodBase.GetCurrentMethod().DeclaringType); |
||
53 | |||
54 | private bool m_Enabled = false; |
||
55 | |||
56 | private IGridService m_LocalGridService; |
||
57 | private IGridService m_RemoteGridService; |
||
58 | |||
59 | private RegionInfoCache m_RegionInfoCache = new RegionInfoCache(); |
||
60 | |||
61 | public RemoteGridServicesConnector() |
||
62 | { |
||
63 | } |
||
64 | |||
65 | public RemoteGridServicesConnector(IConfigSource source) |
||
66 | { |
||
67 | InitialiseServices(source); |
||
68 | } |
||
69 | |||
70 | #region ISharedRegionmodule |
||
71 | |||
72 | public Type ReplaceableInterface |
||
73 | { |
||
74 | get { return null; } |
||
75 | } |
||
76 | |||
77 | public string Name |
||
78 | { |
||
79 | get { return "RemoteGridServicesConnector"; } |
||
80 | } |
||
81 | |||
82 | public void Initialise(IConfigSource source) |
||
83 | { |
||
84 | IConfig moduleConfig = source.Configs["Modules"]; |
||
85 | if (moduleConfig != null) |
||
86 | { |
||
87 | string name = moduleConfig.GetString("GridServices", ""); |
||
88 | if (name == Name) |
||
89 | { |
||
90 | InitialiseServices(source); |
||
91 | m_Enabled = true; |
||
92 | m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | private void InitialiseServices(IConfigSource source) |
||
98 | { |
||
99 | IConfig gridConfig = source.Configs["GridService"]; |
||
100 | if (gridConfig == null) |
||
101 | { |
||
102 | m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini"); |
||
103 | return; |
||
104 | } |
||
105 | |||
106 | string networkConnector = gridConfig.GetString("NetworkConnector", string.Empty); |
||
107 | if (networkConnector == string.Empty) |
||
108 | { |
||
109 | m_log.Error("[REMOTE GRID CONNECTOR]: Please specify a network connector under [GridService]"); |
||
110 | return; |
||
111 | } |
||
112 | |||
113 | Object[] args = new Object[] { source }; |
||
114 | m_RemoteGridService = ServerUtils.LoadPlugin<IGridService>(networkConnector, args); |
||
115 | |||
116 | m_LocalGridService = new LocalGridServicesConnector(source); |
||
117 | } |
||
118 | |||
119 | public void PostInitialise() |
||
120 | { |
||
121 | if (m_LocalGridService != null) |
||
122 | ((ISharedRegionModule)m_LocalGridService).PostInitialise(); |
||
123 | } |
||
124 | |||
125 | public void Close() |
||
126 | { |
||
127 | } |
||
128 | |||
129 | public void AddRegion(Scene scene) |
||
130 | { |
||
131 | if (m_Enabled) |
||
132 | scene.RegisterModuleInterface<IGridService>(this); |
||
133 | |||
134 | if (m_LocalGridService != null) |
||
135 | ((ISharedRegionModule)m_LocalGridService).AddRegion(scene); |
||
136 | } |
||
137 | |||
138 | public void RemoveRegion(Scene scene) |
||
139 | { |
||
140 | if (m_LocalGridService != null) |
||
141 | ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene); |
||
142 | } |
||
143 | |||
144 | public void RegionLoaded(Scene scene) |
||
145 | { |
||
146 | } |
||
147 | |||
148 | #endregion |
||
149 | |||
150 | #region IGridService |
||
151 | |||
152 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) |
||
153 | { |
||
154 | string msg = m_LocalGridService.RegisterRegion(scopeID, regionInfo); |
||
155 | |||
156 | if (msg == String.Empty) |
||
157 | return m_RemoteGridService.RegisterRegion(scopeID, regionInfo); |
||
158 | |||
159 | return msg; |
||
160 | } |
||
161 | |||
162 | public bool DeregisterRegion(UUID regionID) |
||
163 | { |
||
164 | if (m_LocalGridService.DeregisterRegion(regionID)) |
||
165 | return m_RemoteGridService.DeregisterRegion(regionID); |
||
166 | |||
167 | return false; |
||
168 | } |
||
169 | |||
170 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) |
||
171 | { |
||
172 | return m_RemoteGridService.GetNeighbours(scopeID, regionID); |
||
173 | } |
||
174 | |||
175 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
||
176 | { |
||
177 | bool inCache = false; |
||
178 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionID,out inCache); |
||
179 | if (inCache) |
||
180 | return rinfo; |
||
181 | |||
182 | rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); |
||
183 | if (rinfo == null) |
||
184 | rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID); |
||
185 | |||
186 | m_RegionInfoCache.Cache(scopeID,regionID,rinfo); |
||
187 | return rinfo; |
||
188 | } |
||
189 | |||
190 | // Get a region given its base world coordinates (in meters). |
||
191 | // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST |
||
192 | // be the base coordinate of the region. |
||
193 | // The coordinates are world coords (meters), NOT region units. |
||
194 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) |
||
195 | { |
||
196 | bool inCache = false; |
||
197 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID, Util.RegionWorldLocToHandle((uint)x, (uint)y), out inCache); |
||
198 | if (inCache) |
||
199 | return rinfo; |
||
200 | |||
201 | rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); |
||
202 | if (rinfo == null) |
||
203 | rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); |
||
204 | |||
205 | m_RegionInfoCache.Cache(rinfo); |
||
206 | return rinfo; |
||
207 | } |
||
208 | |||
209 | public GridRegion GetRegionByName(UUID scopeID, string regionName) |
||
210 | { |
||
211 | bool inCache = false; |
||
212 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionName, out inCache); |
||
213 | if (inCache) |
||
214 | return rinfo; |
||
215 | |||
216 | rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); |
||
217 | if (rinfo == null) |
||
218 | rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName); |
||
219 | |||
220 | // can't cache negative results for name lookups |
||
221 | m_RegionInfoCache.Cache(rinfo); |
||
222 | return rinfo; |
||
223 | } |
||
224 | |||
225 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) |
||
226 | { |
||
227 | List<GridRegion> rinfo = m_LocalGridService.GetRegionsByName(scopeID, name, maxNumber); |
||
228 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionsByName {0} found {1} regions", name, rinfo.Count); |
||
229 | List<GridRegion> grinfo = m_RemoteGridService.GetRegionsByName(scopeID, name, maxNumber); |
||
230 | |||
231 | if (grinfo != null) |
||
232 | { |
||
233 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetRegionsByName {0} found {1} regions", name, grinfo.Count); |
||
234 | foreach (GridRegion r in grinfo) |
||
235 | { |
||
236 | m_RegionInfoCache.Cache(r); |
||
237 | if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) |
||
238 | rinfo.Add(r); |
||
239 | } |
||
240 | } |
||
241 | |||
242 | return rinfo; |
||
243 | } |
||
244 | |||
245 | public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) |
||
246 | { |
||
247 | List<GridRegion> rinfo = m_LocalGridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); |
||
248 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionRange {0} found {1} regions", name, rinfo.Count); |
||
249 | List<GridRegion> grinfo = m_RemoteGridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); |
||
250 | |||
251 | if (grinfo != null) |
||
252 | { |
||
253 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetRegionRange {0} found {1} regions", name, grinfo.Count); |
||
254 | foreach (GridRegion r in grinfo) |
||
255 | { |
||
256 | m_RegionInfoCache.Cache(r); |
||
257 | if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) |
||
258 | rinfo.Add(r); |
||
259 | } |
||
260 | } |
||
261 | |||
262 | return rinfo; |
||
263 | } |
||
264 | |||
265 | public List<GridRegion> GetDefaultRegions(UUID scopeID) |
||
266 | { |
||
267 | List<GridRegion> rinfo = m_LocalGridService.GetDefaultRegions(scopeID); |
||
268 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetDefaultRegions {0} found {1} regions", name, rinfo.Count); |
||
269 | List<GridRegion> grinfo = m_RemoteGridService.GetDefaultRegions(scopeID); |
||
270 | |||
271 | if (grinfo != null) |
||
272 | { |
||
273 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetDefaultRegions {0} found {1} regions", name, grinfo.Count); |
||
274 | foreach (GridRegion r in grinfo) |
||
275 | { |
||
276 | m_RegionInfoCache.Cache(r); |
||
277 | if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) |
||
278 | rinfo.Add(r); |
||
279 | } |
||
280 | } |
||
281 | |||
282 | return rinfo; |
||
283 | } |
||
284 | |||
285 | public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID) |
||
286 | { |
||
287 | List<GridRegion> rinfo = m_LocalGridService.GetDefaultHypergridRegions(scopeID); |
||
288 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetDefaultHypergridRegions {0} found {1} regions", name, rinfo.Count); |
||
289 | List<GridRegion> grinfo = m_RemoteGridService.GetDefaultHypergridRegions(scopeID); |
||
290 | |||
291 | if (grinfo != null) |
||
292 | { |
||
293 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetDefaultHypergridRegions {0} found {1} regions", name, grinfo.Count); |
||
294 | foreach (GridRegion r in grinfo) |
||
295 | { |
||
296 | m_RegionInfoCache.Cache(r); |
||
297 | if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) |
||
298 | rinfo.Add(r); |
||
299 | } |
||
300 | } |
||
301 | |||
302 | return rinfo; |
||
303 | } |
||
304 | |||
305 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) |
||
306 | { |
||
307 | List<GridRegion> rinfo = m_LocalGridService.GetFallbackRegions(scopeID, x, y); |
||
308 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetFallbackRegions {0} found {1} regions", name, rinfo.Count); |
||
309 | List<GridRegion> grinfo = m_RemoteGridService.GetFallbackRegions(scopeID, x, y); |
||
310 | |||
311 | if (grinfo != null) |
||
312 | { |
||
313 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetFallbackRegions {0} found {1} regions", name, grinfo.Count); |
||
314 | foreach (GridRegion r in grinfo) |
||
315 | { |
||
316 | m_RegionInfoCache.Cache(r); |
||
317 | if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) |
||
318 | rinfo.Add(r); |
||
319 | } |
||
320 | } |
||
321 | |||
322 | return rinfo; |
||
323 | } |
||
324 | |||
325 | public List<GridRegion> GetHyperlinks(UUID scopeID) |
||
326 | { |
||
327 | List<GridRegion> rinfo = m_LocalGridService.GetHyperlinks(scopeID); |
||
328 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetHyperlinks {0} found {1} regions", name, rinfo.Count); |
||
329 | List<GridRegion> grinfo = m_RemoteGridService.GetHyperlinks(scopeID); |
||
330 | |||
331 | if (grinfo != null) |
||
332 | { |
||
333 | //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetHyperlinks {0} found {1} regions", name, grinfo.Count); |
||
334 | foreach (GridRegion r in grinfo) |
||
335 | { |
||
336 | m_RegionInfoCache.Cache(r); |
||
337 | if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null) |
||
338 | rinfo.Add(r); |
||
339 | } |
||
340 | } |
||
341 | |||
342 | return rinfo; |
||
343 | } |
||
344 | |||
345 | public int GetRegionFlags(UUID scopeID, UUID regionID) |
||
346 | { |
||
347 | int flags = m_LocalGridService.GetRegionFlags(scopeID, regionID); |
||
348 | if (flags == -1) |
||
349 | flags = m_RemoteGridService.GetRegionFlags(scopeID, regionID); |
||
350 | |||
351 | return flags; |
||
352 | } |
||
353 | |||
354 | public Dictionary<string, object> GetExtraFeatures() |
||
355 | { |
||
356 | Dictionary<string, object> extraFeatures; |
||
357 | extraFeatures = m_LocalGridService.GetExtraFeatures(); |
||
358 | |||
359 | if (extraFeatures.Count == 0) |
||
360 | extraFeatures = m_RemoteGridService.GetExtraFeatures(); |
||
361 | |||
362 | return extraFeatures; |
||
363 | } |
||
364 | #endregion |
||
365 | } |
||
366 | } |