aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDiva Canto2009-09-27 13:43:57 -0700
committerDiva Canto2009-09-27 13:43:57 -0700
commit2432cc607ec206b79149c1e9b1aa995794fec3bc (patch)
tree291c97bb2530b386dc01ee56bf69d7884b654761 /OpenSim
parentUnpacking the mess with OtherRegionUp, so we can have a real cache of the nei... (diff)
downloadopensim-SC_OLD-2432cc607ec206b79149c1e9b1aa995794fec3bc.zip
opensim-SC_OLD-2432cc607ec206b79149c1e9b1aa995794fec3bc.tar.gz
opensim-SC_OLD-2432cc607ec206b79149c1e9b1aa995794fec3bc.tar.bz2
opensim-SC_OLD-2432cc607ec206b79149c1e9b1aa995794fec3bc.tar.xz
Neighbours cache working.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs54
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs52
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs19
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs4
6 files changed, 126 insertions, 11 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
index 52db400..c8062d7 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
@@ -135,6 +135,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
135 135
136 public void PostInitialise() 136 public void PostInitialise()
137 { 137 {
138 ((ISharedRegionModule)m_GridServiceConnector).PostInitialise();
138 } 139 }
139 140
140 public void Close() 141 public void Close()
@@ -150,11 +151,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
150 scene.RegisterModuleInterface<IGridService>(this); 151 scene.RegisterModuleInterface<IGridService>(this);
151 scene.RegisterModuleInterface<IHyperlinkService>(this); 152 scene.RegisterModuleInterface<IHyperlinkService>(this);
152 153
154 ((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene);
155
153 } 156 }
154 157
155 public void RemoveRegion(Scene scene) 158 public void RemoveRegion(Scene scene)
156 { 159 {
157 m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); 160 m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
161 ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene);
158 } 162 }
159 163
160 public void RegionLoaded(Scene scene) 164 public void RegionLoaded(Scene scene)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 743d3b9..6c2928a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -31,6 +31,7 @@ using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Reflection; 32using System.Reflection;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Console;
34using OpenSim.Server.Base; 35using OpenSim.Server.Base;
35using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes; 37using 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,26 @@ 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);
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));
133 152
134 scene.RegisterModuleInterface<IGridService>(this); 153 }
135 } 154 }
136 155
137 public void RemoveRegion(Scene scene) 156 public void RemoveRegion(Scene scene)
138 { 157 {
158 if (m_MainInstance == this)
159 {
160 m_LocalCache[scene.RegionInfo.RegionID].Clear();
161 m_LocalCache.Remove(scene.RegionInfo.RegionID);
162 }
139 } 163 }
140 164
141 public void RegionLoaded(Scene scene) 165 public void RegionLoaded(Scene scene)
@@ -158,7 +182,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
158 182
159 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) 183 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
160 { 184 {
161 return m_GridService.GetNeighbours(scopeID, regionID); 185 if (m_LocalCache.ContainsKey(regionID))
186 {
187 return m_LocalCache[regionID].GetNeighbours();
188 }
189 else
190 {
191 m_log.WarnFormat("[LOCAL GRID CONNECTOR]: GetNeighbours: Requested region {0} is not on this sim", regionID);
192 return new List<GridRegion>();
193 }
194
195 // Don't go to the DB
196 //return m_GridService.GetNeighbours(scopeID, regionID);
162 } 197 }
163 198
164 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) 199 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
@@ -187,5 +222,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
187 } 222 }
188 223
189 #endregion 224 #endregion
225
226 public void NeighboursCommand(string module, string[] cmdparams)
227 {
228 foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache)
229 {
230 m_log.InfoFormat("*** Neighbours of {0} {1} ***", kvp.Key, kvp.Value.RegionName);
231 List<GridRegion> regions = kvp.Value.GetNeighbours();
232 foreach (GridRegion r in regions)
233 m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
234 }
235 }
190 } 236 }
191} 237}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
new file mode 100644
index 0000000..ea205a2
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
@@ -0,0 +1,52 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5using OpenSim.Region.Framework.Scenes;
6using OpenSim.Services.Interfaces;
7using GridRegion = OpenSim.Services.Interfaces.GridRegion;
8
9using log4net;
10
11namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
12{
13 public class RegionCache
14 {
15 private static readonly ILog m_log =
16 LogManager.GetLogger(
17 MethodBase.GetCurrentMethod().DeclaringType);
18
19 private Scene m_scene;
20 private Dictionary<ulong, GridRegion> m_neighbours = new Dictionary<ulong, GridRegion>();
21
22 public string RegionName
23 {
24 get { return m_scene.RegionInfo.RegionName; }
25 }
26
27 public RegionCache(Scene s)
28 {
29 m_scene = s;
30 m_scene.EventManager.OnRegionUp += OnRegionUp;
31 }
32
33 private void OnRegionUp(GridRegion otherRegion)
34 {
35 m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}",
36 m_scene.RegionInfo.RegionName, otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY);
37
38 m_neighbours[otherRegion.RegionHandle] = otherRegion;
39 }
40
41 public void Clear()
42 {
43 m_scene.EventManager.OnRegionUp -= OnRegionUp;
44 m_neighbours.Clear();
45 }
46
47 public List<GridRegion> GetNeighbours()
48 {
49 return new List<GridRegion>(m_neighbours.Values);
50 }
51 }
52}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
index 91a808b..72c00fc 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
@@ -104,6 +104,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
104 104
105 public void PostInitialise() 105 public void PostInitialise()
106 { 106 {
107 if (m_LocalGridService != null)
108 ((ISharedRegionModule)m_LocalGridService).PostInitialise();
107 } 109 }
108 110
109 public void Close() 111 public void Close()
@@ -112,14 +114,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
112 114
113 public void AddRegion(Scene scene) 115 public void AddRegion(Scene scene)
114 { 116 {
115 if (!m_Enabled) 117 if (m_Enabled)
116 return; 118 scene.RegisterModuleInterface<IGridService>(this);
117 119
118 scene.RegisterModuleInterface<IGridService>(this); 120 if (m_LocalGridService != null)
121 ((ISharedRegionModule)m_LocalGridService).AddRegion(scene);
119 } 122 }
120 123
121 public void RemoveRegion(Scene scene) 124 public void RemoveRegion(Scene scene)
122 { 125 {
126 if (m_LocalGridService != null)
127 ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene);
123 } 128 }
124 129
125 public void RegionLoaded(Scene scene) 130 public void RegionLoaded(Scene scene)
@@ -146,7 +151,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
146 return false; 151 return false;
147 } 152 }
148 153
149 // Let's not override GetNeighbours -- let's get them all from the grid server 154 // Let's override GetNeighbours completely -- never go to the grid server
155 // Neighbours are/should be cached locally
156 // For retrieval from the DB, caller should call GetRegionByPosition
157 public override List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
158 {
159 return m_LocalGridService.GetNeighbours(scopeID, regionID);
160 }
150 161
151 public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) 162 public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
152 { 163 {
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 55478da..bb47ff4 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -611,6 +611,9 @@ namespace OpenSim.Region.Framework.Scenes
611 int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY); 611 int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY);
612 if (resultX <= 1 && resultY <= 1) 612 if (resultX <= 1 && resultY <= 1)
613 { 613 {
614 // Let the grid service module know, so this can be cached
615 m_eventManager.TriggerOnRegionUp(otherRegion);
616
614 RegionInfo regInfo = new RegionInfo(xcell, ycell, otherRegion.InternalEndPoint, otherRegion.ExternalHostName); 617 RegionInfo regInfo = new RegionInfo(xcell, ycell, otherRegion.InternalEndPoint, otherRegion.ExternalHostName);
615 regInfo.RegionID = otherRegion.RegionID; 618 regInfo.RegionID = otherRegion.RegionID;
616 regInfo.RegionName = otherRegion.RegionName; 619 regInfo.RegionName = otherRegion.RegionName;
@@ -641,6 +644,7 @@ namespace OpenSim.Region.Framework.Scenes
641 // This shouldn't happen too often anymore. 644 // This shouldn't happen too often anymore.
642 m_log.Error("[SCENE]: Couldn't inform client of regionup because we got a null reference exception"); 645 m_log.Error("[SCENE]: Couldn't inform client of regionup because we got a null reference exception");
643 } 646 }
647
644 } 648 }
645 else 649 else
646 { 650 {
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 3294ceb..4a2db5e 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -455,14 +455,12 @@ namespace OpenSim.Region.Framework.Scenes
455 // So we're temporarily going back to the old method of grabbing it from the Grid Server Every time :/ 455 // So we're temporarily going back to the old method of grabbing it from the Grid Server Every time :/
456 if (m_regionInfo != null) 456 if (m_regionInfo != null)
457 { 457 {
458 neighbours = 458 neighbours = RequestNeighbours(avatar.Scene,m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
459 RequestNeighbours(avatar.Scene,m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
460 } 459 }
461 else 460 else
462 { 461 {
463 m_log.Debug("[ENABLENEIGHBOURCHILDAGENTS]: m_regionInfo was null in EnableNeighbourChildAgents, is this a NPC?"); 462 m_log.Debug("[ENABLENEIGHBOURCHILDAGENTS]: m_regionInfo was null in EnableNeighbourChildAgents, is this a NPC?");
464 } 463 }
465
466 464
467 /// We need to find the difference between the new regions where there are no child agents 465 /// We need to find the difference between the new regions where there are no child agents
468 /// and the regions where there are already child agents. We only send notification to the former. 466 /// and the regions where there are already child agents. We only send notification to the former.