diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | 164 |
1 files changed, 74 insertions, 90 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 1f782f5..d220568 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | |||
@@ -51,7 +51,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
51 | private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]"; | 51 | private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]"; |
52 | 52 | ||
53 | private IGridService m_GridService; | 53 | private IGridService m_GridService; |
54 | private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); | 54 | private RegionInfoCache m_RegionInfoCache; |
55 | private HashSet<Scene> m_scenes = new HashSet<Scene>(); | ||
55 | 56 | ||
56 | private bool m_Enabled; | 57 | private bool m_Enabled; |
57 | 58 | ||
@@ -63,12 +64,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
63 | public LocalGridServicesConnector(IConfigSource source) | 64 | public LocalGridServicesConnector(IConfigSource source) |
64 | { | 65 | { |
65 | m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader); | 66 | m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader); |
66 | InitialiseService(source); | 67 | InitialiseService(source, null); |
68 | } | ||
69 | |||
70 | public LocalGridServicesConnector(IConfigSource source, RegionInfoCache regionInfoCache) | ||
71 | { | ||
72 | m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly with cache.", LogHeader); | ||
73 | InitialiseService(source, regionInfoCache); | ||
67 | } | 74 | } |
68 | 75 | ||
69 | #region ISharedRegionModule | 76 | #region ISharedRegionModule |
70 | 77 | ||
71 | public Type ReplaceableInterface | 78 | public Type ReplaceableInterface |
72 | { | 79 | { |
73 | get { return null; } | 80 | get { return null; } |
74 | } | 81 | } |
@@ -86,19 +93,24 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
86 | string name = moduleConfig.GetString("GridServices", ""); | 93 | string name = moduleConfig.GetString("GridServices", ""); |
87 | if (name == Name) | 94 | if (name == Name) |
88 | { | 95 | { |
89 | InitialiseService(source); | 96 | if(InitialiseService(source, null)) |
90 | m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled"); | 97 | m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled"); |
91 | } | 98 | } |
92 | } | 99 | } |
93 | } | 100 | } |
94 | 101 | ||
95 | private void InitialiseService(IConfigSource source) | 102 | private bool InitialiseService(IConfigSource source, RegionInfoCache ric) |
96 | { | 103 | { |
104 | if(ric == null && m_RegionInfoCache == null) | ||
105 | m_RegionInfoCache = new RegionInfoCache(); | ||
106 | else | ||
107 | m_RegionInfoCache = ric; | ||
108 | |||
97 | IConfig config = source.Configs["GridService"]; | 109 | IConfig config = source.Configs["GridService"]; |
98 | if (config == null) | 110 | if (config == null) |
99 | { | 111 | { |
100 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini"); | 112 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini"); |
101 | return; | 113 | return false; |
102 | } | 114 | } |
103 | 115 | ||
104 | string serviceDll = config.GetString("LocalServiceModule", String.Empty); | 116 | string serviceDll = config.GetString("LocalServiceModule", String.Empty); |
@@ -106,7 +118,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
106 | if (serviceDll == String.Empty) | 118 | if (serviceDll == String.Empty) |
107 | { | 119 | { |
108 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService"); | 120 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService"); |
109 | return; | 121 | return false; |
110 | } | 122 | } |
111 | 123 | ||
112 | Object[] args = new Object[] { source }; | 124 | Object[] args = new Object[] { source }; |
@@ -117,19 +129,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
117 | if (m_GridService == null) | 129 | if (m_GridService == null) |
118 | { | 130 | { |
119 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service"); | 131 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service"); |
120 | return; | 132 | return false; |
121 | } | 133 | } |
122 | 134 | ||
123 | m_Enabled = true; | 135 | m_Enabled = true; |
136 | return true; | ||
124 | } | 137 | } |
125 | 138 | ||
126 | public void PostInitialise() | 139 | public void PostInitialise() |
127 | { | 140 | { |
128 | // FIXME: We will still add this command even if we aren't enabled since RemoteGridServiceConnector | ||
129 | // will have instantiated us directly. | ||
130 | MainConsole.Instance.Commands.AddCommand("Regions", false, "show neighbours", | ||
131 | "show neighbours", | ||
132 | "Shows the local regions' neighbours", HandleShowNeighboursCommand); | ||
133 | } | 141 | } |
134 | 142 | ||
135 | public void Close() | 143 | public void Close() |
@@ -141,15 +149,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
141 | if (!m_Enabled) | 149 | if (!m_Enabled) |
142 | return; | 150 | return; |
143 | 151 | ||
144 | scene.RegisterModuleInterface<IGridService>(this); | 152 | lock(m_scenes) |
145 | |||
146 | lock (m_LocalCache) | ||
147 | { | 153 | { |
148 | if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) | 154 | if(!m_scenes.Contains(scene)) |
149 | m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); | 155 | m_scenes.Add(scene); |
150 | else | ||
151 | m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); | ||
152 | } | 156 | } |
157 | scene.RegisterModuleInterface<IGridService>(this); | ||
158 | |||
159 | GridRegion r = new GridRegion(scene.RegionInfo); | ||
160 | m_RegionInfoCache.CacheLocal(r); | ||
161 | |||
162 | scene.EventManager.OnRegionUp += OnRegionUp; | ||
153 | } | 163 | } |
154 | 164 | ||
155 | public void RemoveRegion(Scene scene) | 165 | public void RemoveRegion(Scene scene) |
@@ -157,11 +167,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
157 | if (!m_Enabled) | 167 | if (!m_Enabled) |
158 | return; | 168 | return; |
159 | 169 | ||
160 | lock (m_LocalCache) | 170 | lock(m_scenes) |
161 | { | 171 | { |
162 | m_LocalCache[scene.RegionInfo.RegionID].Clear(); | 172 | if(m_scenes.Contains(scene)) |
163 | m_LocalCache.Remove(scene.RegionInfo.RegionID); | 173 | m_scenes.Remove(scene); |
164 | } | 174 | } |
175 | |||
176 | m_RegionInfoCache.Remove(scene.RegionInfo.ScopeID, scene.RegionInfo.RegionHandle); | ||
177 | scene.EventManager.OnRegionUp -= OnRegionUp; | ||
165 | } | 178 | } |
166 | 179 | ||
167 | public void RegionLoaded(Scene scene) | 180 | public void RegionLoaded(Scene scene) |
@@ -172,6 +185,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
172 | 185 | ||
173 | #region IGridService | 186 | #region IGridService |
174 | 187 | ||
188 | private void OnRegionUp(GridRegion region) | ||
189 | { | ||
190 | // This shouldn't happen | ||
191 | if (region == null) | ||
192 | return; | ||
193 | |||
194 | m_RegionInfoCache.CacheNearNeighbour(region.ScopeID, region); | ||
195 | } | ||
196 | |||
175 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) | 197 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) |
176 | { | 198 | { |
177 | return m_GridService.RegisterRegion(scopeID, regionInfo); | 199 | return m_GridService.RegisterRegion(scopeID, regionInfo); |
@@ -184,12 +206,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
184 | 206 | ||
185 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | 207 | public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) |
186 | { | 208 | { |
187 | return m_GridService.GetNeighbours(scopeID, regionID); | 209 | return m_GridService.GetNeighbours(scopeID, regionID); |
188 | } | 210 | } |
189 | 211 | ||
190 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | 212 | public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) |
191 | { | 213 | { |
192 | return m_GridService.GetRegionByUUID(scopeID, regionID); | 214 | bool inCache = false; |
215 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionID,out inCache); | ||
216 | if (inCache) | ||
217 | return rinfo; | ||
218 | |||
219 | rinfo = m_GridService.GetRegionByUUID(scopeID, regionID); | ||
220 | if(rinfo != null) | ||
221 | m_RegionInfoCache.Cache(scopeID, rinfo); | ||
222 | return rinfo; | ||
193 | } | 223 | } |
194 | 224 | ||
195 | // Get a region given its base coordinates. | 225 | // Get a region given its base coordinates. |
@@ -197,59 +227,30 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
197 | // be the base coordinate of the region. | 227 | // be the base coordinate of the region. |
198 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | 228 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) |
199 | { | 229 | { |
200 | GridRegion region = null; | ||
201 | uint regionX = Util.WorldToRegionLoc((uint)x); | ||
202 | uint regionY = Util.WorldToRegionLoc((uint)y); | ||
203 | 230 | ||
204 | // Sanity check | 231 | bool inCache = false; |
205 | if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y)) | 232 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID, (uint)x, (uint)y, out inCache); |
206 | { | 233 | if (inCache) |
207 | m_log.WarnFormat("{0} GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{1},{2}>, Should Be=<{3},{4}>", | 234 | return rinfo; |
208 | LogHeader, x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY)); | ||
209 | } | ||
210 | |||
211 | // First see if it's a neighbour, even if it isn't on this sim. | ||
212 | // Neighbour data is cached in memory, so this is fast | ||
213 | |||
214 | lock (m_LocalCache) | ||
215 | { | ||
216 | foreach (RegionCache rcache in m_LocalCache.Values) | ||
217 | { | ||
218 | region = rcache.GetRegionByPosition(x, y); | ||
219 | if (region != null) | ||
220 | { | ||
221 | m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache (of region {2}). Pos=<{3},{4}>", | ||
222 | LogHeader, region.RegionName, rcache.RegionName, | ||
223 | Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY)); | ||
224 | break; | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | 235 | ||
229 | // Then try on this sim (may be a lookup in DB if this is using MySql). | 236 | // Then try on this sim (may be a lookup in DB if this is using MySql). |
230 | if (region == null) | 237 | rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); |
231 | { | 238 | if(rinfo != null) |
232 | region = m_GridService.GetRegionByPosition(scopeID, x, y); | 239 | m_RegionInfoCache.Cache(scopeID, rinfo); |
233 | 240 | return rinfo; | |
234 | if (region == null) | ||
235 | { | ||
236 | m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>", | ||
237 | LogHeader, regionX, regionY); | ||
238 | } | ||
239 | else | ||
240 | { | ||
241 | m_log.DebugFormat("{0} GetRegionByPosition. Got region {1} from grid service. Pos=<{2},{3}>", | ||
242 | LogHeader, region.RegionName, | ||
243 | Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY)); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | return region; | ||
248 | } | 241 | } |
249 | 242 | ||
250 | public GridRegion GetRegionByName(UUID scopeID, string regionName) | 243 | public GridRegion GetRegionByName(UUID scopeID, string regionName) |
251 | { | 244 | { |
252 | return m_GridService.GetRegionByName(scopeID, regionName); | 245 | bool inCache = false; |
246 | GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionName, out inCache); | ||
247 | if (inCache) | ||
248 | return rinfo; | ||
249 | |||
250 | rinfo = m_GridService.GetRegionByName(scopeID, regionName); | ||
251 | if(rinfo != null) | ||
252 | m_RegionInfoCache.Cache(scopeID, rinfo); | ||
253 | return rinfo; | ||
253 | } | 254 | } |
254 | 255 | ||
255 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) | 256 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) |
@@ -281,7 +282,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
281 | { | 282 | { |
282 | return m_GridService.GetHyperlinks(scopeID); | 283 | return m_GridService.GetHyperlinks(scopeID); |
283 | } | 284 | } |
284 | 285 | ||
285 | public int GetRegionFlags(UUID scopeID, UUID regionID) | 286 | public int GetRegionFlags(UUID scopeID, UUID regionID) |
286 | { | 287 | { |
287 | return m_GridService.GetRegionFlags(scopeID, regionID); | 288 | return m_GridService.GetRegionFlags(scopeID, regionID); |
@@ -294,22 +295,5 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
294 | 295 | ||
295 | #endregion | 296 | #endregion |
296 | 297 | ||
297 | public void HandleShowNeighboursCommand(string module, string[] cmdparams) | ||
298 | { | ||
299 | System.Text.StringBuilder caps = new System.Text.StringBuilder(); | ||
300 | |||
301 | lock (m_LocalCache) | ||
302 | { | ||
303 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) | ||
304 | { | ||
305 | caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key); | ||
306 | List<GridRegion> regions = kvp.Value.GetNeighbours(); | ||
307 | foreach (GridRegion r in regions) | ||
308 | caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY)); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | MainConsole.Instance.Output(caps.ToString()); | ||
313 | } | ||
314 | } | 298 | } |
315 | } | 299 | } |