Applied patch from Mantis# 3387, which adds initial support for Dynamically loading IGridServiceModule "modules" in the userserver. Thank you mpallari.

GenericGridServerConcept
MW 2009-04-03 10:35:47 +00:00
parent da2cbb75b6
commit c7151a5a2b
10 changed files with 205 additions and 80 deletions

View File

@ -9,5 +9,6 @@ namespace OpenSim.Grid.Framework
void Initialise(IGridServiceCore core); void Initialise(IGridServiceCore core);
void PostInitialise(); void PostInitialise();
void RegisterHandlers(BaseHttpServer httpServer); void RegisterHandlers(BaseHttpServer httpServer);
string Name { get; }
} }
} }

View File

@ -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;
}
}
}

View File

@ -41,7 +41,7 @@ using OpenSim.Grid.Framework;
namespace OpenSim.Grid.UserServer.Modules namespace OpenSim.Grid.UserServer.Modules
{ {
public class GridInfoServiceModule public class GridInfoServiceModule : IGridServiceModule
{ {
protected IGridServiceCore m_core; protected IGridServiceCore m_core;
protected GridInfoService m_gridInfoService; protected GridInfoService m_gridInfoService;
@ -73,5 +73,10 @@ namespace OpenSim.Grid.UserServer.Modules
public void Close() public void Close()
{ {
} }
public string Name
{
get { return "GridInfoServiceModule"; }
}
} }
} }

View File

@ -66,7 +66,7 @@ namespace OpenSim.Grid.UserServer.Modules
public delegate void RegionShutdownDelegate(UUID regionID); public delegate void RegionShutdownDelegate(UUID regionID);
public class MessageServersConnector public class MessageServersConnector : IGridServiceModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -508,5 +508,15 @@ namespace OpenSim.Grid.UserServer.Modules
response.Value = result; response.Value = result;
return response; return response;
} }
public void Close()
{
}
public string Name
{
get { return "MessageServersConnector"; }
}
} }
} }

View File

@ -41,7 +41,7 @@ namespace OpenSim.Grid.UserServer.Modules
{ {
public delegate void logOffUser(UUID AgentID); public delegate void logOffUser(UUID AgentID);
public class UserManager public class UserManager : IGridServiceModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 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 UserDataBaseService m_userDataBaseService;
private BaseHttpServer m_httpServer; private BaseHttpServer m_httpServer;
private IGridServiceCore m_core;
/// <summary> public UserManager()
///
/// </summary>
/// <param name="userDataBaseService"></param>
public UserManager( UserDataBaseService userDataBaseService)
{ {
m_userDataBaseService = userDataBaseService;
} }
public void Initialise(IGridServiceCore core) public void Initialise(IGridServiceCore core)
{ {
m_core = core;
m_core.RegisterInterface<UserManager>(this);
} }
public void PostInitialise() 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) public void RegisterHandlers(BaseHttpServer httpServer)
@ -685,6 +683,15 @@ namespace OpenSim.Grid.UserServer.Modules
public void HandleRegionShutdown(UUID regionID) public void HandleRegionShutdown(UUID regionID)
{ {
m_userDataBaseService.LogoutUsers(regionID); m_userDataBaseService.LogoutUsers(regionID);
} }
public void Close()
{
}
public string Name
{
get { return "UserManager"; }
}
} }
} }

View File

@ -39,26 +39,27 @@ using OpenSim.Grid.Framework;
namespace OpenSim.Grid.UserServer.Modules 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 UserDataBaseService m_userDataBaseService;
private BaseHttpServer m_httpServer; private BaseHttpServer m_httpServer;
private IGridServiceCore m_core;
public UserServerAvatarAppearanceModule(UserDataBaseService userDataBaseService) public UserServerAvatarAppearanceModule()
{ {
m_userDataBaseService = userDataBaseService;
} }
public void Initialise(IGridServiceCore core) public void Initialise(IGridServiceCore core)
{ {
m_core = core;
} }
public void PostInitialise() 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) public void RegisterHandlers(BaseHttpServer httpServer)
@ -121,5 +122,14 @@ namespace OpenSim.Grid.UserServer.Modules
response.Value = responseData; response.Value = responseData;
return response; return response;
} }
public void Close()
{
}
public string Name
{
get { return "UserServerAvatarAppearanceModule"; }
}
} }
} }

View File

@ -44,7 +44,7 @@ using OpenSim.Grid.Framework;
namespace OpenSim.Grid.UserServer.Modules namespace OpenSim.Grid.UserServer.Modules
{ {
public class UserServerCommandModule public class UserServerCommandModule : IGridServiceModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -368,6 +368,16 @@ namespace OpenSim.Grid.UserServer.Modules
break; break;
} }
} }
}
#endregion #endregion
public void Close()
{
}
public string Name
{
get { return "UserServerCommandModule"; }
}
}
} }

View File

@ -46,32 +46,38 @@ namespace OpenSim.Grid.UserServer.Modules
{ {
//Do we actually need these event dispatchers? //Do we actually need these event dispatchers?
//shouldn't the other modules just directly register event handlers to each other? //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 UserManager m_userManager;
protected MessageServersConnector m_messagesService; protected MessageServersConnector m_messagesService;
protected UserLoginService m_loginService; 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) public void Initialise(IGridServiceCore core)
{ {
m_core = core;
} }
public void PostInitialise() public void PostInitialise()
{ {
m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation; if (m_core.TryGet<UserManager>(out m_userManager) &&
m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff; m_core.TryGet<MessageServersConnector>(out m_messagesService) &&
m_core.TryGet<UserLoginService>(out m_loginService))
{
m_messagesService.OnAgentLocation += HandleAgentLocation; m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
m_messagesService.OnAgentLeaving += HandleAgentLeaving; m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff;
m_messagesService.OnRegionStartup += HandleRegionStartup;
m_messagesService.OnRegionShutdown += HandleRegionShutdown; m_messagesService.OnAgentLocation += HandleAgentLocation;
m_messagesService.OnAgentLeaving += HandleAgentLeaving;
m_messagesService.OnRegionStartup += HandleRegionStartup;
m_messagesService.OnRegionShutdown += HandleRegionShutdown;
}
} }
public void RegisterHandlers(BaseHttpServer httpServer) public void RegisterHandlers(BaseHttpServer httpServer)
@ -136,5 +142,10 @@ namespace OpenSim.Grid.UserServer.Modules
m_messagesService.TellMessageServersAboutRegionShutdown(regionID); m_messagesService.TellMessageServersAboutRegionShutdown(regionID);
} }
#endregion #endregion
public string Name
{
get { return "UserServerEventDispatchModule"; }
}
} }
} }

View File

@ -36,30 +36,32 @@ using OpenSim.Framework;
using OpenSim.Framework.Communications; using OpenSim.Framework.Communications;
using OpenSim.Framework.Servers; using OpenSim.Framework.Servers;
using OpenSim.Grid.Framework; using OpenSim.Grid.Framework;
using OpenSim.Grid.GridServer;
namespace OpenSim.Grid.UserServer.Modules 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 UserDataBaseService m_userDataBaseService;
private BaseHttpServer m_httpServer; private BaseHttpServer m_httpServer;
private IGridServiceCore m_core;
public UserServerFriendsModule(UserDataBaseService userDataBaseService) public UserServerFriendsModule()
{ {
m_userDataBaseService = userDataBaseService;
} }
public void Initialise(IGridServiceCore core) public void Initialise(IGridServiceCore core)
{ {
m_core = core;
} }
public void PostInitialise() 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) public void RegisterHandlers(BaseHttpServer httpServer)
@ -170,5 +172,14 @@ namespace OpenSim.Grid.UserServer.Modules
return FriendListItemListtoXmlRPCResponse(returndata); return FriendListItemListtoXmlRPCResponse(returndata);
} }
public void Close()
{
}
public string Name
{
get { return "UserServerFriendsModule"; }
}
} }
} }

View File

@ -53,18 +53,7 @@ namespace OpenSim.Grid.UserServer.Modules
protected UserDataBaseService m_userDataBaseService; protected UserDataBaseService m_userDataBaseService;
public UserManager m_userManager;
protected UserServerAvatarAppearanceModule m_avatarAppearanceModule;
protected UserServerFriendsModule m_friendsModule;
public UserLoginService m_loginService; public UserLoginService m_loginService;
public MessageServersConnector m_messagesService;
protected GridInfoServiceModule m_gridInfoService;
protected UserServerCommandModule m_consoleCommandModule;
protected UserServerEventDispatchModule m_eventDispatcher;
protected BaseHttpServer m_httpServer; protected BaseHttpServer m_httpServer;
@ -72,6 +61,8 @@ namespace OpenSim.Grid.UserServer.Modules
protected ConsoleBase m_console; protected ConsoleBase m_console;
protected List<IGridServiceModule> m_modules;
public UserServerPlugin() public UserServerPlugin()
{ {
@ -133,24 +124,21 @@ namespace OpenSim.Grid.UserServer.Modules
m_userDataBaseService = new UserDataBaseService(); m_userDataBaseService = new UserDataBaseService();
m_userDataBaseService.Initialise(m_core); m_userDataBaseService.Initialise(m_core);
//TODO: change these modules so they fetch the databaseService class in the PostInitialise method //DONE: change these modules so they fetch the databaseService class in the PostInitialise method
m_userManager = new UserManager(m_userDataBaseService);
m_userManager.Initialise(m_core);
m_avatarAppearanceModule = new UserServerAvatarAppearanceModule(m_userDataBaseService); GridModuleLoader<IGridServiceModule> moduleLoader = new GridModuleLoader<IGridServiceModule>();
m_avatarAppearanceModule.Initialise(m_core);
m_friendsModule = new UserServerFriendsModule(m_userDataBaseService); m_modules = moduleLoader.PickupModules(".");
m_friendsModule.Initialise(m_core);
m_consoleCommandModule = new UserServerCommandModule(); InitializeModules();
m_consoleCommandModule.Initialise(m_core); }
m_messagesService = new MessageServersConnector(); private void InitializeModules()
m_messagesService.Initialise(m_core); {
foreach (IGridServiceModule module in m_modules)
m_gridInfoService = new GridInfoServiceModule(); {
m_gridInfoService.Initialise(m_core); module.Initialise(m_core);
}
} }
protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService) protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService)
@ -164,32 +152,24 @@ namespace OpenSim.Grid.UserServer.Modules
m_loginService.setloginlevel((int)m_cfg.DefaultUserLevel); m_loginService.setloginlevel((int)m_cfg.DefaultUserLevel);
m_core.RegisterInterface<UserLoginService>(m_loginService); //TODO: should be done in the login service 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() protected virtual void PostInitialiseModules()
{ {
m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here foreach (IGridServiceModule module in m_modules)
m_userDataBaseService.PostInitialise(); {
m_messagesService.PostInitialise(); module.PostInitialise();
m_eventDispatcher.PostInitialise(); //it will register event handlers in here }
m_gridInfoService.PostInitialise();
m_userManager.PostInitialise();
m_avatarAppearanceModule.PostInitialise();
m_friendsModule.PostInitialise();
} }
protected virtual void RegisterHttpHandlers() protected virtual void RegisterHttpHandlers()
{ {
m_loginService.RegisterHandlers(m_httpServer, m_cfg.EnableLLSDLogin, true); m_loginService.RegisterHandlers(m_httpServer, m_cfg.EnableLLSDLogin, true);
m_userManager.RegisterHandlers(m_httpServer); foreach (IGridServiceModule module in m_modules)
m_friendsModule.RegisterHandlers(m_httpServer); {
m_avatarAppearanceModule.RegisterHandlers(m_httpServer); module.RegisterHandlers(m_httpServer);
m_messagesService.RegisterHandlers(m_httpServer); }
m_gridInfoService.RegisterHandlers(m_httpServer);
} }
#region IPlugin Members #region IPlugin Members
@ -215,7 +195,10 @@ namespace OpenSim.Grid.UserServer.Modules
public void Dispose() public void Dispose()
{ {
throw new NotImplementedException(); foreach (IGridServiceModule module in m_modules)
{
module.Close();
}
} }
#endregion #endregion