From 5d09c53a1a42b38e1ee35cfbb5571d70b75380f4 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Sun, 27 Sep 2009 10:14:10 -0700
Subject: Unpacking the mess with OtherRegionUp, so we can have a real cache of
the neighbours in the grid service modules.
---
OpenSim/Region/Framework/Scenes/EventManager.cs | 13 ++++
OpenSim/Region/Framework/Scenes/Scene.cs | 63 +++++-----------
OpenSim/Region/Framework/Scenes/SceneBase.cs | 3 +-
.../Framework/Scenes/SceneCommunicationService.cs | 87 +++++++++-------------
.../Framework/Scenes/Tests/SceneBaseTests.cs | 3 +-
5 files changed, 74 insertions(+), 95 deletions(-)
(limited to 'OpenSim/Region/Framework')
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 287d8d9..7424b24 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -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);
+ }
+
}
}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 8990f29..55478da 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -587,10 +587,7 @@ namespace OpenSim.Region.Framework.Scenes
}
///
- /// 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
///
/// RegionInfo handle for the new region.
/// True after all operations complete, throws exceptions otherwise.
- 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 old = new List();
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);
}
///
@@ -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;
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index 2a82237..2af98cc 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -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()
{
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
index 9071701..3294ceb 100644
--- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs
@@ -93,10 +93,10 @@ namespace OpenSim.Region.Framework.Scenes
///
public event PrimCrossing OnPrimCrossingIntoRegion;
- ///
- /// A New Region is up and available
- ///
- public event RegionUp OnRegionUp;
+ /////
+ ///// A New Region is up and available
+ /////
+ //public event RegionUp OnRegionUp;
///
/// 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;
@@ -239,22 +239,6 @@ namespace OpenSim.Region.Framework.Scenes
}
///
- /// A New Region is now available. Inform the scene that there is a new region available.
- ///
- /// Information about the new region that is available
- /// True if the event was handled
- 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;
- }
-
- ///
/// Inform the scene that we've got an update about a child agent that we have
///
///
@@ -647,31 +631,23 @@ namespace OpenSim.Region.Framework.Scenes
///
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 neighbours = new List();
- // 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 neighbours = new List();
+ //// 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));
}
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
index f6737a5..5c9e66f 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs
@@ -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();
}
--
cgit v1.1