Unpacking the mess with OtherRegionUp, so we can have a real cache of the neighbours in the grid service modules.

This commit is contained in:
Diva Canto
2009-09-27 10:14:10 -07:00
parent 68e40a87ca
commit 5d09c53a1a
16 changed files with 99 additions and 127 deletions

View File

@@ -32,6 +32,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces;
using Caps=OpenSim.Framework.Capabilities.Caps;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.Framework.Scenes
{
@@ -305,6 +306,9 @@ namespace OpenSim.Region.Framework.Scenes
public delegate void Attach(uint localID, UUID itemID, UUID avatarID);
public event Attach OnAttach;
public delegate void RegionUp(GridRegion region);
public event RegionUp OnRegionUp;
public class MoneyTransferArgs : EventArgs
{
public UUID sender;
@@ -446,6 +450,7 @@ namespace OpenSim.Region.Framework.Scenes
private EmptyScriptCompileQueue handlerEmptyScriptCompileQueue = null;
private Attach handlerOnAttach = null;
private RegionUp handlerOnRegionUp = null;
public void TriggerOnAttach(uint localID, UUID itemID, UUID avatarID)
{
@@ -1035,5 +1040,13 @@ namespace OpenSim.Region.Framework.Scenes
if (handlerSetRootAgentScene != null)
handlerSetRootAgentScene(agentID, scene);
}
public void TriggerOnRegionUp(GridRegion otherRegion)
{
handlerOnRegionUp = OnRegionUp;
if (handlerOnRegionUp != null)
handlerOnRegionUp(otherRegion);
}
}
}

View File

@@ -587,10 +587,7 @@ namespace OpenSim.Region.Framework.Scenes
}
/// <summary>
/// Another region is up. Gets called from Grid Comms:
/// (OGS1 -> LocalBackEnd -> RegionListened -> SceneCommunicationService)
/// We have to tell all our ScenePresences about it, and add it to the
/// neighbor list.
/// Another region is up.
///
/// We only add it to the neighbor list if it's within 1 region from here.
/// Agents may have draw distance values that cross two regions though, so
@@ -599,47 +596,27 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary>
/// <param name="otherRegion">RegionInfo handle for the new region.</param>
/// <returns>True after all operations complete, throws exceptions otherwise.</returns>
public override bool OtherRegionUp(RegionInfo otherRegion)
public override void OtherRegionUp(GridRegion otherRegion)
{
m_log.InfoFormat("[SCENE]: Region {0} up in coords {1}-{2}", otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY);
uint xcell = (uint)((int)otherRegion.RegionLocX / (int)Constants.RegionSize);
uint ycell = (uint)((int)otherRegion.RegionLocY / (int)Constants.RegionSize);
m_log.InfoFormat("[SCENE]: (on region {0}): Region {1} up in coords {2}-{3}",
RegionInfo.RegionName, otherRegion.RegionName, xcell, ycell);
if (RegionInfo.RegionHandle != otherRegion.RegionHandle)
{
for (int i = 0; i < m_neighbours.Count; i++)
{
// The purpose of this loop is to re-update the known neighbors
// when another region comes up on top of another one.
// The latest region in that location ends up in the
// 'known neighbors list'
// Additionally, the commFailTF property gets reset to false.
if (m_neighbours[i].RegionHandle == otherRegion.RegionHandle)
{
lock (m_neighbours)
{
m_neighbours[i] = otherRegion;
}
}
}
// If the value isn't in the neighbours, add it.
// If the RegionInfo isn't exact but is for the same XY World location,
// then the above loop will fix that.
if (!(CheckNeighborRegion(otherRegion)))
{
lock (m_neighbours)
{
m_neighbours.Add(otherRegion);
//m_log.Info("[UP]: " + otherRegion.RegionHandle.ToString());
}
}
// If these are cast to INT because long + negative values + abs returns invalid data
int resultX = Math.Abs((int)otherRegion.RegionLocX - (int)RegionInfo.RegionLocX);
int resultY = Math.Abs((int)otherRegion.RegionLocY - (int)RegionInfo.RegionLocY);
int resultX = Math.Abs((int)xcell - (int)RegionInfo.RegionLocX);
int resultY = Math.Abs((int)ycell - (int)RegionInfo.RegionLocY);
if (resultX <= 1 && resultY <= 1)
{
RegionInfo regInfo = new RegionInfo(xcell, ycell, otherRegion.InternalEndPoint, otherRegion.ExternalHostName);
regInfo.RegionID = otherRegion.RegionID;
regInfo.RegionName = otherRegion.RegionName;
regInfo.ScopeID = otherRegion.ScopeID;
regInfo.ExternalHostName = otherRegion.ExternalHostName;
try
{
ForEachScenePresence(delegate(ScenePresence agent)
@@ -653,7 +630,7 @@ namespace OpenSim.Region.Framework.Scenes
List<ulong> old = new List<ulong>();
old.Add(otherRegion.RegionHandle);
agent.DropOldNeighbours(old);
InformClientOfNeighbor(agent, otherRegion);
InformClientOfNeighbor(agent, regInfo);
}
}
);
@@ -672,7 +649,6 @@ namespace OpenSim.Region.Framework.Scenes
otherRegion.RegionLocY.ToString() + ")");
}
}
return true;
}
public void AddNeighborRegion(RegionInfo region)
@@ -704,9 +680,10 @@ namespace OpenSim.Region.Framework.Scenes
}
// Alias IncomingHelloNeighbour OtherRegionUp, for now
public bool IncomingHelloNeighbour(RegionInfo neighbour)
public GridRegion IncomingHelloNeighbour(RegionInfo neighbour)
{
return OtherRegionUp(neighbour);
OtherRegionUp(new GridRegion(neighbour));
return new GridRegion(RegionInfo);
}
/// <summary>
@@ -3104,7 +3081,7 @@ namespace OpenSim.Region.Framework.Scenes
m_sceneGridService.OnExpectUser += HandleNewUserConnection;
m_sceneGridService.OnAvatarCrossingIntoRegion += AgentCrossing;
m_sceneGridService.OnCloseAgentConnection += IncomingCloseAgent;
m_sceneGridService.OnRegionUp += OtherRegionUp;
//m_eventManager.OnRegionUp += OtherRegionUp;
//m_sceneGridService.OnChildAgentUpdate += IncomingChildAgentDataUpdate;
m_sceneGridService.OnExpectPrim += IncomingInterRegionPrimGroup;
//m_sceneGridService.OnRemoveKnownRegionFromAvatar += HandleRemoveKnownRegionsFromAvatar;
@@ -3132,7 +3109,7 @@ namespace OpenSim.Region.Framework.Scenes
//m_sceneGridService.OnRemoveKnownRegionFromAvatar -= HandleRemoveKnownRegionsFromAvatar;
m_sceneGridService.OnExpectPrim -= IncomingInterRegionPrimGroup;
//m_sceneGridService.OnChildAgentUpdate -= IncomingChildAgentDataUpdate;
m_sceneGridService.OnRegionUp -= OtherRegionUp;
//m_eventManager.OnRegionUp -= OtherRegionUp;
m_sceneGridService.OnExpectUser -= HandleNewUserConnection;
m_sceneGridService.OnAvatarCrossingIntoRegion -= AgentCrossing;
m_sceneGridService.OnCloseAgentConnection -= IncomingCloseAgent;

View File

@@ -36,6 +36,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Region.Framework.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.Framework.Scenes
{
@@ -227,7 +228,7 @@ namespace OpenSim.Region.Framework.Scenes
return false;
}
public abstract bool OtherRegionUp(RegionInfo thisRegion);
public abstract void OtherRegionUp(GridRegion otherRegion);
public virtual string GetSimulatorVersion()
{

View File

@@ -93,10 +93,10 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary>
public event PrimCrossing OnPrimCrossingIntoRegion;
/// <summary>
/// A New Region is up and available
/// </summary>
public event RegionUp OnRegionUp;
///// <summary>
///// A New Region is up and available
///// </summary>
//public event RegionUp OnRegionUp;
/// <summary>
/// We have a child agent for this avatar and we're getting a status update about it
@@ -119,7 +119,7 @@ namespace OpenSim.Region.Framework.Scenes
private ExpectPrimDelegate handlerExpectPrim = null; // OnExpectPrim;
private CloseAgentConnection handlerCloseAgentConnection = null; // OnCloseAgentConnection;
private PrimCrossing handlerPrimCrossingIntoRegion = null; // OnPrimCrossingIntoRegion;
private RegionUp handlerRegionUp = null; // OnRegionUp;
//private RegionUp handlerRegionUp = null; // OnRegionUp;
private ChildAgentUpdate handlerChildAgentUpdate = null; // OnChildAgentUpdate;
//private RemoveKnownRegionsFromAvatarList handlerRemoveKnownRegionFromAvatar = null; // OnRemoveKnownRegionFromAvatar;
private LogOffUser handlerLogOffUser = null;
@@ -238,22 +238,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
/// <summary>
/// A New Region is now available. Inform the scene that there is a new region available.
/// </summary>
/// <param name="region">Information about the new region that is available</param>
/// <returns>True if the event was handled</returns>
protected bool newRegionUp(RegionInfo region)
{
handlerRegionUp = OnRegionUp;
if (handlerRegionUp != null)
{
//m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: newRegionUp Fired for User:" + region.RegionName);
handlerRegionUp(region);
}
return true;
}
/// <summary>
/// Inform the scene that we've got an update about a child agent that we have
/// </summary>
@@ -647,31 +631,23 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="regionhandle"></param>
private void InformNeighboursThatRegionIsUpAsync(INeighbourService neighbourService, RegionInfo region, ulong regionhandle)
{
m_log.Info("[INTERGRID]: Starting to inform neighbors that I'm here");
//RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
uint x = 0, y = 0;
Utils.LongToUInts(regionhandle, out x, out y);
//bool regionAccepted =
// m_commsProvider.InterRegion.RegionUp(new SerializableRegionInfo(region), regionhandle);
//bool regionAccepted = m_interregionCommsOut.SendHelloNeighbour(regionhandle, region);
bool regionAccepted = false;
GridRegion neighbour = null;
if (neighbourService != null)
regionAccepted = neighbourService.HelloNeighbour(regionhandle, region);
neighbour = neighbourService.HelloNeighbour(regionhandle, region);
else
m_log.DebugFormat("[SCS]: No neighbour service provided for informing neigbhours of this region");
if (regionAccepted)
if (neighbour != null)
{
m_log.Info("[INTERGRID]: Completed informing neighbors that I'm here");
handlerRegionUp = OnRegionUp;
// yes, we're notifying ourselves.
if (handlerRegionUp != null)
handlerRegionUp(region);
m_log.DebugFormat("[INTERGRID]: Successfully informed neighbour {0}-{1} that I'm here", x / Constants.RegionSize, y / Constants.RegionSize);
m_scene.EventManager.TriggerOnRegionUp(neighbour);
}
else
{
m_log.Warn("[INTERGRID]: Failed to inform neighbors that I'm here.");
m_log.WarnFormat("[INTERGRID]: Failed to inform neighbour {0}-{1} that I'm here.", x / Constants.RegionSize, y / Constants.RegionSize);
}
}
@@ -680,22 +656,33 @@ namespace OpenSim.Region.Framework.Scenes
{
//m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName);
for (int x = (int)region.RegionLocX - 1; x <= region.RegionLocX + 1; x++)
for (int y = (int)region.RegionLocY - 1; y <= region.RegionLocY + 1; y++)
if (!((x == region.RegionLocX) && (y == region.RegionLocY))) // skip this region
{
ulong handle = Utils.UIntsToLong((uint)x * Constants.RegionSize, (uint)y * Constants.RegionSize);
InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync;
List<GridRegion> neighbours = new List<GridRegion>();
// This stays uncached because we don't already know about our neighbors at this point.
d.BeginInvoke(neighbourService, region, handle,
InformNeighborsThatRegionisUpCompleted,
d);
}
neighbours = m_scene.GridService.GetNeighbours(m_regionInfo.ScopeID, m_regionInfo.RegionID);
if (neighbours != null)
{
for (int i = 0; i < neighbours.Count; i++)
{
InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync;
//List<GridRegion> neighbours = new List<GridRegion>();
//// This stays uncached because we don't already know about our neighbors at this point.
d.BeginInvoke(neighbourService, region, neighbours[i].RegionHandle,
InformNeighborsThatRegionisUpCompleted,
d);
}
}
//neighbours = m_scene.GridService.GetNeighbours(m_regionInfo.ScopeID, m_regionInfo.RegionID);
//if (neighbours != null)
//{
// for (int i = 0; i < neighbours.Count; i++)
// {
// InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync;
// d.BeginInvoke(neighbourService, region, neighbours[i].RegionHandle,
// InformNeighborsThatRegionisUpCompleted,
// d);
// }
//}
//bool val = m_commsProvider.InterRegion.RegionUp(new SerializableRegionInfo(region));
}

View File

@@ -29,6 +29,7 @@ using System;
using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Framework;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.Framework.Scenes.Tests
{
@@ -65,7 +66,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
throw new NotImplementedException();
}
public override bool OtherRegionUp(RegionInfo thisRegion)
public override void OtherRegionUp(GridRegion otherRegion)
{
throw new NotImplementedException();
}