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