From 342126b7b9ca386f9160daecb51ecc14487a5f9f Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Wed, 22 Apr 2009 22:19:43 +0000 Subject: * Resolve http://opensimulator.org/mantis/view.php?id=3509 by putting some service initialization into CommsManager * What is really needed is a plugin and interface request system as being done for region modules --- .../CreateCommsManager/CreateCommsManagerPlugin.cs | 36 +++++------------ OpenSim/Data/IUserData.cs | 3 +- .../Communications/CommunicationsManager.cs | 6 +++ OpenSim/Framework/Communications/IUserService.cs | 7 +++- .../Framework/Communications/UserManagerBase.cs | 45 ++++++++++++---------- .../Grid/UserServer.Modules/UserDataBaseService.cs | 16 +------- OpenSim/Grid/UserServer/Main.cs | 11 +++++- OpenSim/Grid/UserServer/UserServerCommsManager.cs | 40 +++++++++++++++++++ .../Hypergrid/HGCommunicationsStandalone.cs | 37 ++++++++++++++---- .../Communications/Hypergrid/HGUserServices.cs | 8 ---- .../Communications/Local/CommunicationsLocal.cs | 24 +++++++----- .../Communications/Local/LocalUserServices.cs | 6 +-- .../Region/Communications/OGS1/OGS1UserServices.cs | 5 +-- .../Tests/Common/Mock/TestCommunicationsManager.cs | 2 +- 14 files changed, 148 insertions(+), 98 deletions(-) create mode 100644 OpenSim/Grid/UserServer/UserServerCommsManager.cs diff --git a/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs b/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs index 41ad386..c5aabc6 100644 --- a/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs +++ b/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs @@ -181,21 +181,14 @@ namespace OpenSim.ApplicationPlugins.CreateCommsManager inventoryService.AddPlugin(m_openSim.ConfigurationSettings.StandaloneInventoryPlugin, m_openSim.ConfigurationSettings.StandaloneInventorySource); - LocalUserServices userService = - new LocalUserServices( - m_openSim.NetServersInfo.DefaultHomeLocX, m_openSim.NetServersInfo.DefaultHomeLocY, inventoryService); - userService.AddPlugin(m_openSim.ConfigurationSettings.StandaloneUserPlugin, - m_openSim.ConfigurationSettings.StandaloneUserSource); - LocalBackEndServices backendService = new LocalBackEndServices(); //LocalLoginService loginService = CreateLoginService(libraryRootFolder, inventoryService, userService, backendService); m_commsManager = new CommunicationsLocal( - m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, userService, userService, - inventoryService, backendService, userService, - libraryRootFolder, m_openSim.ConfigurationSettings.DumpAssetsToFile); + m_openSim.ConfigurationSettings, m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, + inventoryService, backendService, libraryRootFolder, m_openSim.ConfigurationSettings.DumpAssetsToFile); CreateGridInfoService(); } @@ -207,7 +200,6 @@ namespace OpenSim.ApplicationPlugins.CreateCommsManager m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler()); m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim)); - } protected virtual void InitialiseHGStandaloneServices(LibraryRootFolder libraryRootFolder) @@ -215,30 +207,20 @@ namespace OpenSim.ApplicationPlugins.CreateCommsManager // Standalone mode HGInventoryServiceClient inventoryService = new HGInventoryServiceClient(m_openSim.NetServersInfo.InventoryURL, null, false); - inventoryService.AddPlugin(m_openSim.ConfigurationSettings.StandaloneInventoryPlugin, m_openSim.ConfigurationSettings.StandaloneInventorySource); - - LocalUserServices localuserService = - new LocalUserServices( - m_openSim.NetServersInfo.DefaultHomeLocX, m_openSim.NetServersInfo.DefaultHomeLocY, - inventoryService); - localuserService.AddPlugin( - m_openSim.ConfigurationSettings.StandaloneUserPlugin, - m_openSim.ConfigurationSettings.StandaloneUserSource); - - HGUserServices userService = new HGUserServices(m_commsManager, localuserService); - // This plugin arrangement could eventually be configurable rather than hardcoded here. - userService.AddPlugin(new OGS1UserDataPlugin(m_commsManager)); + inventoryService.AddPlugin(m_openSim.ConfigurationSettings.StandaloneInventoryPlugin, m_openSim.ConfigurationSettings.StandaloneInventorySource); HGGridServicesStandalone gridService = new HGGridServicesStandalone( - m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, m_openSim.SceneManager); + m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, m_openSim.SceneManager); - m_commsManager = new HGCommunicationsStandalone(m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, - userService, localuserService, inventoryService, gridService, userService, libraryRootFolder, m_openSim.ConfigurationSettings.DumpAssetsToFile); + m_commsManager + = new HGCommunicationsStandalone( + m_openSim.ConfigurationSettings, m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, + inventoryService, gridService, + libraryRootFolder, m_openSim.ConfigurationSettings.DumpAssetsToFile); inventoryService.UserProfileCache = m_commsManager.UserProfileCacheService; HGServices = gridService; - userService.SetCommunicationsManager(m_commsManager); CreateGridInfoService(); } diff --git a/OpenSim/Data/IUserData.cs b/OpenSim/Data/IUserData.cs index 573355b..d3631d5 100644 --- a/OpenSim/Data/IUserData.cs +++ b/OpenSim/Data/IUserData.cs @@ -64,7 +64,7 @@ namespace OpenSim.Data /// /// ID associated with the user's query. This must match what the client sent /// The filtered contents of the search box when the user hit search. - /// A list of user details. If there are no results than either an empty list or null can be returned + /// A list of user details. If there are no results than either an empty list or null List GeneratePickerResults(UUID queryID, string query); /// @@ -140,6 +140,7 @@ namespace OpenSim.Data /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner /// /// The agent that we're retreiving the friends Data. + /// The user's friends. If there are no results than either an empty list or null List GetUserFriendList(UUID friendlistowner); /// diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs index b4078fd..1df1f48 100644 --- a/OpenSim/Framework/Communications/CommunicationsManager.cs +++ b/OpenSim/Framework/Communications/CommunicationsManager.cs @@ -36,6 +36,12 @@ namespace OpenSim.Framework.Communications /// /// This class manages references to OpenSim non-region services (asset, inventory, user, etc.) /// + /// + /// TODO: Service retrieval needs to be managed via plugin and interfaces requests, as happens for region + /// modules from scene. Among other things, this will allow this class to be used in many different contexts + /// (from a grid service executable, to provide services on a region) without lots of messy nulls and confusion. + /// Also, a post initialize step on the plugins will be needed so that we don't get tortuous problems with + /// circular dependencies between plugins. public class CommunicationsManager { //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); diff --git a/OpenSim/Framework/Communications/IUserService.cs b/OpenSim/Framework/Communications/IUserService.cs index 3a56d35..fb24c15 100644 --- a/OpenSim/Framework/Communications/IUserService.cs +++ b/OpenSim/Framework/Communications/IUserService.cs @@ -117,7 +117,12 @@ namespace OpenSim.Framework.Communications /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship /// for UUID friendslistowner /// - /// The agent that we're retreiving the friends Data. + /// + /// The agent for whom we're retreiving the friends Data. + /// + /// A List of FriendListItems that contains info about the user's friends. + /// Always returns a list even if the user has no friends + /// List GetUserFriendList(UUID friendlistowner); // This probably shouldn't be here, it belongs to IAuthentication diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index a269b59..2d0bf63 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -35,6 +35,7 @@ using Nwc.XmlRpc; using OpenMetaverse; using OpenMetaverse.StructuredData; using OpenSim.Data; +using OpenSim.Framework.Communications; using OpenSim.Framework.Statistics; namespace OpenSim.Framework.Communications @@ -52,15 +53,15 @@ namespace OpenSim.Framework.Communications /// private List m_plugins = new List(); - protected IInterServiceInventoryServices m_interServiceInventoryService; + protected CommunicationsManager m_commsManager; /// /// Constructor /// - /// - public UserManagerBase(IInterServiceInventoryServices interServiceInventoryService) + /// + public UserManagerBase(CommunicationsManager commsManager) { - m_interServiceInventoryService = interServiceInventoryService; + m_commsManager = commsManager; } /// @@ -296,48 +297,48 @@ namespace OpenSim.Framework.Communications return null; } - /// - /// Loads a user's friend list - /// - /// the UUID of the friend list owner - /// A List of FriendListItems that contains info about the user's friends public virtual List GetUserFriendList(UUID ownerID) { + List allFriends = new List(); + foreach (IUserDataPlugin plugin in m_plugins) { try { - List result = plugin.GetUserFriendList(ownerID); + List friends = plugin.GetUserFriendList(ownerID); - if (result != null) - return result; + if (friends != null) + allFriends.AddRange(friends); } catch (Exception e) { - m_log.Info("[USERSTORAGE]: Unable to GetUserFriendList via " + plugin.Name + "(" + e.ToString() + ")"); + m_log.Error("[USERSTORAGE]: Unable to GetUserFriendList via " + plugin.Name + "(" + e.ToString() + ")"); } } - return null; + return allFriends; } public virtual Dictionary GetFriendRegionInfos (List uuids) { + //Dictionary allFriendRegions = new Dictionary(); + foreach (IUserDataPlugin plugin in m_plugins) { try { - Dictionary result = plugin.GetFriendRegionInfos(uuids); + Dictionary friendRegions = plugin.GetFriendRegionInfos(uuids); - if (result != null) - return result; + if (friendRegions != null) + return friendRegions; } catch (Exception e) { m_log.Info("[USERSTORAGE]: Unable to GetFriendRegionInfos via " + plugin.Name + "(" + e.ToString() + ")"); } } - return null; + + return new Dictionary(); } public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) @@ -662,7 +663,7 @@ namespace OpenSim.Framework.Communications } else { - m_interServiceInventoryService.CreateNewUserInventory(userProf.ID); + m_commsManager.InterServiceInventoryService.CreateNewUserInventory(userProf.ID); return userProf.ID; } @@ -731,13 +732,17 @@ namespace OpenSim.Framework.Communications { try { - return plugin.GetUserAppearance(user); + AvatarAppearance appearance = plugin.GetUserAppearance(user); + + if (appearance != null) + return appearance; } catch (Exception e) { m_log.InfoFormat("[USERSTORAGE]: Unable to find user appearance {0} via {1} ({2})", user.ToString(), plugin.Name, e.ToString()); } } + return null; } diff --git a/OpenSim/Grid/UserServer.Modules/UserDataBaseService.cs b/OpenSim/Grid/UserServer.Modules/UserDataBaseService.cs index 485dd46..51f9708 100644 --- a/OpenSim/Grid/UserServer.Modules/UserDataBaseService.cs +++ b/OpenSim/Grid/UserServer.Modules/UserDataBaseService.cs @@ -43,13 +43,8 @@ namespace OpenSim.Grid.UserServer.Modules { protected IGridServiceCore m_core; - public UserDataBaseService() - : base(null) - { - } - - public UserDataBaseService(IInterServiceInventoryServices interServiceInventoryService) - : base(interServiceInventoryService) + public UserDataBaseService(CommunicationsManager commsManager) + : base(commsManager) { } @@ -57,13 +52,6 @@ namespace OpenSim.Grid.UserServer.Modules { m_core = core; - //we only need core components so we can request them from here - IInterServiceInventoryServices inventoryService; - if (m_core.TryGet(out inventoryService)) - { - m_interServiceInventoryService = inventoryService; - } - UserConfig cfg; if (m_core.TryGet(out cfg)) { diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index c0cba4a..0a5abd3 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -145,9 +145,16 @@ namespace OpenSim.Grid.UserServer /// protected virtual void StartupUserServerModules() { - m_log.Info("[STARTUP]: Establishing data connection"); + m_log.Info("[STARTUP]: Establishing data connection"); + + //we only need core components so we can request them from here + IInterServiceInventoryServices inventoryService; + TryGet(out inventoryService); + + CommunicationsManager commsManager = new UserServerCommsManager(inventoryService); + //setup database access service, for now this has to be created before the other modules. - m_userDataBaseService = new UserDataBaseService(); + m_userDataBaseService = new UserDataBaseService(commsManager); m_userDataBaseService.Initialise(this); //TODO: change these modules so they fetch the databaseService class in the PostInitialise method diff --git a/OpenSim/Grid/UserServer/UserServerCommsManager.cs b/OpenSim/Grid/UserServer/UserServerCommsManager.cs new file mode 100644 index 0000000..519dfbc --- /dev/null +++ b/OpenSim/Grid/UserServer/UserServerCommsManager.cs @@ -0,0 +1,40 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using OpenSim.Framework.Communications; + +namespace OpenSim.Grid.UserServer +{ + public class UserServerCommsManager : CommunicationsManager + { + public UserServerCommsManager(IInterServiceInventoryServices interServiceInventoryService) + : base(null, null, null, false, null) + { + m_interServiceInventoryService = interServiceInventoryService; + } + } +} diff --git a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs index b649a91..126f42b 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsStandalone.cs @@ -25,32 +25,53 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - using OpenSim.Framework; using OpenSim.Framework.Communications; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Servers; using OpenSim.Region.Communications.Local; +using OpenSim.Region.Communications.OGS1; namespace OpenSim.Region.Communications.Hypergrid { - public class HGCommunicationsStandalone : CommunicationsLocal + public class HGCommunicationsStandalone : CommunicationsManager { public HGCommunicationsStandalone( + ConfigSettings configSettings, NetworkServersInfo serversInfo, BaseHttpServer httpServer, IAssetCache assetCache, - IUserService userService, - IUserAdminService userServiceAdmin, LocalInventoryService inventoryService, - HGGridServices gridService, IMessagingService messageService, LibraryRootFolder libraryRootFolder, bool dumpAssetsToFile) - : base(serversInfo, httpServer, assetCache, userService, userServiceAdmin, inventoryService, gridService, messageService, libraryRootFolder, dumpAssetsToFile) - { - gridService.UserProfileCache = m_userProfileCacheService; + HGGridServices gridService, + LibraryRootFolder libraryRootFolder, + bool dumpAssetsToFile) + : base(serversInfo, httpServer, assetCache, dumpAssetsToFile, libraryRootFolder) + { + LocalUserServices localUserService = + new LocalUserServices( + serversInfo.DefaultHomeLocX, serversInfo.DefaultHomeLocY, this); + localUserService.AddPlugin(configSettings.StandaloneUserPlugin, configSettings.StandaloneUserSource); + + AddInventoryService(inventoryService); + m_defaultInventoryHost = inventoryService.Host; + m_interServiceInventoryService = inventoryService; + m_assetCache = assetCache; // Let's swap to always be secure access to inventory AddSecureInventoryService((ISecureInventoryService)inventoryService); m_inventoryServices = null; + + HGUserServices hgUserService = new HGUserServices(this, localUserService); + // This plugin arrangement could eventually be configurable rather than hardcoded here. + hgUserService.AddPlugin(new OGS1UserDataPlugin(this)); + + m_userService = hgUserService; + m_userAdminService = hgUserService; + m_avatarService = hgUserService; + m_messageService = hgUserService; + + gridService.UserProfileCache = m_userProfileCacheService; + m_gridService = gridService; } } } diff --git a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs index 25c6341..93d5434 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs @@ -47,7 +47,6 @@ namespace OpenSim.Region.Communications.Hypergrid { //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private CommunicationsManager m_parent; //private OGS1UserServices m_remoteUserServices; private LocalUserServices m_localUserServices; @@ -64,12 +63,6 @@ namespace OpenSim.Region.Communications.Hypergrid m_localUserServices = local; } - // Called for standalone mode only, to set up the communications manager - public void SetCommunicationsManager(CommunicationsManager parent) - { - m_commsManager = parent; - } - /// /// Get a user agent from the user server /// @@ -84,7 +77,6 @@ namespace OpenSim.Region.Communications.Hypergrid return base.GetAgentByUUID(userId); } - /// /// Logs off a user on the user server /// diff --git a/OpenSim/Region/Communications/Local/CommunicationsLocal.cs b/OpenSim/Region/Communications/Local/CommunicationsLocal.cs index 59a1293..c17f799 100644 --- a/OpenSim/Region/Communications/Local/CommunicationsLocal.cs +++ b/OpenSim/Region/Communications/Local/CommunicationsLocal.cs @@ -35,24 +35,30 @@ namespace OpenSim.Region.Communications.Local public class CommunicationsLocal : CommunicationsManager { public CommunicationsLocal( + ConfigSettings configSettings, NetworkServersInfo serversInfo, BaseHttpServer httpServer, IAssetCache assetCache, - IUserService userService, - IUserAdminService userServiceAdmin, LocalInventoryService inventoryService, - IGridServices gridService, IMessagingService messageService, - LibraryRootFolder libraryRootFolder, bool dumpAssetsToFile) + IGridServices gridService, + LibraryRootFolder libraryRootFolder, + bool dumpAssetsToFile) : base(serversInfo, httpServer, assetCache, dumpAssetsToFile, libraryRootFolder) { AddInventoryService(inventoryService); m_defaultInventoryHost = inventoryService.Host; m_interServiceInventoryService = inventoryService; - m_userService = userService; - m_userAdminService = userServiceAdmin; - m_avatarService = (IAvatarService)userService; - m_gridService = gridService; - m_messageService = messageService; + + LocalUserServices lus + = new LocalUserServices( + serversInfo.DefaultHomeLocX, serversInfo.DefaultHomeLocY, this); + lus.AddPlugin(configSettings.StandaloneUserPlugin, configSettings.StandaloneUserSource); + m_userService = lus; + m_userAdminService = lus; + m_avatarService = lus; + m_messageService = lus; + + m_gridService = gridService; } } } diff --git a/OpenSim/Region/Communications/Local/LocalUserServices.cs b/OpenSim/Region/Communications/Local/LocalUserServices.cs index eb60610..7412500 100644 --- a/OpenSim/Region/Communications/Local/LocalUserServices.cs +++ b/OpenSim/Region/Communications/Local/LocalUserServices.cs @@ -45,10 +45,10 @@ namespace OpenSim.Region.Communications.Local /// /// /// - /// + /// public LocalUserServices( - uint defaultHomeLocX, uint defaultHomeLocY, IInterServiceInventoryServices interServiceInventoryService) - : base(interServiceInventoryService) + uint defaultHomeLocX, uint defaultHomeLocY, CommunicationsManager commsManager) + : base(commsManager) { m_defaultHomeX = defaultHomeLocX; m_defaultHomeY = defaultHomeLocY; diff --git a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs index 5f77107..fee17ac 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs @@ -46,12 +46,9 @@ namespace OpenSim.Region.Communications.OGS1 { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected CommunicationsManager m_commsManager; - public OGS1UserServices(CommunicationsManager commsManager) - : base(commsManager.InterServiceInventoryService) + : base(commsManager) { - m_commsManager = commsManager; } public override void ClearUserAgent(UUID avatarID) diff --git a/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs b/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs index 93891c0..4ade40d 100644 --- a/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs +++ b/OpenSim/Tests/Common/Mock/TestCommunicationsManager.cs @@ -67,7 +67,7 @@ namespace OpenSim.Tests.Common.Mock m_interServiceInventoryService = lis; AddInventoryService(lis); - LocalUserServices lus = new LocalUserServices(991, 992, lis); + LocalUserServices lus = new LocalUserServices(991, 992, this); lus.AddPlugin(m_userDataPlugin); m_userService = lus; m_userAdminService = lus; -- cgit v1.1