Applied patch from Mantis# 3387, which adds initial support for Dynamically loading IGridServiceModule "modules" in the userserver. Thank you mpallari.
parent
da2cbb75b6
commit
c7151a5a2b
|
@ -9,5 +9,6 @@ namespace OpenSim.Grid.Framework
|
|||
void Initialise(IGridServiceCore core);
|
||||
void PostInitialise();
|
||||
void RegisterHandlers(BaseHttpServer httpServer);
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
|
||||
namespace OpenSim.Grid.GridServer
|
||||
{
|
||||
public class GridModuleLoader<T>
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>();
|
||||
|
||||
public List<T> PickupModules(string path)
|
||||
{
|
||||
DirectoryInfo dir = new DirectoryInfo(path);
|
||||
List<T> modules = new List<T>();
|
||||
|
||||
foreach (FileInfo fileInfo in dir.GetFiles("*.dll"))
|
||||
{
|
||||
List<T> foundModules = this.LoadModules(fileInfo.FullName);
|
||||
modules.AddRange(foundModules);
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
public List<T> LoadModules(string dllName)
|
||||
{
|
||||
List<T> modules = new List<T>();
|
||||
|
||||
Assembly pluginAssembly;
|
||||
if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly))
|
||||
{
|
||||
try
|
||||
{
|
||||
pluginAssembly = Assembly.LoadFrom(dllName);
|
||||
LoadedAssemblys.Add(dllName, pluginAssembly);
|
||||
}
|
||||
catch (BadImageFormatException)
|
||||
{
|
||||
//m_log.InfoFormat("[MODULES]: The file [{0}] is not a module assembly.", e.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (pluginAssembly != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (Type pluginType in pluginAssembly.GetTypes())
|
||||
{
|
||||
if (pluginType.IsPublic)
|
||||
{
|
||||
if (!pluginType.IsAbstract)
|
||||
{
|
||||
if (pluginType.GetInterface(typeof(T).Name) != null)
|
||||
{
|
||||
modules.Add((T)Activator.CreateInstance(pluginType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[MODULES]: Could not load types for [{0}]. Exception {1}", pluginAssembly.FullName, e);
|
||||
|
||||
// justincc: Right now this is fatal to really get the user's attention
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ using OpenSim.Grid.Framework;
|
|||
|
||||
namespace OpenSim.Grid.UserServer.Modules
|
||||
{
|
||||
public class GridInfoServiceModule
|
||||
public class GridInfoServiceModule : IGridServiceModule
|
||||
{
|
||||
protected IGridServiceCore m_core;
|
||||
protected GridInfoService m_gridInfoService;
|
||||
|
@ -73,5 +73,10 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "GridInfoServiceModule"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
public delegate void RegionShutdownDelegate(UUID regionID);
|
||||
|
||||
|
||||
public class MessageServersConnector
|
||||
public class MessageServersConnector : IGridServiceModule
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
@ -508,5 +508,15 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
response.Value = result;
|
||||
return response;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "MessageServersConnector"; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
{
|
||||
public delegate void logOffUser(UUID AgentID);
|
||||
|
||||
public class UserManager
|
||||
public class UserManager : IGridServiceModule
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
@ -50,24 +50,22 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
|
||||
private UserDataBaseService m_userDataBaseService;
|
||||
private BaseHttpServer m_httpServer;
|
||||
private IGridServiceCore m_core;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userDataBaseService"></param>
|
||||
public UserManager( UserDataBaseService userDataBaseService)
|
||||
public UserManager()
|
||||
{
|
||||
m_userDataBaseService = userDataBaseService;
|
||||
}
|
||||
|
||||
public void Initialise(IGridServiceCore core)
|
||||
{
|
||||
|
||||
m_core = core;
|
||||
m_core.RegisterInterface<UserManager>(this);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
|
||||
if (!m_core.TryGet<UserDataBaseService>(out m_userDataBaseService))
|
||||
m_log.Error("[UserManager]: Failed to fetch database plugin");
|
||||
}
|
||||
|
||||
public void RegisterHandlers(BaseHttpServer httpServer)
|
||||
|
@ -685,6 +683,15 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
public void HandleRegionShutdown(UUID regionID)
|
||||
{
|
||||
m_userDataBaseService.LogoutUsers(regionID);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "UserManager"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,26 +39,27 @@ using OpenSim.Grid.Framework;
|
|||
|
||||
namespace OpenSim.Grid.UserServer.Modules
|
||||
{
|
||||
public class UserServerAvatarAppearanceModule
|
||||
public class UserServerAvatarAppearanceModule : IGridServiceModule
|
||||
{
|
||||
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private UserDataBaseService m_userDataBaseService;
|
||||
private BaseHttpServer m_httpServer;
|
||||
private IGridServiceCore m_core;
|
||||
|
||||
public UserServerAvatarAppearanceModule(UserDataBaseService userDataBaseService)
|
||||
public UserServerAvatarAppearanceModule()
|
||||
{
|
||||
m_userDataBaseService = userDataBaseService;
|
||||
}
|
||||
|
||||
public void Initialise(IGridServiceCore core)
|
||||
{
|
||||
|
||||
m_core = core;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
|
||||
if (!m_core.TryGet<UserDataBaseService>(out m_userDataBaseService))
|
||||
m_log.Error("[UserServerAvatarAppearanceModule]: Failed to fetch database plugin");
|
||||
}
|
||||
|
||||
public void RegisterHandlers(BaseHttpServer httpServer)
|
||||
|
@ -121,5 +122,14 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
response.Value = responseData;
|
||||
return response;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "UserServerAvatarAppearanceModule"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ using OpenSim.Grid.Framework;
|
|||
|
||||
namespace OpenSim.Grid.UserServer.Modules
|
||||
{
|
||||
public class UserServerCommandModule
|
||||
public class UserServerCommandModule : IGridServiceModule
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
|
@ -368,6 +368,16 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "UserServerCommandModule"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,32 +46,38 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
{
|
||||
//Do we actually need these event dispatchers?
|
||||
//shouldn't the other modules just directly register event handlers to each other?
|
||||
public class UserServerEventDispatchModule
|
||||
public class UserServerEventDispatchModule : IGridServiceModule
|
||||
{
|
||||
protected UserManager m_userManager;
|
||||
protected MessageServersConnector m_messagesService;
|
||||
protected UserLoginService m_loginService;
|
||||
|
||||
public UserServerEventDispatchModule(UserManager userManager, MessageServersConnector messagesService, UserLoginService loginService)
|
||||
private IGridServiceCore m_core;
|
||||
|
||||
public UserServerEventDispatchModule()
|
||||
{
|
||||
m_userManager = userManager;
|
||||
m_messagesService = messagesService;
|
||||
m_loginService = loginService;
|
||||
}
|
||||
|
||||
public void Initialise(IGridServiceCore core)
|
||||
{
|
||||
m_core = core;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
|
||||
m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff;
|
||||
if (m_core.TryGet<UserManager>(out m_userManager) &&
|
||||
m_core.TryGet<MessageServersConnector>(out m_messagesService) &&
|
||||
m_core.TryGet<UserLoginService>(out m_loginService))
|
||||
{
|
||||
|
||||
m_messagesService.OnAgentLocation += HandleAgentLocation;
|
||||
m_messagesService.OnAgentLeaving += HandleAgentLeaving;
|
||||
m_messagesService.OnRegionStartup += HandleRegionStartup;
|
||||
m_messagesService.OnRegionShutdown += HandleRegionShutdown;
|
||||
m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
|
||||
m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff;
|
||||
|
||||
m_messagesService.OnAgentLocation += HandleAgentLocation;
|
||||
m_messagesService.OnAgentLeaving += HandleAgentLeaving;
|
||||
m_messagesService.OnRegionStartup += HandleRegionStartup;
|
||||
m_messagesService.OnRegionShutdown += HandleRegionShutdown;
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterHandlers(BaseHttpServer httpServer)
|
||||
|
@ -136,5 +142,10 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
m_messagesService.TellMessageServersAboutRegionShutdown(regionID);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "UserServerEventDispatchModule"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,30 +36,32 @@ using OpenSim.Framework;
|
|||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Grid.Framework;
|
||||
using OpenSim.Grid.GridServer;
|
||||
|
||||
namespace OpenSim.Grid.UserServer.Modules
|
||||
{
|
||||
public class UserServerFriendsModule
|
||||
public class UserServerFriendsModule : IGridServiceModule
|
||||
{
|
||||
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private UserDataBaseService m_userDataBaseService;
|
||||
|
||||
private BaseHttpServer m_httpServer;
|
||||
private IGridServiceCore m_core;
|
||||
|
||||
public UserServerFriendsModule(UserDataBaseService userDataBaseService)
|
||||
public UserServerFriendsModule()
|
||||
{
|
||||
m_userDataBaseService = userDataBaseService;
|
||||
}
|
||||
|
||||
public void Initialise(IGridServiceCore core)
|
||||
{
|
||||
|
||||
m_core = core;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
|
||||
if (!m_core.TryGet<UserDataBaseService>(out m_userDataBaseService))
|
||||
m_log.Error("[UserServerFriendsModule]: Failed to fetch database plugin");
|
||||
}
|
||||
|
||||
public void RegisterHandlers(BaseHttpServer httpServer)
|
||||
|
@ -170,5 +172,14 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
|
||||
return FriendListItemListtoXmlRPCResponse(returndata);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "UserServerFriendsModule"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,18 +53,7 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
|
||||
protected UserDataBaseService m_userDataBaseService;
|
||||
|
||||
public UserManager m_userManager;
|
||||
|
||||
protected UserServerAvatarAppearanceModule m_avatarAppearanceModule;
|
||||
protected UserServerFriendsModule m_friendsModule;
|
||||
|
||||
public UserLoginService m_loginService;
|
||||
public MessageServersConnector m_messagesService;
|
||||
|
||||
protected GridInfoServiceModule m_gridInfoService;
|
||||
|
||||
protected UserServerCommandModule m_consoleCommandModule;
|
||||
protected UserServerEventDispatchModule m_eventDispatcher;
|
||||
|
||||
protected BaseHttpServer m_httpServer;
|
||||
|
||||
|
@ -72,6 +61,8 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
|
||||
protected ConsoleBase m_console;
|
||||
|
||||
protected List<IGridServiceModule> m_modules;
|
||||
|
||||
|
||||
public UserServerPlugin()
|
||||
{
|
||||
|
@ -133,24 +124,21 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
m_userDataBaseService = new UserDataBaseService();
|
||||
m_userDataBaseService.Initialise(m_core);
|
||||
|
||||
//TODO: change these modules so they fetch the databaseService class in the PostInitialise method
|
||||
m_userManager = new UserManager(m_userDataBaseService);
|
||||
m_userManager.Initialise(m_core);
|
||||
//DONE: change these modules so they fetch the databaseService class in the PostInitialise method
|
||||
|
||||
m_avatarAppearanceModule = new UserServerAvatarAppearanceModule(m_userDataBaseService);
|
||||
m_avatarAppearanceModule.Initialise(m_core);
|
||||
GridModuleLoader<IGridServiceModule> moduleLoader = new GridModuleLoader<IGridServiceModule>();
|
||||
|
||||
m_friendsModule = new UserServerFriendsModule(m_userDataBaseService);
|
||||
m_friendsModule.Initialise(m_core);
|
||||
m_modules = moduleLoader.PickupModules(".");
|
||||
|
||||
m_consoleCommandModule = new UserServerCommandModule();
|
||||
m_consoleCommandModule.Initialise(m_core);
|
||||
InitializeModules();
|
||||
}
|
||||
|
||||
m_messagesService = new MessageServersConnector();
|
||||
m_messagesService.Initialise(m_core);
|
||||
|
||||
m_gridInfoService = new GridInfoServiceModule();
|
||||
m_gridInfoService.Initialise(m_core);
|
||||
private void InitializeModules()
|
||||
{
|
||||
foreach (IGridServiceModule module in m_modules)
|
||||
{
|
||||
module.Initialise(m_core);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService)
|
||||
|
@ -164,32 +152,24 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
m_loginService.setloginlevel((int)m_cfg.DefaultUserLevel);
|
||||
|
||||
m_core.RegisterInterface<UserLoginService>(m_loginService); //TODO: should be done in the login service
|
||||
|
||||
m_eventDispatcher = new UserServerEventDispatchModule(m_userManager, m_messagesService, m_loginService);
|
||||
m_eventDispatcher.Initialise(m_core);
|
||||
}
|
||||
|
||||
protected virtual void PostInitialiseModules()
|
||||
{
|
||||
m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here
|
||||
m_userDataBaseService.PostInitialise();
|
||||
m_messagesService.PostInitialise();
|
||||
m_eventDispatcher.PostInitialise(); //it will register event handlers in here
|
||||
m_gridInfoService.PostInitialise();
|
||||
m_userManager.PostInitialise();
|
||||
m_avatarAppearanceModule.PostInitialise();
|
||||
m_friendsModule.PostInitialise();
|
||||
foreach (IGridServiceModule module in m_modules)
|
||||
{
|
||||
module.PostInitialise();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RegisterHttpHandlers()
|
||||
{
|
||||
m_loginService.RegisterHandlers(m_httpServer, m_cfg.EnableLLSDLogin, true);
|
||||
|
||||
m_userManager.RegisterHandlers(m_httpServer);
|
||||
m_friendsModule.RegisterHandlers(m_httpServer);
|
||||
m_avatarAppearanceModule.RegisterHandlers(m_httpServer);
|
||||
m_messagesService.RegisterHandlers(m_httpServer);
|
||||
m_gridInfoService.RegisterHandlers(m_httpServer);
|
||||
foreach (IGridServiceModule module in m_modules)
|
||||
{
|
||||
module.RegisterHandlers(m_httpServer);
|
||||
}
|
||||
}
|
||||
|
||||
#region IPlugin Members
|
||||
|
@ -215,7 +195,10 @@ namespace OpenSim.Grid.UserServer.Modules
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (IGridServiceModule module in m_modules)
|
||||
{
|
||||
module.Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in New Issue