System folders inventory cache added to OUT inventory modules. This tracks agents in and out of *sims* in order to fetch/drop their system folders from the cache. Also added region-side support for fetching the system folders from the inventory service. Nothing of this is called yet.

arthursv
Diva Canto 2009-08-11 10:30:03 -07:00
parent cdcbc48534
commit 31419a70ce
8 changed files with 238 additions and 48 deletions

View File

@ -41,7 +41,7 @@ using OpenMetaverse;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{ {
public class HGInventoryBroker : ISharedRegionModule, IInventoryService public class HGInventoryBroker : InventoryCache, ISharedRegionModule, IInventoryService
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger( LogManager.GetLogger(
@ -122,6 +122,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
m_LocalGridInventoryURI = inventoryConfig.GetString("InventoryServerURI", string.Empty); m_LocalGridInventoryURI = inventoryConfig.GetString("InventoryServerURI", string.Empty);
Init(source);
m_Enabled = true; m_Enabled = true;
m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled"); m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled");
} }
@ -136,7 +138,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{ {
} }
public void AddRegion(Scene scene) public override void AddRegion(Scene scene)
{ {
if (!m_Enabled) if (!m_Enabled)
return; return;
@ -154,10 +156,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
} }
scene.RegisterModuleInterface<IInventoryService>(this); scene.RegisterModuleInterface<IInventoryService>(this);
base.AddRegion(scene);
} }
public void RemoveRegion(Scene scene) public override void RemoveRegion(Scene scene)
{ {
base.RemoveRegion(scene);
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
@ -165,7 +169,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
if (!m_Enabled) if (!m_Enabled)
return; return;
m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled HG inventory for region {0}", scene.RegionInfo.RegionName); m_log.InfoFormat("[HG INVENTORY CONNECTOR]: Enabled HG inventory for region {0}", scene.RegionInfo.RegionName);
} }
@ -201,19 +205,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
} }
} }
public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) // Inherited. See base
{ //public override InventoryFolderBase GetFolderForType(UUID userID, AssetType type)
if (IsLocalGridUser(userID)) //{
return m_GridService.GetFolderForType(userID, type); // if (IsLocalGridUser(userID))
else // return m_GridService.GetFolderForType(userID, type);
{ // else
UUID sessionID = GetSessionID(userID); // {
string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); // UUID sessionID = GetSessionID(userID);
// !!!!!! // string uri = GetUserInventoryURI(userID) + "/" + userID.ToString();
return null; // // !!!!!!
//return m_HGService.GetFolderForType(uri, sessionID, type); // return null;
} // //return m_HGService.GetFolderForType(uri, sessionID, type);
} // }
//}
public InventoryCollection GetFolderContent(UUID userID, UUID folderID) public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
{ {
@ -227,6 +232,45 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
} }
} }
public override Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID)
{
if (IsLocalGridUser(userID))
return GetSystemFoldersLocal(userID);
else
{
UUID sessionID = GetSessionID(userID);
string uri = GetUserInventoryURI(userID) + "/" + userID.ToString();
return m_HGService.GetSystemFolders(uri, sessionID);
}
}
private Dictionary<AssetType, InventoryFolderBase> GetSystemFoldersLocal(UUID userID)
{
InventoryFolderBase root = m_GridService.GetRootFolder(userID);
if (root != null)
{
InventoryCollection content = m_GridService.GetFolderContent(userID, root.ID);
if (content != null)
{
Dictionary<AssetType, InventoryFolderBase> folders = new Dictionary<AssetType, InventoryFolderBase>();
m_log.DebugFormat("[HG INVENTORY CONNECTOR]: System folders count for {0}: {1}", userID, folders.Count);
foreach (InventoryFolderBase folder in content.Folders)
{
m_log.DebugFormat("[HG INVENTORY CONNECTOR]: scanning folder type {0}", (AssetType)folder.Type);
if (folder.Type != (short)AssetType.Folder)
folders[(AssetType)folder.Type] = folder;
}
return folders;
}
m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Root folder content not found for {0}", userID);
}
m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Root folder not found for {0}", userID);
return new Dictionary<AssetType, InventoryFolderBase>();
}
public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID) public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
{ {
return new List<InventoryItemBase>(); return new List<InventoryItemBase>();

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using OpenSim.Framework;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Scenes;
using OpenMetaverse;
using Nini.Config;
using log4net;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{
public abstract class InventoryCache
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
protected List<Scene> m_Scenes;
// The cache proper
protected Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>> m_InventoryCache;
protected virtual void Init(IConfigSource source)
{
m_Scenes = new List<Scene>();
m_InventoryCache = new Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>>();
}
public virtual void AddRegion(Scene scene)
{
m_Scenes.Add(scene);
scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
scene.EventManager.OnClientClosed += OnClientClosed;
}
public virtual void RemoveRegion(Scene scene)
{
if ((m_Scenes != null) && m_Scenes.Contains(scene))
{
m_Scenes.Remove(scene);
}
}
void OnMakeRootAgent(ScenePresence presence)
{
// Get system folders
// First check if they're here already
lock (m_InventoryCache)
{
if (m_InventoryCache.ContainsKey(presence.UUID))
{
m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent, system folders for {0} {1} already in cache", presence.Firstname, presence.Lastname);
return;
}
}
// If not, go get them and place them in the cache
Dictionary<AssetType, InventoryFolderBase> folders = GetSystemFolders(presence.UUID);
m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent, fetched system folders for {0} {1}: count {2}",
presence.Firstname, presence.Lastname, folders.Count);
if (folders.Count > 0)
lock (m_InventoryCache)
m_InventoryCache.Add(presence.UUID, folders);
}
void OnClientClosed(UUID clientID, Scene scene)
{
ScenePresence sp = null;
foreach (Scene s in m_Scenes)
{
s.TryGetAvatar(clientID, out sp);
if (sp != null)
{
m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed, but user {0} still in sim. Keeping system folders in cache", clientID);
return;
}
}
m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed, user {0} out of sim. Dropping system folders", clientID);
// Drop system folders
lock (m_InventoryCache)
if (m_InventoryCache.ContainsKey(clientID))
m_InventoryCache.Remove(clientID);
}
public abstract Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID);
public InventoryFolderBase GetFolderForType(UUID userID, AssetType type)
{
Dictionary<AssetType, InventoryFolderBase> folders = null;
lock (m_InventoryCache)
{
m_InventoryCache.TryGetValue(userID, out folders);
}
if ((folders != null) && folders.ContainsKey(type))
{
return folders[type];
}
return null;
}
}
}

View File

@ -41,7 +41,7 @@ using OpenMetaverse;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{ {
public class LocalInventoryServicesConnector : ISharedRegionModule, IInventoryService public class LocalInventoryServicesConnector : InventoryCache, ISharedRegionModule, IInventoryService
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger( LogManager.GetLogger(
@ -108,6 +108,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
// m_InventoryService.AddPlugin(new OspInventoryWrapperPlugin(plugin, this)); // m_InventoryService.AddPlugin(new OspInventoryWrapperPlugin(plugin, this));
//} //}
Init(source);
m_Enabled = true; m_Enabled = true;
m_log.Info("[INVENTORY CONNECTOR]: Local inventory connector enabled"); m_log.Info("[INVENTORY CONNECTOR]: Local inventory connector enabled");
} }
@ -122,7 +124,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{ {
} }
public void AddRegion(Scene scene) public override void AddRegion(Scene scene)
{ {
if (!m_Enabled) if (!m_Enabled)
return; return;
@ -139,10 +141,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
// "[INVENTORY CONNECTOR]: Registering IInventoryService to scene {0}", scene.RegionInfo.RegionName); // "[INVENTORY CONNECTOR]: Registering IInventoryService to scene {0}", scene.RegionInfo.RegionName);
scene.RegisterModuleInterface<IInventoryService>(this); scene.RegisterModuleInterface<IInventoryService>(this);
base.AddRegion(scene);
} }
public void RemoveRegion(Scene scene) public override void RemoveRegion(Scene scene)
{ {
base.RemoveRegion(scene);
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
@ -176,9 +180,30 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
m_InventoryService.GetUserInventory(userID, callback); m_InventoryService.GetUserInventory(userID, callback);
} }
public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) // Inherited. See base
//public InventoryFolderBase GetFolderForType(UUID userID, AssetType type)
//{
// return m_InventoryService.GetFolderForType(userID, type);
//}
public override Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID)
{ {
return m_InventoryService.GetFolderForType(userID, type); InventoryFolderBase root = GetRootFolder(userID);
if (root != null)
{
InventoryCollection content = GetFolderContent(userID, root.ID);
if (content != null)
{
Dictionary<AssetType, InventoryFolderBase> folders = new Dictionary<AssetType, InventoryFolderBase>();
foreach (InventoryFolderBase folder in content.Folders)
{
if (folder.Type != (short)AssetType.Folder)
folders[(AssetType)folder.Type] = folder;
}
return folders;
}
}
return new Dictionary<AssetType, InventoryFolderBase>();
} }
public InventoryCollection GetFolderContent(UUID userID, UUID folderID) public InventoryCollection GetFolderContent(UUID userID, UUID folderID)

View File

@ -40,7 +40,7 @@ using OpenMetaverse;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{ {
public class RemoteInventoryServicesConnector : ISharedRegionModule, IInventoryService public class RemoteInventoryServicesConnector : InventoryCache, ISharedRegionModule, IInventoryService
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -69,9 +69,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
Init(source); Init(source);
} }
private void Init(IConfigSource source) protected override void Init(IConfigSource source)
{ {
m_RemoteConnector = new InventoryServicesConnector(source); m_RemoteConnector = new InventoryServicesConnector(source);
base.Init(source);
} }
@ -101,7 +102,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{ {
} }
public void AddRegion(Scene scene) public override void AddRegion(Scene scene)
{ {
if (!m_Enabled) if (!m_Enabled)
return; return;
@ -116,10 +117,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
} }
scene.RegisterModuleInterface<IInventoryService>(this); scene.RegisterModuleInterface<IInventoryService>(this);
base.AddRegion(scene);
} }
public void RemoveRegion(Scene scene) public override void RemoveRegion(Scene scene)
{ {
base.RemoveRegion(scene);
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
@ -168,23 +171,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
} }
public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) // inherited. See base class
// public InventoryFolderBase GetFolderForType(UUID userID, AssetType type)
public override Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID)
{ {
//UUID sessionID = GetSessionID(userID); UUID sessionID = GetSessionID(userID);
//List<InventoryFolderBase> sysFolders; return m_RemoteConnector.GetSystemFolders(userID.ToString(), sessionID);
//try
//{
// sysFolders = m_RemoteConnector.GetSystemFolders(userID.ToString(), sessionID);
//}
//catch (Exception e)
//{
// m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderForType operation failed, {0} {1}",
// e.Source, e.Message);
//}
// PLACEHOLDER UNTIL CACHE IS DONE
return null;
} }
public InventoryCollection GetFolderContent(UUID userID, UUID folderID) public InventoryCollection GetFolderContent(UUID userID, UUID folderID)

View File

@ -126,7 +126,7 @@ namespace OpenSim.Services.Connectors.Inventory
/// <param name="userID"></param> /// <param name="userID"></param>
/// <param name="type"></param> /// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
public List<InventoryFolderBase> GetSystemFolders(string id, UUID sessionID) public Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(string id, UUID sessionID)
{ {
m_log.Debug("[HGInventory]: GetSystemFolders " + id); m_log.Debug("[HGInventory]: GetSystemFolders " + id);
string url = string.Empty; string url = string.Empty;
@ -138,7 +138,7 @@ namespace OpenSim.Services.Connectors.Inventory
return connector.GetSystemFolders(userID, sessionID); return connector.GetSystemFolders(userID, sessionID);
} }
return new List<InventoryFolderBase>(); return new Dictionary<AssetType, InventoryFolderBase>();
} }
/// <summary> /// <summary>

View File

@ -57,7 +57,7 @@ namespace OpenSim.Services.Connectors
/// <param name="userID"></param> /// <param name="userID"></param>
/// <param name="type"></param> /// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
List<InventoryFolderBase> GetSystemFolders(string userID, UUID session_id); Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(string userID, UUID session_id);
/// <summary> /// <summary>
/// Gets everything (folders and items) inside a folder /// Gets everything (folders and items) inside a folder

View File

@ -161,11 +161,11 @@ namespace OpenSim.Services.Connectors
/// <param name="userID"></param> /// <param name="userID"></param>
/// <param name="type"></param> /// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
public List<InventoryFolderBase> GetSystemFolders(string userID, UUID sessionID) public Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(string userID, UUID sessionID)
{ {
try try
{ {
return SynchronousRestSessionObjectPoster<string, List<InventoryFolderBase>>.BeginPostObject( return SynchronousRestSessionObjectPoster<string, Dictionary<AssetType, InventoryFolderBase>>.BeginPostObject(
"GET", m_ServerURI + "/SystemFolders/", userID, sessionID.ToString(), userID.ToString()); "GET", m_ServerURI + "/SystemFolders/", userID, sessionID.ToString(), userID.ToString());
} }
catch (Exception e) catch (Exception e)
@ -174,7 +174,7 @@ namespace OpenSim.Services.Connectors
e.Source, e.Message); e.Source, e.Message);
} }
return new List<InventoryFolderBase>(); return new Dictionary<AssetType, InventoryFolderBase>();
} }
/// <summary> /// <summary>

View File

@ -273,6 +273,26 @@ namespace OpenSim.Services.InventoryService
return root; return root;
} }
public Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID)
{
InventoryFolderBase root = GetRootFolder(userID);
if (root != null)
{
InventoryCollection content = GetFolderContent(userID, root.ID);
if (content != null)
{
Dictionary<AssetType, InventoryFolderBase> folders = new Dictionary<AssetType, InventoryFolderBase>();
foreach (InventoryFolderBase folder in content.Folders)
{
if (folder.Type != (short)AssetType.Folder)
folders[(AssetType)folder.Type] = folder;
}
return folders;
}
}
return new Dictionary<AssetType, InventoryFolderBase>();
}
public List<InventoryItemBase> GetActiveGestures(UUID userId) public List<InventoryItemBase> GetActiveGestures(UUID userId)
{ {
List<InventoryItemBase> activeGestures = new List<InventoryItemBase>(); List<InventoryItemBase> activeGestures = new List<InventoryItemBase>();