diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs new file mode 100644 index 0000000..3ca4882 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | |||
@@ -0,0 +1,240 @@ | |||
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 Nini.Config; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Console; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
43 | { | ||
44 | public class LocalGridServicesConnector : | ||
45 | ISharedRegionModule, IGridService | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private static LocalGridServicesConnector m_MainInstance; | ||
52 | |||
53 | private IGridService m_GridService; | ||
54 | private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); | ||
55 | |||
56 | private bool m_Enabled = false; | ||
57 | |||
58 | public LocalGridServicesConnector() | ||
59 | { | ||
60 | } | ||
61 | |||
62 | public LocalGridServicesConnector(IConfigSource source) | ||
63 | { | ||
64 | m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); | ||
65 | m_MainInstance = this; | ||
66 | InitialiseService(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 "LocalGridServicesConnector"; } | ||
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 | InitialiseService(source); | ||
90 | m_MainInstance = this; | ||
91 | m_Enabled = true; | ||
92 | m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | private void InitialiseService(IConfigSource source) | ||
98 | { | ||
99 | IConfig assetConfig = source.Configs["GridService"]; | ||
100 | if (assetConfig == null) | ||
101 | { | ||
102 | m_log.Error("[LOCAL GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | string serviceDll = assetConfig.GetString("LocalServiceModule", | ||
107 | String.Empty); | ||
108 | |||
109 | if (serviceDll == String.Empty) | ||
110 | { | ||
111 | m_log.Error("[LOCAL GRID CONNECTOR]: No LocalServiceModule named in section GridService"); | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | Object[] args = new Object[] { source }; | ||
116 | m_GridService = | ||
117 | ServerUtils.LoadPlugin<IGridService>(serviceDll, | ||
118 | args); | ||
119 | |||
120 | if (m_GridService == null) | ||
121 | { | ||
122 | m_log.Error("[LOCAL GRID CONNECTOR]: Can't load grid service"); | ||
123 | return; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public void PostInitialise() | ||
128 | { | ||
129 | if (m_MainInstance == this) | ||
130 | { | ||
131 | MainConsole.Instance.Commands.AddCommand("LocalGridConnector", false, "show neighbours", | ||
132 | "show neighbours", | ||
133 | "Shows the local regions' neighbours", NeighboursCommand); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | public void Close() | ||
138 | { | ||
139 | } | ||
140 | |||
141 | public void AddRegion(Scene scene) | ||
142 | { | ||
143 | if (m_Enabled) | ||
144 | scene.RegisterModuleInterface<IGridService>(this); | ||
145 | |||
146 | if (m_MainInstance == this) | ||
147 | { | ||
148 | if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) | ||
149 | m_log.ErrorFormat("[LOCAL GRID CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); | ||
150 | else | ||
151 | m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | public void RemoveRegion(Scene scene) | ||
156 | { | ||
157 | if (m_MainInstance == this) | ||
158 | { | ||
159 | m_LocalCache[scene.RegionInfo.RegionID].Clear(); | ||
160 | m_LocalCache.Remove(scene.RegionInfo.RegionID); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | public void RegionLoaded(Scene scene) | ||
165 | { | ||
166 | } | ||
167 | |||
168 | #endregion | ||
169 | |||
170 | #region IGridService | ||
171 | |||
172 | public bool RegisterRegion(UUID scopeID, GridRegion regionInfo) | ||
173 | { | ||
174 | return m_GridService.RegisterRegion(scopeID, regionInfo); | ||
175 | } | ||
176 | |||
177 | public bool DeregisterRegion(UUID regionID) | ||
178 | { | ||
179 | return m_GridService.DeregisterRegion(regionID); | ||
180 | } | ||
181 | |||
182 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | ||
183 | { | ||
184 | if (m_LocalCache.ContainsKey(regionID)) | ||
185 | { | ||
186 | List<GridRegion> neighbours = m_LocalCache[regionID].GetNeighbours(); | ||
187 | if (neighbours.Count == 0) | ||
188 | // try the DB | ||
189 | neighbours = m_GridService.GetNeighbours(scopeID, regionID); | ||
190 | return neighbours; | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | m_log.WarnFormat("[LOCAL GRID CONNECTOR]: GetNeighbours: Requested region {0} is not on this sim", regionID); | ||
195 | return new List<GridRegion>(); | ||
196 | } | ||
197 | |||
198 | // Don't go to the DB | ||
199 | //return m_GridService.GetNeighbours(scopeID, regionID); | ||
200 | } | ||
201 | |||
202 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | ||
203 | { | ||
204 | return m_GridService.GetRegionByUUID(scopeID, regionID); | ||
205 | } | ||
206 | |||
207 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | ||
208 | { | ||
209 | return m_GridService.GetRegionByPosition(scopeID, x, y); | ||
210 | } | ||
211 | |||
212 | public GridRegion GetRegionByName(UUID scopeID, string regionName) | ||
213 | { | ||
214 | return m_GridService.GetRegionByName(scopeID, regionName); | ||
215 | } | ||
216 | |||
217 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) | ||
218 | { | ||
219 | return m_GridService.GetRegionsByName(scopeID, name, maxNumber); | ||
220 | } | ||
221 | |||
222 | public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) | ||
223 | { | ||
224 | return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); | ||
225 | } | ||
226 | |||
227 | #endregion | ||
228 | |||
229 | public void NeighboursCommand(string module, string[] cmdparams) | ||
230 | { | ||
231 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) | ||
232 | { | ||
233 | m_log.InfoFormat("*** Neighbours of {0} {1} ***", kvp.Key, kvp.Value.RegionName); | ||
234 | List<GridRegion> regions = kvp.Value.GetNeighbours(); | ||
235 | foreach (GridRegion r in regions) | ||
236 | m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | } | ||