Merge branch 'master' into careminster-presence-refactor

This commit is contained in:
Melanie
2010-12-14 23:58:45 +00:00
15 changed files with 823 additions and 191 deletions

View File

@@ -41,8 +41,7 @@ using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
{
public class RemoteGridServicesConnector :
GridServicesConnector, ISharedRegionModule, IGridService
public class RemoteGridServicesConnector : ISharedRegionModule, IGridService
{
private static readonly ILog m_log =
LogManager.GetLogger(
@@ -51,6 +50,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
private bool m_Enabled = false;
private IGridService m_LocalGridService;
private IGridService m_RemoteGridService;
public RemoteGridServicesConnector()
{
@@ -73,7 +73,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
get { return "RemoteGridServicesConnector"; }
}
public override void Initialise(IConfigSource source)
public void Initialise(IConfigSource source)
{
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
@@ -97,9 +97,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
return;
}
base.Initialise(source);
m_LocalGridService = new LocalGridServicesConnector(source);
m_RemoteGridService = new GridServicesConnector(source);
}
public void PostInitialise()
@@ -135,61 +134,61 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
#region IGridService
public override string RegisterRegion(UUID scopeID, GridRegion regionInfo)
public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
{
string msg = m_LocalGridService.RegisterRegion(scopeID, regionInfo);
if (msg == String.Empty)
return base.RegisterRegion(scopeID, regionInfo);
return m_RemoteGridService.RegisterRegion(scopeID, regionInfo);
return msg;
}
public override bool DeregisterRegion(UUID regionID)
public bool DeregisterRegion(UUID regionID)
{
if (m_LocalGridService.DeregisterRegion(regionID))
return base.DeregisterRegion(regionID);
return m_RemoteGridService.DeregisterRegion(regionID);
return false;
}
public override List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
{
return base.GetNeighbours(scopeID, regionID);
return m_RemoteGridService.GetNeighbours(scopeID, regionID);
}
public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{
GridRegion rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
if (rinfo == null)
rinfo = base.GetRegionByUUID(scopeID, regionID);
rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID);
return rinfo;
}
public override GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{
GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y);
if (rinfo == null)
rinfo = base.GetRegionByPosition(scopeID, x, y);
rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y);
return rinfo;
}
public override GridRegion GetRegionByName(UUID scopeID, string regionName)
public GridRegion GetRegionByName(UUID scopeID, string regionName)
{
GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
if (rinfo == null)
rinfo = base.GetRegionByName(scopeID, regionName);
rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName);
return rinfo;
}
public override List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
{
List<GridRegion> rinfo = m_LocalGridService.GetRegionsByName(scopeID, name, maxNumber);
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionsByName {0} found {1} regions", name, rinfo.Count);
List<GridRegion> grinfo = base.GetRegionsByName(scopeID, name, maxNumber);
List<GridRegion> grinfo = m_RemoteGridService.GetRegionsByName(scopeID, name, maxNumber);
if (grinfo != null)
{
@@ -202,13 +201,79 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
return rinfo;
}
// Let's not override GetRegionRange -- let's get them all from the grid server
public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
{
List<GridRegion> rinfo = m_LocalGridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionRange {0} found {1} regions", name, rinfo.Count);
List<GridRegion> grinfo = m_RemoteGridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
public override int GetRegionFlags(UUID scopeID, UUID regionID)
if (grinfo != null)
{
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetRegionRange {0} found {1} regions", name, grinfo.Count);
foreach (GridRegion r in grinfo)
if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null)
rinfo.Add(r);
}
return rinfo;
}
public List<GridRegion> GetDefaultRegions(UUID scopeID)
{
List<GridRegion> rinfo = m_LocalGridService.GetDefaultRegions(scopeID);
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetDefaultRegions {0} found {1} regions", name, rinfo.Count);
List<GridRegion> grinfo = m_RemoteGridService.GetDefaultRegions(scopeID);
if (grinfo != null)
{
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetDefaultRegions {0} found {1} regions", name, grinfo.Count);
foreach (GridRegion r in grinfo)
if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null)
rinfo.Add(r);
}
return rinfo;
}
public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
{
List<GridRegion> rinfo = m_LocalGridService.GetFallbackRegions(scopeID, x, y);
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetFallbackRegions {0} found {1} regions", name, rinfo.Count);
List<GridRegion> grinfo = m_RemoteGridService.GetFallbackRegions(scopeID, x, y);
if (grinfo != null)
{
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetFallbackRegions {0} found {1} regions", name, grinfo.Count);
foreach (GridRegion r in grinfo)
if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null)
rinfo.Add(r);
}
return rinfo;
}
public List<GridRegion> GetHyperlinks(UUID scopeID)
{
List<GridRegion> rinfo = m_LocalGridService.GetHyperlinks(scopeID);
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetHyperlinks {0} found {1} regions", name, rinfo.Count);
List<GridRegion> grinfo = m_RemoteGridService.GetHyperlinks(scopeID);
if (grinfo != null)
{
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetHyperlinks {0} found {1} regions", name, grinfo.Count);
foreach (GridRegion r in grinfo)
if (rinfo.Find(delegate(GridRegion gr) { return gr.RegionID == r.RegionID; }) == null)
rinfo.Add(r);
}
return rinfo;
}
public int GetRegionFlags(UUID scopeID, UUID regionID)
{
int flags = m_LocalGridService.GetRegionFlags(scopeID, regionID);
if (flags == -1)
flags = base.GetRegionFlags(scopeID, regionID);
flags = m_RemoteGridService.GetRegionFlags(scopeID, regionID);
return flags;
}

View File

@@ -93,13 +93,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
}
// try to fetch from GridServer
List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(UUID.Zero, mapName, 20);
List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
if (regionInfos == null)
{
m_log.Warn("[MAPSEARCHMODULE]: RequestNamedRegions returned null. Old gridserver?");
// service wasn't available; maybe still an old GridServer. Try the old API, though it will return only one region
regionInfos = new List<GridRegion>();
GridRegion info = m_scene.GridService.GetRegionByName(UUID.Zero, mapName);
GridRegion info = m_scene.GridService.GetRegionByName(m_scene.RegionInfo.ScopeID, mapName);
if (info != null) regionInfos.Add(info);
}

View File

@@ -33,6 +33,7 @@ using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using log4net;
using Nini.Config;
@@ -413,11 +414,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
}
}
private int nAsyncRequests = 0;
/// <summary>
/// Processing thread main() loop for doing remote mapitem requests
/// </summary>
public void process()
{
const int MAX_ASYNC_REQUESTS = 20;
try
{
while (true)
@@ -437,10 +440,16 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
dorequest = false;
}
if (dorequest)
if (dorequest && !m_blacklistedregions.ContainsKey(st.regionhandle))
{
OSDMap response = RequestMapItemsAsync("", st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle);
RequestMapItemsCompleted(response);
while (nAsyncRequests >= MAX_ASYNC_REQUESTS) // hit the break
Thread.Sleep(80);
RequestMapItemsDelegate d = RequestMapItemsAsync;
d.BeginInvoke(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle, RequestMapItemsCompleted, null);
//OSDMap response = RequestMapItemsAsync(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle);
//RequestMapItemsCompleted(response);
Interlocked.Increment(ref nAsyncRequests);
}
}
@@ -469,8 +478,18 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
/// Sends the mapitem response to the IClientAPI
/// </summary>
/// <param name="response">The OSDMap Response for the mapitem</param>
private void RequestMapItemsCompleted(OSDMap response)
private void RequestMapItemsCompleted(IAsyncResult iar)
{
AsyncResult result = (AsyncResult)iar;
RequestMapItemsDelegate icon = (RequestMapItemsDelegate)result.AsyncDelegate;
OSDMap response = (OSDMap)icon.EndInvoke(iar);
Interlocked.Decrement(ref nAsyncRequests);
if (!response.ContainsKey("requestID"))
return;
UUID requestID = response["requestID"].AsUUID();
if (requestID != UUID.Zero)
@@ -538,6 +557,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
EnqueueMapItemRequest(st);
}
private delegate OSDMap RequestMapItemsDelegate(UUID id, uint flags,
uint EstateID, bool godlike, uint itemtype, ulong regionhandle);
/// <summary>
/// Does the actual remote mapitem request
/// This should be called from an asynchronous thread
@@ -552,9 +573,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
/// <param name="itemtype">passed in from packet</param>
/// <param name="regionhandle">Region we're looking up</param>
/// <returns></returns>
private OSDMap RequestMapItemsAsync(string httpserver, UUID id, uint flags,
private OSDMap RequestMapItemsAsync(UUID id, uint flags,
uint EstateID, bool godlike, uint itemtype, ulong regionhandle)
{
string httpserver = "";
bool blacklisted = false;
lock (m_blacklistedregions)
{
@@ -593,7 +615,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (!m_blacklistedregions.ContainsKey(regionhandle))
m_blacklistedregions.Add(regionhandle, Environment.TickCount);
}
m_log.InfoFormat("[WORLD MAP]: Blacklisted region {0}", regionhandle.ToString());
//m_log.InfoFormat("[WORLD MAP]: Blacklisted region {0}", regionhandle.ToString());
}
}
@@ -638,7 +660,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
os = mapitemsrequest.GetRequestStream();
os.Write(buffer, 0, buffer.Length); //Send it
os.Close();
//m_log.DebugFormat("[WORLD MAP]: Getting MapItems from Sim {0}", httpserver);
//m_log.DebugFormat("[WORLD MAP]: Getting MapItems from {0}", httpserver);
}
catch (WebException ex)
{
@@ -654,15 +676,22 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
return responseMap;
}
catch
{
m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver);
responseMap["connect"] = OSD.FromBoolean(false);
return responseMap;
}
string response_mapItems_reply = null;
{ // get the response
StreamReader sr = null;
try
{
WebResponse webResponse = mapitemsrequest.GetResponse();
if (webResponse != null)
{
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
sr = new StreamReader(webResponse.GetResponseStream());
response_mapItems_reply = sr.ReadToEnd().Trim();
}
else
@@ -683,6 +712,24 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
return responseMap;
}
catch
{
m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver);
responseMap["connect"] = OSD.FromBoolean(false);
lock (m_blacklistedregions)
{
if (!m_blacklistedregions.ContainsKey(regionhandle))
m_blacklistedregions.Add(regionhandle, Environment.TickCount);
}
return responseMap;
}
finally
{
if (sr != null)
sr.Close();
}
OSD rezResponse = null;
try
{
@@ -691,14 +738,29 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
responseMap = (OSDMap)rezResponse;
responseMap["requestID"] = OSD.FromUUID(requestID);
}
catch (Exception)
catch (Exception ex)
{
//m_log.InfoFormat("[OGP]: exception on parse of rez reply {0}", ex.Message);
m_log.InfoFormat("[WORLD MAP]: exception on parse of RequestMapItems reply from {0}: {1}", httpserver, ex.Message);
responseMap["connect"] = OSD.FromBoolean(false);
lock (m_blacklistedregions)
{
if (!m_blacklistedregions.ContainsKey(regionhandle))
m_blacklistedregions.Add(regionhandle, Environment.TickCount);
}
return responseMap;
}
}
if (!responseMap.ContainsKey(itemtype.ToString())) // remote sim doesnt have the stated region handle
{
if (!m_blacklistedregions.ContainsKey(regionhandle))
{
m_log.DebugFormat("[WORLD MAP]: Remote sim does not have the stated region. Blacklisting.");
m_blacklistedregions.Add(regionhandle, Environment.TickCount);
}
}
return responseMap;
}