Remove the old style module loader and all references to it

integration
Melanie 2012-11-12 22:50:28 +00:00
parent e41374dd01
commit 8c130bcaf5
9 changed files with 21 additions and 425 deletions

View File

@ -136,9 +136,6 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
}
}
}
m_openSim.ModuleLoader.PostInitialise();
m_openSim.ModuleLoader.ClearCache();
}
public void Dispose()

View File

@ -757,33 +757,13 @@ namespace OpenSim
switch (cmdparams[0].ToLower())
{
case "list":
foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
{
MainConsole.Instance.Output(String.Format("Shared region module: {0}", irm.Name));
}
//TODO: Convert to new region modules
break;
case "unload":
if (cmdparams.Length > 1)
{
foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
{
if (rm.Name.ToLower() == cmdparams[1].ToLower())
{
MainConsole.Instance.Output(String.Format("Unloading module: {0}", rm.Name));
m_moduleLoader.UnloadModule(rm);
}
}
}
//TODO: Convert to new region modules
break;
case "load":
if (cmdparams.Length > 1)
{
foreach (Scene s in new ArrayList(SceneManager.Scenes))
{
MainConsole.Instance.Output(String.Format("Loading module: {0}", cmdparams[1]));
m_moduleLoader.LoadRegionModules(cmdparams[1], s);
}
}
//TODO: Convert to new region modules
break;
}
}
@ -1018,28 +998,9 @@ namespace OpenSim
break;
case "modules":
MainConsole.Instance.Output("The currently loaded shared modules are:");
foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
{
MainConsole.Instance.Output("Shared Module: " + module.Name);
}
SceneManager.ForEachScene(
delegate(Scene scene) {
m_log.Error("The currently loaded modules in " + scene.RegionInfo.RegionName + " are:");
foreach (IRegionModule module in scene.Modules.Values)
{
if (!module.IsSharedModule)
{
m_log.Error("Region Module: " + module.Name);
}
}
}
);
SceneManager.ForEachScene(
delegate(Scene scene) {
MainConsole.Instance.Output("Loaded new region modules in" + scene.RegionInfo.RegionName + " are:");
MainConsole.Instance.Output("Loaded region modules in" + scene.RegionInfo.RegionName + " are:");
foreach (IRegionModuleBase module in scene.RegionModules.Values)
{
Type type = module.GetType().GetInterface("ISharedRegionModule");

View File

@ -127,14 +127,6 @@ namespace OpenSim
get { return m_httpServerPort; }
}
public ModuleLoader ModuleLoader
{
get { return m_moduleLoader; }
set { m_moduleLoader = value; }
}
protected ModuleLoader m_moduleLoader;
protected IRegistryCore m_applicationRegistry = new RegistryCore();
public IRegistryCore ApplicationRegistry
@ -223,9 +215,6 @@ namespace OpenSim
base.StartupSpecific();
// Create a ModuleLoader instance
m_moduleLoader = new ModuleLoader(m_config.Source);
LoadPlugins();
foreach (IApplicationPlugin plugin in m_plugins)
{
@ -370,12 +359,6 @@ namespace OpenSim
m_log.Info("[MODULES]: Loading Region's modules (old style)");
List<IRegionModule> modules = m_moduleLoader.PickupModules(scene, ".");
// This needs to be ahead of the script engine load, so the
// script module can pick up events exposed by a module
m_moduleLoader.InitialiseSharedModules(scene);
// Use this in the future, the line above will be deprecated soon
m_log.Info("[REGIONMODULES]: Loading Region's modules (new style)");
IRegionModulesController controller;
@ -426,13 +409,6 @@ namespace OpenSim
clientServer.Start();
}
if (do_post_init)
{
foreach (IRegionModule module in modules)
{
module.PostInitialise();
}
}
scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); };
mscene = scene;
@ -722,7 +698,7 @@ namespace OpenSim
return new Scene(
regionInfo, circuitManager, sceneGridService,
simDataService, estateDataService, m_moduleLoader, false,
simDataService, estateDataService, false,
m_config.Source, m_version);
}

View File

@ -1,262 +0,0 @@
/*
* 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 OpenSimulator 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 System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using log4net;
using Nini.Config;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.Framework
{
public class ModuleLoader
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public Dictionary<string, Assembly> LoadedAssemblys = new Dictionary<string, Assembly>();
private readonly List<IRegionModule> m_loadedModules = new List<IRegionModule>();
private readonly Dictionary<string, IRegionModule> m_loadedSharedModules = new Dictionary<string, IRegionModule>();
private readonly IConfigSource m_config;
public ModuleLoader(IConfigSource config)
{
m_config = config;
}
public IRegionModule[] GetLoadedSharedModules
{
get
{
IRegionModule[] regionModules = new IRegionModule[m_loadedSharedModules.Count];
m_loadedSharedModules.Values.CopyTo(regionModules, 0);
return regionModules;
}
}
public List<IRegionModule> PickupModules(Scene scene, string moduleDir)
{
DirectoryInfo dir = new DirectoryInfo(moduleDir);
List<IRegionModule> modules = new List<IRegionModule>();
foreach (FileInfo fileInfo in dir.GetFiles("*.dll"))
{
modules.AddRange(LoadRegionModules(fileInfo.FullName, scene));
}
return modules;
}
public void LoadDefaultSharedModule(IRegionModule module)
{
if (m_loadedSharedModules.ContainsKey(module.Name))
{
m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module not added!", module.Name);
}
else
{
m_loadedSharedModules.Add(module.Name, module);
}
}
public void InitialiseSharedModules(Scene scene)
{
foreach (IRegionModule module in m_loadedSharedModules.Values)
{
module.Initialise(scene, m_config);
scene.AddModule(module.Name, module); //should be doing this?
}
}
public void InitializeModule(IRegionModule module, Scene scene)
{
module.Initialise(scene, m_config);
scene.AddModule(module.Name, module);
m_loadedModules.Add(module);
}
/// <summary>
/// Loads/initialises a Module instance that can be used by multiple Regions
/// </summary>
/// <param name="dllName"></param>
/// <param name="moduleName"></param>
public void LoadSharedModule(string dllName, string moduleName)
{
IRegionModule module = LoadModule(dllName, moduleName);
if (module != null)
LoadSharedModule(module);
}
/// <summary>
/// Loads/initialises a Module instance that can be used by multiple Regions
/// </summary>
/// <param name="module"></param>
public void LoadSharedModule(IRegionModule module)
{
if (!m_loadedSharedModules.ContainsKey(module.Name))
{
m_loadedSharedModules.Add(module.Name, module);
}
}
public List<IRegionModule> LoadRegionModules(string dllName, Scene scene)
{
IRegionModule[] modules = LoadModules(dllName);
List<IRegionModule> initializedModules = new List<IRegionModule>();
if (modules.Length > 0)
{
m_log.InfoFormat("[MODULES]: Found Module Library [{0}]", dllName);
foreach (IRegionModule module in modules)
{
if (!module.IsSharedModule)
{
m_log.InfoFormat("[MODULES]: [{0}]: Initializing.", module.Name);
InitializeModule(module, scene);
initializedModules.Add(module);
}
else
{
m_log.InfoFormat("[MODULES]: [{0}]: Loading Shared Module.", module.Name);
LoadSharedModule(module);
}
}
}
return initializedModules;
}
public void LoadRegionModule(string dllName, string moduleName, Scene scene)
{
IRegionModule module = LoadModule(dllName, moduleName);
if (module != null)
{
InitializeModule(module, scene);
}
}
/// <summary>
/// Loads a external Module (if not already loaded) and creates a new instance of it.
/// </summary>
/// <param name="dllName"></param>
/// <param name="moduleName"></param>
public IRegionModule LoadModule(string dllName, string moduleName)
{
IRegionModule[] modules = LoadModules(dllName);
foreach (IRegionModule module in modules)
{
if ((module != null) && (module.Name == moduleName))
{
return module;
}
}
return null;
}
public IRegionModule[] LoadModules(string dllName)
{
//m_log.DebugFormat("[MODULES]: Looking for modules in {0}", dllName);
List<IRegionModule> modules = new List<IRegionModule>();
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("IRegionModule") != null)
{
modules.Add((IRegionModule)Activator.CreateInstance(pluginType));
}
}
}
}
}
catch (Exception e)
{
m_log.ErrorFormat(
"[MODULES]: Could not load types for plugin DLL {0}. Exception {1} {2}",
pluginAssembly.FullName, e.Message, e.StackTrace);
// justincc: Right now this is fatal to really get the user's attention
throw e;
}
}
return modules.ToArray();
}
public void PostInitialise()
{
foreach (IRegionModule module in m_loadedSharedModules.Values)
{
module.PostInitialise();
}
foreach (IRegionModule module in m_loadedModules)
{
module.PostInitialise();
}
}
public void ClearCache()
{
LoadedAssemblys.Clear();
}
public void UnloadModule(IRegionModule rm)
{
rm.Close();
m_loadedModules.Remove(rm);
}
}
}

View File

@ -176,7 +176,6 @@ namespace OpenSim.Region.Framework.Scenes
protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
protected string m_simulatorVersion = "OpenSimulator Server";
protected ModuleLoader m_moduleLoader;
protected AgentCircuitManager m_authenticateHandler;
protected SceneCommunicationService m_sceneGridService;
@ -659,7 +658,7 @@ namespace OpenSim.Region.Framework.Scenes
public Scene(RegionInfo regInfo, AgentCircuitManager authen,
SceneCommunicationService sceneGridService,
ISimulationDataService simDataService, IEstateDataService estateDataService,
ModuleLoader moduleLoader, bool dumpAssetsToFile,
bool dumpAssetsToFile,
IConfigSource config, string simulatorVersion)
: this(regInfo)
{
@ -670,7 +669,6 @@ namespace OpenSim.Region.Framework.Scenes
Random random = new Random();
m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4);
m_moduleLoader = moduleLoader;
m_authenticateHandler = authen;
m_sceneGridService = sceneGridService;
m_SimulationDataService = simDataService;

View File

@ -67,12 +67,6 @@ namespace OpenSim.Region.Framework.Scenes
/// <value>
/// All the region modules attached to this scene.
/// </value>
public Dictionary<string, IRegionModule> Modules
{
get { return m_modules; }
}
protected Dictionary<string, IRegionModule> m_modules = new Dictionary<string, IRegionModule>();
public Dictionary<string, IRegionModuleBase> RegionModules
{
get { return m_regionModules; }
@ -272,16 +266,6 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary>
public virtual void Close()
{
// Shut down all non shared modules.
foreach (IRegionModule module in Modules.Values)
{
if (!module.IsSharedModule)
{
module.Close();
}
}
Modules.Clear();
try
{
EventManager.TriggerShutdown();
@ -311,19 +295,6 @@ namespace OpenSim.Region.Framework.Scenes
#region Module Methods
/// <summary>
/// Add a module to this scene.
/// </summary>
/// <param name="name"></param>
/// <param name="module"></param>
public void AddModule(string name, IRegionModule module)
{
if (!Modules.ContainsKey(name))
{
Modules.Add(name, module);
}
}
/// <summary>
/// Add a region-module to this scene. TODO: This will replace AddModule in the future.
/// </summary>
@ -508,9 +479,9 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="shorthelp"></param>
/// <param name="longhelp"></param>
/// <param name="callback"></param>
public void AddCommand(object mod, string command, string shorthelp, string longhelp, CommandDelegate callback)
public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
{
AddCommand(mod, command, shorthelp, longhelp, string.Empty, callback);
AddCommand(module, command, shorthelp, longhelp, string.Empty, callback);
}
/// <summary>
@ -528,9 +499,9 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="longhelp"></param>
/// <param name="callback"></param>
public void AddCommand(
string category, object mod, string command, string shorthelp, string longhelp, CommandDelegate callback)
string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
{
AddCommand(category, mod, command, shorthelp, longhelp, string.Empty, callback);
AddCommand(category, module, command, shorthelp, longhelp, string.Empty, callback);
}
/// <summary>
@ -542,29 +513,14 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="longhelp"></param>
/// <param name="descriptivehelp"></param>
/// <param name="callback"></param>
public void AddCommand(object mod, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
{
string moduleName = "";
if (mod != null)
{
if (mod is IRegionModule)
{
IRegionModule module = (IRegionModule)mod;
moduleName = module.Name;
}
else if (mod is IRegionModuleBase)
{
IRegionModuleBase module = (IRegionModuleBase)mod;
moduleName = module.Name;
}
else
{
throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase");
}
}
if (module != null)
moduleName = module.Name;
AddCommand(moduleName, mod, command, shorthelp, longhelp, descriptivehelp, callback);
AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback);
}
/// <summary>
@ -580,7 +536,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="descriptivehelp"></param>
/// <param name="callback"></param>
public void AddCommand(
string category, object mod, string command,
string category, IRegionModuleBase module, string command,
string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
{
if (MainConsole.Instance == null)
@ -588,22 +544,8 @@ namespace OpenSim.Region.Framework.Scenes
bool shared = false;
if (mod != null)
{
if (mod is IRegionModule)
{
IRegionModule module = (IRegionModule)mod;
shared = module.IsSharedModule;
}
else if (mod is IRegionModuleBase)
{
shared = mod is ISharedRegionModule;
}
else
{
throw new Exception("AddCommand module parameter must be IRegionModule or IRegionModuleBase");
}
}
if (module != null)
shared = module is ISharedRegionModule;
MainConsole.Instance.Commands.AddCommand(
category, shared, command, shorthelp, longhelp, descriptivehelp, callback);

View File

@ -144,22 +144,6 @@ namespace OpenSim.Region.Framework.Scenes
// collect known shared modules in sharedModules
Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>();
lock (m_localScenes)
{
for (int i = 0; i < m_localScenes.Count; i++)
{
// extract known shared modules from scene
foreach (string k in m_localScenes[i].Modules.Keys)
{
if (m_localScenes[i].Modules[k].IsSharedModule &&
!sharedModules.ContainsKey(k))
sharedModules[k] = m_localScenes[i].Modules[k];
}
// close scene/region
m_localScenes[i].Close();
}
}
// all regions/scenes are now closed, we can now safely
// close all shared modules
foreach (IRegionModule mod in sharedModules.Values)

View File

@ -139,7 +139,7 @@ namespace OpenSim.Tests.Common
SceneCommunicationService scs = new SceneCommunicationService();
TestScene testScene = new TestScene(
regInfo, m_acm, scs, m_simDataService, m_estateDataService, null, false, configSource, null);
regInfo, m_acm, scs, m_simDataService, m_estateDataService, false, configSource, null);
INonSharedRegionModule godsModule = new GodsModule();
godsModule.Initialise(new IniConfigSource());

View File

@ -41,9 +41,9 @@ namespace OpenSim.Tests.Common.Mock
public TestScene(
RegionInfo regInfo, AgentCircuitManager authen,
SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService,
ModuleLoader moduleLoader, bool dumpAssetsToFile,
bool dumpAssetsToFile,
IConfigSource config, string simulatorVersion)
: base(regInfo, authen, sceneGridService, simDataService, estateDataService, moduleLoader,
: base(regInfo, authen, sceneGridService, simDataService, estateDataService,
dumpAssetsToFile, config, simulatorVersion)
{
}
@ -73,4 +73,4 @@ namespace OpenSim.Tests.Common.Mock
get { return m_asyncSceneObjectDeleter; }
}
}
}
}