Applied patch from mantis #3387, which adds Dynamic plugin support to gridserver. Thanks mikkopa.

GenericGridServerConcept
MW 2009-04-30 12:02:03 +00:00
parent c7151a5a2b
commit 70f283e089
10 changed files with 209 additions and 96 deletions

View File

@ -962,6 +962,10 @@ namespace OpenSim.Framework
{ {
fieldInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString()))); fieldInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
} }
else if (fieldInfo.FieldType == typeof(System.Uri))
{
fieldInfo.SetValue(settingsClass, new Uri(config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass))));
}
} }
} }
@ -986,10 +990,14 @@ namespace OpenSim.Framework
{ {
propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null); propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
} }
if (propInfo.PropertyType == typeof(System.UInt32)) else if (propInfo.PropertyType == typeof(System.UInt32))
{ {
propInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null); propInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
} }
else if (propInfo.PropertyType == typeof(System.Uri))
{
propInfo.SetValue(settingsClass, new Uri(config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null))), null);
}
} }
} }

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Grid.Framework;
using log4net;
using System.Reflection;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.GridServer.ModuleLoader
{
public class GridModuleLoaderPlugin : IGridPlugin
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected List<IGridServiceModule> m_modules;
protected GridServerBase m_core;
#region IGridPlugin Members
public void Initialise(GridServerBase gridServer)
{
m_core = gridServer;
GridModuleLoader<IGridServiceModule> moduleLoader = new GridModuleLoader<IGridServiceModule>();
m_modules = moduleLoader.PickupModules(".");
InitializeModules();
PostInitializeModules();
RegisterModuleHandlers();
}
#endregion
protected void InitializeModules()
{
foreach (IGridServiceModule m in m_modules)
{
m_log.InfoFormat("[MODULES]: Initialising Grid Service Module {0}", m.Name);
m.Initialise(m_core);
}
}
protected void PostInitializeModules()
{
foreach (IGridServiceModule m in m_modules)
{
//m_log.InfoFormat("[MODULES]: Initialising Grid Service Module {0}", m.Name);
m.PostInitialise();
}
}
protected void RegisterModuleHandlers()
{
BaseHttpServer httpServer;
if (m_core.TryGet<BaseHttpServer>(out httpServer))
{
foreach (IGridServiceModule m in m_modules)
{
//m_log.InfoFormat("[MODULES]: Initialising Grid Service Module {0}", m.Name);
m.RegisterHandlers(httpServer);
}
}
}
#region IPlugin Members
public string Version
{
get { return "0.1"; }
}
public string Name
{
get { return "GridModuleLoaderPlugin"; }
}
public void Initialise()
{
}
#endregion
#region IDisposable Members
public void Dispose()
{
}
#endregion
}
}

View File

@ -39,9 +39,9 @@ using OpenSim.Grid.Framework;
namespace OpenSim.Grid.GridServer.Modules namespace OpenSim.Grid.GridServer.Modules
{ {
public class GridMessagingModule : IMessagingServerDiscovery public class GridMessagingModule : IMessagingServerDiscovery, IGridServiceModule
{ {
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected IRegionProfileService m_gridDBService; protected IRegionProfileService m_gridDBService;
protected IGridServiceCore m_gridCore; protected IGridServiceCore m_gridCore;
@ -62,27 +62,28 @@ namespace OpenSim.Grid.GridServer.Modules
{ {
} }
public void Initialise(string opensimVersion, IRegionProfileService gridDBService, IGridServiceCore gridCore, GridConfig config) public void Initialise(IGridServiceCore core)
{ {
//m_opensimVersion = opensimVersion; m_gridCore = core;
m_gridDBService = gridDBService;
m_gridCore = gridCore;
m_config = config;
m_gridCore.RegisterInterface<IMessagingServerDiscovery>(this); m_gridCore.RegisterInterface<IMessagingServerDiscovery>(this);
RegisterHandlers();
} }
public void PostInitialise() public void PostInitialise()
{ {
if (m_gridCore.TryGet<IRegionProfileService>(out m_gridDBService) &&
m_gridCore.TryGet<GridConfig>(out m_config))
{
;
}
else
{
m_log.Error("[GridMessagingModule] Failed to post initialize module");
}
} }
public void RegisterHandlers() public void RegisterHandlers(BaseHttpServer httpServer)
{ {
//have these in separate method as some servers restart the http server and reregister all the handlers. m_httpServer = httpServer;
m_httpServer = m_gridCore.GetHttpServer();
// Message Server ---> Grid Server // Message Server ---> Grid Server
m_httpServer.AddXmlRPCHandler("register_messageserver", XmlRPCRegisterMessageServer); m_httpServer.AddXmlRPCHandler("register_messageserver", XmlRPCRegisterMessageServer);
@ -158,5 +159,14 @@ namespace OpenSim.Grid.GridServer.Modules
m_messageServers.Remove(m); m_messageServers.Remove(m);
} }
} }
public void Close()
{
}
public string Name
{
get { return "GridMessagingModule"; }
}
} }
} }

View File

@ -41,7 +41,7 @@ using OpenSim.Grid.Framework;
namespace OpenSim.Grid.GridServer.Modules namespace OpenSim.Grid.GridServer.Modules
{ {
public class GridRestModule public class GridRestModule : IGridServiceModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -67,24 +67,34 @@ namespace OpenSim.Grid.GridServer.Modules
{ {
} }
public void Initialise(string opensimVersion, GridDBService gridDBService, IGridServiceCore gridCore, GridConfig config) #region IGridServiceModule Members
public void Close()
{ {
//m_opensimVersion = opensimVersion; throw new NotImplementedException();
m_gridDBService = gridDBService; }
m_gridCore = gridCore;
m_config = config; public void Initialise(IGridServiceCore core)
RegisterHandlers(); {
m_gridCore = core;
} }
public void PostInitialise() public void PostInitialise()
{ {
IRegionProfileService dbService;
if (m_gridCore.TryGet<IRegionProfileService>(out dbService) &&
m_gridCore.TryGet<GridConfig>(out m_config))
{
if (dbService is GridDBService)
m_gridDBService = (GridDBService)dbService;
}
else
m_log.Warn("[GridRestModule]: Could not get modules from core");
} }
public void RegisterHandlers() public void RegisterHandlers(BaseHttpServer httpServer)
{ {
//have these in separate method as some servers restart the http server and reregister all the handlers. m_httpServer = httpServer;
m_httpServer = m_gridCore.GetHttpServer();
m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", RestGetSimMethod)); m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", RestGetSimMethod));
m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", RestSetSimMethod)); m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", RestSetSimMethod));
@ -93,6 +103,13 @@ namespace OpenSim.Grid.GridServer.Modules
m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", RestSetRegionMethod)); m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", RestSetRegionMethod));
} }
public string Name
{
get { return "GridRestModule"; }
}
#endregion
/// <summary> /// <summary>
/// Performs a REST Get Operation /// Performs a REST Get Operation
/// </summary> /// </summary>

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using log4net; using log4net;
using OpenSim.Data;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Grid.Framework; using OpenSim.Grid.Framework;
@ -71,19 +72,8 @@ namespace OpenSim.Grid.GridServer.Modules
//Register the database access service so modules can fetch it //Register the database access service so modules can fetch it
// RegisterInterface<GridDBService>(m_gridDBService); // RegisterInterface<GridDBService>(m_gridDBService);
m_core.RegisterInterface<IRegionProfileService>(m_gridDBService);
m_gridMessageModule = new GridMessagingModule(); m_core.RegisterInterface<GridConfig>(m_config);
m_gridMessageModule.Initialise(m_version, m_gridDBService, m_core, m_config);
m_gridXmlRpcModule = new GridXmlRpcModule();
m_gridXmlRpcModule.Initialise(m_version, m_gridDBService, m_core, m_config);
m_gridRestModule = new GridRestModule();
m_gridRestModule.Initialise(m_version, m_gridDBService, m_core, m_config);
m_gridMessageModule.PostInitialise();
m_gridXmlRpcModule.PostInitialise();
m_gridRestModule.PostInitialise();
} }
#region Console Command Handlers #region Console Command Handlers

View File

@ -42,7 +42,7 @@ using OpenSim.Grid.Framework;
namespace OpenSim.Grid.GridServer.Modules namespace OpenSim.Grid.GridServer.Modules
{ {
public class GridXmlRpcModule public class GridXmlRpcModule : IGridServiceModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -69,28 +69,27 @@ namespace OpenSim.Grid.GridServer.Modules
{ {
} }
public void Initialise(string opensimVersion, IRegionProfileService gridDBService, IGridServiceCore gridCore, GridConfig config) #region IGridServiceModule Members
public void Initialise(IGridServiceCore core)
{ {
m_opensimVersion = opensimVersion; m_gridCore = core;
m_gridDBService = gridDBService;
m_gridCore = gridCore;
m_config = config;
RegisterHandlers();
} }
public void PostInitialise() public void PostInitialise()
{ {
IMessagingServerDiscovery messagingModule; IMessagingServerDiscovery messagingModule;
if (m_gridCore.TryGet<IMessagingServerDiscovery>(out messagingModule)) if (m_gridCore.TryGet<IMessagingServerDiscovery>(out messagingModule) &&
m_gridCore.TryGet<IRegionProfileService>(out m_gridDBService) &&
m_gridCore.TryGet<GridConfig>(out m_config))
{ {
m_messagingServerMapper = messagingModule; m_messagingServerMapper = messagingModule;
} }
} }
public void RegisterHandlers() public void RegisterHandlers(BaseHttpServer httpServer)
{ {
//have these in separate method as some servers restart the http server and reregister all the handlers. m_httpServer = httpServer;
m_httpServer = m_gridCore.GetHttpServer();
m_httpServer.AddXmlRPCHandler("simulator_login", XmlRpcSimulatorLoginMethod); m_httpServer.AddXmlRPCHandler("simulator_login", XmlRpcSimulatorLoginMethod);
m_httpServer.AddXmlRPCHandler("simulator_data_request", XmlRpcSimulatorDataRequestMethod); m_httpServer.AddXmlRPCHandler("simulator_data_request", XmlRpcSimulatorDataRequestMethod);
@ -99,6 +98,17 @@ namespace OpenSim.Grid.GridServer.Modules
m_httpServer.AddXmlRPCHandler("search_for_region_by_name", XmlRpcSearchForRegionMethod); m_httpServer.AddXmlRPCHandler("search_for_region_by_name", XmlRpcSearchForRegionMethod);
} }
public string Name
{
get { return "GridXmlRpcModule"; }
}
public void Close()
{
}
#endregion
/// <summary> /// <summary>
/// Returns a XML String containing a list of the neighbouring regions /// Returns a XML String containing a list of the neighbouring regions
/// </summary> /// </summary>

View File

@ -111,10 +111,11 @@ namespace OpenSim.Grid.GridServer
IConfig startupConfig = m_configSource.Source.Configs["Startup"]; IConfig startupConfig = m_configSource.Source.Configs["Startup"];
if (startupConfig != null) if (startupConfig != null)
{ {
Convert.ToUInt32(startupConfig.GetString("HttpPort", "8051")); httpPort = Convert.ToUInt32(startupConfig.GetString("HttpPort", "8051"));
m_log.Info("[GRID]: Starting HTTP process"); m_log.InfoFormat("[GRID]: Starting HTTP process on port {0}", httpPort);
m_httpServer = new BaseHttpServer(httpPort); m_httpServer = new BaseHttpServer(httpPort);
RegisterInterface<BaseHttpServer>(m_httpServer);
string pluginsToLoad = startupConfig.GetString("LoadPlugins", ""); string pluginsToLoad = startupConfig.GetString("LoadPlugins", "");

View File

@ -90,11 +90,6 @@ namespace OpenSim.Grid.UserServer.Modules
StartupUserServerModules(); StartupUserServerModules();
StartOtherComponents(inventoryService); StartOtherComponents(inventoryService);
//PostInitialise the modules
PostInitialiseModules();
RegisterHttpHandlers();
} }
protected virtual IInterServiceInventoryServices StartupCoreComponents() protected virtual IInterServiceInventoryServices StartupCoreComponents()
@ -123,22 +118,6 @@ namespace OpenSim.Grid.UserServer.Modules
//setup database access service, for now this has to be created before the other modules. //setup database access service, for now this has to be created before the other modules.
m_userDataBaseService = new UserDataBaseService(); m_userDataBaseService = new UserDataBaseService();
m_userDataBaseService.Initialise(m_core); m_userDataBaseService.Initialise(m_core);
//DONE: change these modules so they fetch the databaseService class in the PostInitialise method
GridModuleLoader<IGridServiceModule> moduleLoader = new GridModuleLoader<IGridServiceModule>();
m_modules = moduleLoader.PickupModules(".");
InitializeModules();
}
private void InitializeModules()
{
foreach (IGridServiceModule module in m_modules)
{
module.Initialise(m_core);
}
} }
protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService) protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService)
@ -152,24 +131,8 @@ 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
}
protected virtual void PostInitialiseModules() m_loginService.RegisterHandlers(m_httpServer, m_cfg.EnableLLSDLogin, true);
{
foreach (IGridServiceModule module in m_modules)
{
module.PostInitialise();
}
}
protected virtual void RegisterHttpHandlers()
{
m_loginService.RegisterHandlers(m_httpServer, m_cfg.EnableLLSDLogin, true);
foreach (IGridServiceModule module in m_modules)
{
module.RegisterHandlers(m_httpServer);
}
} }
#region IPlugin Members #region IPlugin Members
@ -195,10 +158,6 @@ namespace OpenSim.Grid.UserServer.Modules
public void Dispose() public void Dispose()
{ {
foreach (IGridServiceModule module in m_modules)
{
module.Close();
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
[Startup] [Startup]
HttpPort = 8001 HttpPort = 8001
LoadPlugins = "GridServerPlugin,UserServerPlugin" LoadPlugins = "GridServerPlugin,UserServerPlugin,GridModuleLoaderPlugin"
[UserServerConfig] [UserServerConfig]
DatabaseProvider = "OpenSim.Data.MySql.dll" DatabaseProvider = "OpenSim.Data.MySql.dll"

View File

@ -784,6 +784,32 @@
</Files> </Files>
</Project> </Project>
<Project name="OpenSim.Grid.GridServer.ModuleLoader" path="OpenSim/Grid/GridServer.ModuleLoader" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Grid.Framework"/>
<Reference name="OpenSim.Grid.GridServer"/>
<Reference name="log4net.dll"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
<Match pattern="*.addin.xml" path="Resources" buildAction="EmbeddedResource" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Grid.AssetServer" path="OpenSim/Grid/AssetServer" type="Exe"> <Project name="OpenSim.Grid.AssetServer" path="OpenSim/Grid/AssetServer" type="Exe">
<Configuration name="Debug"> <Configuration name="Debug">