diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 743d3b9..3ca4882 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | |||
@@ -31,6 +31,7 @@ using System; | |||
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Console; | ||
34 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
35 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
@@ -47,7 +48,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
47 | LogManager.GetLogger( | 48 | LogManager.GetLogger( |
48 | MethodBase.GetCurrentMethod().DeclaringType); | 49 | MethodBase.GetCurrentMethod().DeclaringType); |
49 | 50 | ||
51 | private static LocalGridServicesConnector m_MainInstance; | ||
52 | |||
50 | private IGridService m_GridService; | 53 | private IGridService m_GridService; |
54 | private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); | ||
51 | 55 | ||
52 | private bool m_Enabled = false; | 56 | private bool m_Enabled = false; |
53 | 57 | ||
@@ -58,6 +62,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
58 | public LocalGridServicesConnector(IConfigSource source) | 62 | public LocalGridServicesConnector(IConfigSource source) |
59 | { | 63 | { |
60 | m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); | 64 | m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); |
65 | m_MainInstance = this; | ||
61 | InitialiseService(source); | 66 | InitialiseService(source); |
62 | } | 67 | } |
63 | 68 | ||
@@ -82,6 +87,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
82 | if (name == Name) | 87 | if (name == Name) |
83 | { | 88 | { |
84 | InitialiseService(source); | 89 | InitialiseService(source); |
90 | m_MainInstance = this; | ||
85 | m_Enabled = true; | 91 | m_Enabled = true; |
86 | m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); | 92 | m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); |
87 | } | 93 | } |
@@ -120,6 +126,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
120 | 126 | ||
121 | public void PostInitialise() | 127 | public void PostInitialise() |
122 | { | 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 | } | ||
123 | } | 135 | } |
124 | 136 | ||
125 | public void Close() | 137 | public void Close() |
@@ -128,14 +140,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
128 | 140 | ||
129 | public void AddRegion(Scene scene) | 141 | public void AddRegion(Scene scene) |
130 | { | 142 | { |
131 | if (!m_Enabled) | 143 | if (m_Enabled) |
132 | return; | 144 | scene.RegisterModuleInterface<IGridService>(this); |
133 | 145 | ||
134 | scene.RegisterModuleInterface<IGridService>(this); | 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 | } | ||
135 | } | 153 | } |
136 | 154 | ||
137 | public void RemoveRegion(Scene scene) | 155 | public void RemoveRegion(Scene scene) |
138 | { | 156 | { |
157 | if (m_MainInstance == this) | ||
158 | { | ||
159 | m_LocalCache[scene.RegionInfo.RegionID].Clear(); | ||
160 | m_LocalCache.Remove(scene.RegionInfo.RegionID); | ||
161 | } | ||
139 | } | 162 | } |
140 | 163 | ||
141 | public void RegionLoaded(Scene scene) | 164 | public void RegionLoaded(Scene scene) |
@@ -158,7 +181,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
158 | 181 | ||
159 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | 182 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) |
160 | { | 183 | { |
161 | return m_GridService.GetNeighbours(scopeID, regionID); | 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); | ||
162 | } | 200 | } |
163 | 201 | ||
164 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | 202 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
@@ -187,5 +225,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
187 | } | 225 | } |
188 | 226 | ||
189 | #endregion | 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 | } | ||
190 | } | 239 | } |
191 | } | 240 | } |