Neighbours cache working.
parent
5d09c53a1a
commit
2432cc607e
|
@ -135,6 +135,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
|
||||||
public void PostInitialise()
|
public void PostInitialise()
|
||||||
{
|
{
|
||||||
|
((ISharedRegionModule)m_GridServiceConnector).PostInitialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
@ -150,11 +151,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
scene.RegisterModuleInterface<IGridService>(this);
|
scene.RegisterModuleInterface<IGridService>(this);
|
||||||
scene.RegisterModuleInterface<IHyperlinkService>(this);
|
scene.RegisterModuleInterface<IHyperlinkService>(this);
|
||||||
|
|
||||||
|
((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRegion(Scene scene)
|
public void RemoveRegion(Scene scene)
|
||||||
{
|
{
|
||||||
m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
|
m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
|
||||||
|
((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegionLoaded(Scene scene)
|
public void RegionLoaded(Scene scene)
|
||||||
|
|
|
@ -31,6 +31,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Console;
|
||||||
using OpenSim.Server.Base;
|
using OpenSim.Server.Base;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
@ -47,7 +48,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
LogManager.GetLogger(
|
LogManager.GetLogger(
|
||||||
MethodBase.GetCurrentMethod().DeclaringType);
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private static LocalGridServicesConnector m_MainInstance;
|
||||||
|
|
||||||
private IGridService m_GridService;
|
private IGridService m_GridService;
|
||||||
|
private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>();
|
||||||
|
|
||||||
private bool m_Enabled = false;
|
private bool m_Enabled = false;
|
||||||
|
|
||||||
|
@ -58,6 +62,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
public LocalGridServicesConnector(IConfigSource source)
|
public LocalGridServicesConnector(IConfigSource source)
|
||||||
{
|
{
|
||||||
m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated");
|
m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated");
|
||||||
|
m_MainInstance = this;
|
||||||
InitialiseService(source);
|
InitialiseService(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +87,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
if (name == Name)
|
if (name == Name)
|
||||||
{
|
{
|
||||||
InitialiseService(source);
|
InitialiseService(source);
|
||||||
|
m_MainInstance = this;
|
||||||
m_Enabled = true;
|
m_Enabled = true;
|
||||||
m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled");
|
m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled");
|
||||||
}
|
}
|
||||||
|
@ -120,6 +126,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
|
||||||
public void PostInitialise()
|
public void PostInitialise()
|
||||||
{
|
{
|
||||||
|
if (m_MainInstance == this)
|
||||||
|
{
|
||||||
|
MainConsole.Instance.Commands.AddCommand("LocalGridConnector", false, "show neighbours",
|
||||||
|
"show neighbours",
|
||||||
|
"Shows the local regions' neighbours", NeighboursCommand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
@ -128,14 +140,26 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
|
||||||
public void AddRegion(Scene scene)
|
public void AddRegion(Scene scene)
|
||||||
{
|
{
|
||||||
if (!m_Enabled)
|
if (m_Enabled)
|
||||||
return;
|
|
||||||
|
|
||||||
scene.RegisterModuleInterface<IGridService>(this);
|
scene.RegisterModuleInterface<IGridService>(this);
|
||||||
|
|
||||||
|
if (m_MainInstance == this)
|
||||||
|
{
|
||||||
|
if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID))
|
||||||
|
m_log.ErrorFormat("[LOCAL GRID CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
|
||||||
|
else
|
||||||
|
m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRegion(Scene scene)
|
public void RemoveRegion(Scene scene)
|
||||||
{
|
{
|
||||||
|
if (m_MainInstance == this)
|
||||||
|
{
|
||||||
|
m_LocalCache[scene.RegionInfo.RegionID].Clear();
|
||||||
|
m_LocalCache.Remove(scene.RegionInfo.RegionID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegionLoaded(Scene scene)
|
public void RegionLoaded(Scene scene)
|
||||||
|
@ -158,7 +182,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
|
||||||
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
|
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
|
||||||
{
|
{
|
||||||
return m_GridService.GetNeighbours(scopeID, regionID);
|
if (m_LocalCache.ContainsKey(regionID))
|
||||||
|
{
|
||||||
|
return m_LocalCache[regionID].GetNeighbours();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[LOCAL GRID CONNECTOR]: GetNeighbours: Requested region {0} is not on this sim", regionID);
|
||||||
|
return new List<GridRegion>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't go to the DB
|
||||||
|
//return m_GridService.GetNeighbours(scopeID, regionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
|
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
|
||||||
|
@ -187,5 +222,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public void NeighboursCommand(string module, string[] cmdparams)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache)
|
||||||
|
{
|
||||||
|
m_log.InfoFormat("*** Neighbours of {0} {1} ***", kvp.Key, kvp.Value.RegionName);
|
||||||
|
List<GridRegion> regions = kvp.Value.GetNeighbours();
|
||||||
|
foreach (GridRegion r in regions)
|
||||||
|
m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
|
||||||
|
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
{
|
||||||
|
public class RegionCache
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private Scene m_scene;
|
||||||
|
private Dictionary<ulong, GridRegion> m_neighbours = new Dictionary<ulong, GridRegion>();
|
||||||
|
|
||||||
|
public string RegionName
|
||||||
|
{
|
||||||
|
get { return m_scene.RegionInfo.RegionName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionCache(Scene s)
|
||||||
|
{
|
||||||
|
m_scene = s;
|
||||||
|
m_scene.EventManager.OnRegionUp += OnRegionUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRegionUp(GridRegion otherRegion)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}",
|
||||||
|
m_scene.RegionInfo.RegionName, otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY);
|
||||||
|
|
||||||
|
m_neighbours[otherRegion.RegionHandle] = otherRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
m_scene.EventManager.OnRegionUp -= OnRegionUp;
|
||||||
|
m_neighbours.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GridRegion> GetNeighbours()
|
||||||
|
{
|
||||||
|
return new List<GridRegion>(m_neighbours.Values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -104,6 +104,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
|
||||||
public void PostInitialise()
|
public void PostInitialise()
|
||||||
{
|
{
|
||||||
|
if (m_LocalGridService != null)
|
||||||
|
((ISharedRegionModule)m_LocalGridService).PostInitialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
@ -112,14 +114,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
|
|
||||||
public void AddRegion(Scene scene)
|
public void AddRegion(Scene scene)
|
||||||
{
|
{
|
||||||
if (!m_Enabled)
|
if (m_Enabled)
|
||||||
return;
|
|
||||||
|
|
||||||
scene.RegisterModuleInterface<IGridService>(this);
|
scene.RegisterModuleInterface<IGridService>(this);
|
||||||
|
|
||||||
|
if (m_LocalGridService != null)
|
||||||
|
((ISharedRegionModule)m_LocalGridService).AddRegion(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRegion(Scene scene)
|
public void RemoveRegion(Scene scene)
|
||||||
{
|
{
|
||||||
|
if (m_LocalGridService != null)
|
||||||
|
((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegionLoaded(Scene scene)
|
public void RegionLoaded(Scene scene)
|
||||||
|
@ -146,7 +151,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's not override GetNeighbours -- let's get them all from the grid server
|
// Let's override GetNeighbours completely -- never go to the grid server
|
||||||
|
// Neighbours are/should be cached locally
|
||||||
|
// For retrieval from the DB, caller should call GetRegionByPosition
|
||||||
|
public override List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
|
||||||
|
{
|
||||||
|
return m_LocalGridService.GetNeighbours(scopeID, regionID);
|
||||||
|
}
|
||||||
|
|
||||||
public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
|
public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
|
||||||
{
|
{
|
||||||
|
|
|
@ -611,6 +611,9 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY);
|
int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY);
|
||||||
if (resultX <= 1 && resultY <= 1)
|
if (resultX <= 1 && resultY <= 1)
|
||||||
{
|
{
|
||||||
|
// Let the grid service module know, so this can be cached
|
||||||
|
m_eventManager.TriggerOnRegionUp(otherRegion);
|
||||||
|
|
||||||
RegionInfo regInfo = new RegionInfo(xcell, ycell, otherRegion.InternalEndPoint, otherRegion.ExternalHostName);
|
RegionInfo regInfo = new RegionInfo(xcell, ycell, otherRegion.InternalEndPoint, otherRegion.ExternalHostName);
|
||||||
regInfo.RegionID = otherRegion.RegionID;
|
regInfo.RegionID = otherRegion.RegionID;
|
||||||
regInfo.RegionName = otherRegion.RegionName;
|
regInfo.RegionName = otherRegion.RegionName;
|
||||||
|
@ -641,6 +644,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
// This shouldn't happen too often anymore.
|
// This shouldn't happen too often anymore.
|
||||||
m_log.Error("[SCENE]: Couldn't inform client of regionup because we got a null reference exception");
|
m_log.Error("[SCENE]: Couldn't inform client of regionup because we got a null reference exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -455,15 +455,13 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
// So we're temporarily going back to the old method of grabbing it from the Grid Server Every time :/
|
// So we're temporarily going back to the old method of grabbing it from the Grid Server Every time :/
|
||||||
if (m_regionInfo != null)
|
if (m_regionInfo != null)
|
||||||
{
|
{
|
||||||
neighbours =
|
neighbours = RequestNeighbours(avatar.Scene,m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
|
||||||
RequestNeighbours(avatar.Scene,m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_log.Debug("[ENABLENEIGHBOURCHILDAGENTS]: m_regionInfo was null in EnableNeighbourChildAgents, is this a NPC?");
|
m_log.Debug("[ENABLENEIGHBOURCHILDAGENTS]: m_regionInfo was null in EnableNeighbourChildAgents, is this a NPC?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// We need to find the difference between the new regions where there are no child agents
|
/// We need to find the difference between the new regions where there are no child agents
|
||||||
/// and the regions where there are already child agents. We only send notification to the former.
|
/// and the regions where there are already child agents. We only send notification to the former.
|
||||||
List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
|
List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
|
||||||
|
|
Loading…
Reference in New Issue