From e0e0db366061eae148364e3d5670f275b1ab25b7 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Fri, 18 Jul 2008 04:51:41 +0000 Subject: Thanks, sempuki, for a patch that moves all grid plugins to new PluginLoader (issue 1763). --- OpenSim/Data/GridDataBase.cs | 12 ++- OpenSim/Data/IGridData.cs | 45 ++++---- OpenSim/Data/ILogData.cs | 34 +++--- OpenSim/Data/MSSQL/MSSQLGridData.cs | 22 +++- OpenSim/Data/MSSQL/MSSQLLogData.cs | 30 ++++-- OpenSim/Data/MySQL/MySQLAssetData.cs | 1 + OpenSim/Data/MySQL/MySQLGridData.cs | 22 +++- OpenSim/Data/MySQL/MySQLLogData.cs | 26 +++-- OpenSim/Data/MySQL/MySQLManager.cs | 2 +- OpenSim/Data/SQLite/SQLiteGridData.cs | 25 ++++- OpenSim/Framework/PluginLoader.cs | 170 ++++++++++++++++++------------ OpenSim/Grid/GridServer/GridManager.cs | 120 +++++++++++---------- OpenSim/Grid/GridServer/GridServerBase.cs | 3 +- OpenSim/Grid/GridServer/IGridPlugin.cs | 3 +- OpenSim/Region/Application/OpenSimBase.cs | 3 +- 15 files changed, 310 insertions(+), 208 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/GridDataBase.cs b/OpenSim/Data/GridDataBase.cs index 0c9d24a..6480f84 100644 --- a/OpenSim/Data/GridDataBase.cs +++ b/OpenSim/Data/GridDataBase.cs @@ -29,19 +29,21 @@ using libsecondlife; namespace OpenSim.Data { - public abstract class GridDataBase : IGridData + public abstract class GridDataBase : IGridDataPlugin { public abstract RegionProfileData GetProfileByHandle(ulong regionHandle); public abstract RegionProfileData GetProfileByLLUUID(LLUUID UUID); public abstract RegionProfileData GetProfileByString(string regionName); public abstract RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax); public abstract bool AuthenticateSim(LLUUID UUID, ulong regionHandle, string simrecvkey); - public abstract void Initialise(string connect); - public abstract void Close(); - public abstract string getName(); - public abstract string getVersion(); public abstract DataResponse AddProfile(RegionProfileData profile); public abstract ReservationData GetReservationAtPoint(uint x, uint y); public abstract DataResponse UpdateProfile(RegionProfileData profile); + + public abstract void Initialise(); + public abstract void Initialise(string connect); + public abstract void Dispose(); + public abstract string Name { get; } + public abstract string Version { get; } } } diff --git a/OpenSim/Data/IGridData.cs b/OpenSim/Data/IGridData.cs index e242312..fa24d82 100644 --- a/OpenSim/Data/IGridData.cs +++ b/OpenSim/Data/IGridData.cs @@ -26,6 +26,10 @@ */ using libsecondlife; +using Mono.Addins; +using OpenSim.Framework; + +[assembly : AddinRoot("OpenSim.Data", "0.5")] namespace OpenSim.Data { @@ -40,9 +44,15 @@ namespace OpenSim.Data /// /// A standard grid interface /// - public interface IGridData + [TypeExtensionPoint("/OpenSim/GridDataStore")] + public interface IGridDataPlugin : IPlugin { /// + /// Initialises the interface + /// + void Initialise(string connect); + + /// /// Returns a sim profile from a regionHandle /// /// A 64bit Region Handle @@ -84,28 +94,6 @@ namespace OpenSim.Data bool AuthenticateSim(LLUUID UUID, ulong regionHandle, string simrecvkey); /// - /// Initialises the interface - /// - void Initialise(string connect); - - /// - /// Closes the interface - /// - void Close(); - - /// - /// The plugin being loaded - /// - /// A string containing the plugin name - string getName(); - - /// - /// The plugins version - /// - /// A string containing the plugin version - string getVersion(); - - /// /// Adds a new profile to the database /// /// The profile to add @@ -116,4 +104,15 @@ namespace OpenSim.Data ReservationData GetReservationAtPoint(uint x, uint y); } + + public class GridDataStoreInitialiser : PluginInitialiserBase + { + private string connect; + public GridDataStoreInitialiser (string s) { connect = s; } + public override void Initialise (IPlugin plugin) + { + IGridDataPlugin p = plugin as IGridDataPlugin; + p.Initialise (connect); + } + } } diff --git a/OpenSim/Data/ILogData.cs b/OpenSim/Data/ILogData.cs index 7275637..34657dc 100644 --- a/OpenSim/Data/ILogData.cs +++ b/OpenSim/Data/ILogData.cs @@ -25,6 +25,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using Mono.Addins; +using OpenSim.Framework; + namespace OpenSim.Data { /// @@ -61,7 +64,8 @@ namespace OpenSim.Data /// /// An interface to a LogData storage system /// - public interface ILogData + [TypeExtensionPoint("/OpenSim/GridLogData")] + public interface ILogDataPlugin : IPlugin { void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage); @@ -70,22 +74,16 @@ namespace OpenSim.Data /// Initialises the interface /// void Initialise(string connect); - - /// - /// Closes the interface - /// - void Close(); - - /// - /// The plugin being loaded - /// - /// A string containing the plugin name - string getName(); - - /// - /// The plugins version - /// - /// A string containing the plugin version - string getVersion(); + } + + public class LogDataInitialiser : PluginInitialiserBase + { + private string connect; + public LogDataInitialiser (string s) { connect = s; } + public override void Initialise (IPlugin plugin) + { + ILogDataPlugin p = plugin as ILogDataPlugin; + p.Initialise (connect); + } } } diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs index 0abd0d0..7de77d1 100644 --- a/OpenSim/Data/MSSQL/MSSQLGridData.cs +++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs @@ -33,12 +33,18 @@ using System.Security.Cryptography; using System.Text; using libsecondlife; using log4net; +using Mono.Addins; +using OpenSim.Framework; + +[assembly : Addin] +[assembly : AddinDependency("OpenSim.Data", "0.5")] namespace OpenSim.Data.MSSQL { /// /// A grid data interface for MSSQL Server /// + [Extension("/OpenSim/GridDataStore")] public class MSSQLGridData : GridDataBase { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -50,6 +56,12 @@ namespace OpenSim.Data.MSSQL private string m_regionsTableName; + override public void Initialise() + { + m_log.Info("[MSSQLGridData]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException (Name); + } + /// /// Initialises the Grid Interface /// @@ -101,7 +113,7 @@ namespace OpenSim.Data.MSSQL /// /// Shuts down the grid interface /// - override public void Close() + override public void Dispose() { // nothing to close } @@ -110,18 +122,18 @@ namespace OpenSim.Data.MSSQL /// The name of this DB provider. /// /// A string containing the storage system name - override public string getName() + override public string Name { - return "Sql OpenGridData"; + get { return "Sql OpenGridData"; } } /// /// Database provider version. /// /// A string containing the storage system version - override public string getVersion() + override public string Version { - return "0.1"; + get { return "0.1"; } } /// diff --git a/OpenSim/Data/MSSQL/MSSQLLogData.cs b/OpenSim/Data/MSSQL/MSSQLLogData.cs index 849d0fb..d0d81b6 100644 --- a/OpenSim/Data/MSSQL/MSSQLLogData.cs +++ b/OpenSim/Data/MSSQL/MSSQLLogData.cs @@ -25,21 +25,39 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; +using System.Reflection; using System.Collections.Generic; using System.Data; +using log4net; +using Mono.Addins; +using OpenSim.Framework; + +// Only one attribute per assembly. See: *GridData.cs +// [assembly : Addin] +// [assembly : AddinDependency("OpenSim.Data", "0.5")] namespace OpenSim.Data.MSSQL { /// /// An interface to the log database for MSSQL /// - internal class MSSQLLogData : ILogData + [Extension("/OpenSim/GridLogData")] + internal class MSSQLLogData : ILogDataPlugin { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// /// The database manager /// public MSSQLManager database; + public void Initialise() + { + m_log.Info("[MSSQLLogData]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException (Name); + } + /// /// Artificial constructor called when the plugin is loaded /// @@ -97,15 +115,15 @@ namespace OpenSim.Data.MSSQL /// Returns the name of this DB provider /// /// A string containing the DB provider name - public string getName() + public string Name { - return "MSSQL Logdata Interface"; + get { return "MSSQL Logdata Interface"; } } /// /// Closes the database provider /// - public void Close() + public void Dispose() { // Do nothing. } @@ -114,9 +132,9 @@ namespace OpenSim.Data.MSSQL /// Returns the version of this DB provider /// /// A string containing the provider version - public string getVersion() + public string Version { - return "0.1"; + get { return "0.1"; } } } } diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index 6cb0b4c..9284ba9 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs @@ -34,6 +34,7 @@ using log4net; using MySql.Data.MySqlClient; using OpenSim.Framework; + namespace OpenSim.Data.MySQL { /// diff --git a/OpenSim/Data/MySQL/MySQLGridData.cs b/OpenSim/Data/MySQL/MySQLGridData.cs index bb71c99..8142c74 100644 --- a/OpenSim/Data/MySQL/MySQLGridData.cs +++ b/OpenSim/Data/MySQL/MySQLGridData.cs @@ -33,12 +33,18 @@ using System.Security.Cryptography; using System.Text; using libsecondlife; using log4net; +using Mono.Addins; +using OpenSim.Framework; + +[assembly : Addin] +[assembly : AddinDependency("OpenSim.Data", "0.5")] namespace OpenSim.Data.MySQL { /// /// A MySQL Interface for the Grid Server /// + [Extension("/OpenSim/GridDataStore")] public class MySQLGridData : GridDataBase { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -48,6 +54,12 @@ namespace OpenSim.Data.MySQL /// private MySQLManager database; + override public void Initialise() + { + m_log.Info("[MySQLLogData]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException (Name); + } + /// /// Initialises Grid interface /// @@ -144,7 +156,7 @@ namespace OpenSim.Data.MySQL /// /// Shuts down the grid interface /// - override public void Close() + override public void Dispose() { database.Close(); } @@ -153,18 +165,18 @@ namespace OpenSim.Data.MySQL /// Returns the plugin name /// /// Plugin name - override public string getName() + override public string Name { - return "MySql OpenGridData"; + get { return "MySql OpenGridData"; } } /// /// Returns the plugin version /// /// Plugin version - override public string getVersion() + override public string Version { - return "0.1"; + get { return "0.1"; } } /// diff --git a/OpenSim/Data/MySQL/MySQLLogData.cs b/OpenSim/Data/MySQL/MySQLLogData.cs index fee7f2f..f11aec5 100644 --- a/OpenSim/Data/MySQL/MySQLLogData.cs +++ b/OpenSim/Data/MySQL/MySQLLogData.cs @@ -28,20 +28,34 @@ using System; using System.Reflection; using System.Collections.Generic; using log4net; +using Mono.Addins; +using OpenSim.Framework; + +// Only one attribute per assembly. See: *GridData.cs +// [assembly : Addin] +// [assembly : AddinDependency("OpenSim.Data", "0.5")] namespace OpenSim.Data.MySQL { /// /// An interface to the log database for MySQL /// - internal class MySQLLogData : ILogData + [Extension("/OpenSim/GridLogData")] + internal class MySQLLogData : ILogDataPlugin { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// /// The database manager /// public MySQLManager database; + public void Initialise() + { + m_log.Info("[MySQLLogData]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException (Name); + } + /// /// Artificial constructor called when the plugin is loaded /// Uses the obsolete mysql_connection.ini if connect string is empty. @@ -128,16 +142,16 @@ namespace OpenSim.Data.MySQL /// Returns the name of this DB provider /// /// A string containing the DB provider name - public string getName() + public string Name { - return "MySQL Logdata Interface"; + get { return "MySQL Logdata Interface";} } /// /// Closes the database provider /// /// do nothing - public void Close() + public void Dispose() { // Do nothing. } @@ -146,9 +160,9 @@ namespace OpenSim.Data.MySQL /// Returns the version of this DB provider /// /// A string containing the provider version - public string getVersion() + public string Version { - return "0.1"; + get { return "0.1"; } } } } diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs index cf4bce3..89d0672 100644 --- a/OpenSim/Data/MySQL/MySQLManager.cs +++ b/OpenSim/Data/MySQL/MySQLManager.cs @@ -227,7 +227,7 @@ namespace OpenSim.Data.MySQL return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, - dllVersion.Revision); + dllVersion.Revision); } /// diff --git a/OpenSim/Data/SQLite/SQLiteGridData.cs b/OpenSim/Data/SQLite/SQLiteGridData.cs index 6fd7235..1e07458 100644 --- a/OpenSim/Data/SQLite/SQLiteGridData.cs +++ b/OpenSim/Data/SQLite/SQLiteGridData.cs @@ -28,23 +28,38 @@ using System; using System.Collections.Generic; using System.Data; +using System.Reflection; using System.Security.Cryptography; using System.Text; using libsecondlife; +using log4net; +using Mono.Addins; using OpenSim.Framework; +[assembly : Addin] +[assembly : AddinDependency("OpenSim.Data", "0.5")] + namespace OpenSim.Data.SQLite { /// /// A Grid Interface to the SQLite database /// + [Extension("/OpenSim/GridDataStore")] public class SQLiteGridData : GridDataBase { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// /// SQLite database manager /// private SQLiteManager database; + override public void Initialise() + { + m_log.Info("[SQLite]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException (Name); + } + /// /// /// Initialises Inventory interface @@ -61,7 +76,7 @@ namespace OpenSim.Data.SQLite /// /// Shuts down the grid interface /// - override public void Close() + override public void Dispose() { database.Close(); } @@ -70,18 +85,18 @@ namespace OpenSim.Data.SQLite /// Returns the name of this grid interface /// /// A string containing the grid interface - override public string getName() + override public string Name { - return "SQLite OpenGridData"; + get { return "SQLite OpenGridData"; } } /// /// Returns the version of this grid interface /// /// A string containing the version - override public string getVersion() + override public string Version { - return "0.1"; + get { return "0.1"; } } /// diff --git a/OpenSim/Framework/PluginLoader.cs b/OpenSim/Framework/PluginLoader.cs index 9104958..2d61b2c 100644 --- a/OpenSim/Framework/PluginLoader.cs +++ b/OpenSim/Framework/PluginLoader.cs @@ -32,6 +32,7 @@ using System.Reflection; using log4net; using Mono.Addins; + namespace OpenSim.Framework { /// @@ -50,8 +51,17 @@ namespace OpenSim.Framework /// public interface IPluginConstraint { - bool Fail (string extpoint); string Message { get; } + bool Apply (string extpoint); + } + + /// + /// Classes wishing to select specific plugins from a range of possible options + /// must implement this class and pass it to PluginLoader Load() + /// + public interface IPluginFilter + { + bool Apply (ExtensionNode plugin); } /// @@ -64,18 +74,22 @@ namespace OpenSim.Framework private List loaded = new List(); private List extpoints = new List(); private PluginInitialiserBase initialiser; + private Dictionary constraints = new Dictionary(); - + + private Dictionary filters + = new Dictionary(); + private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - + public PluginInitialiserBase Initialiser { set { initialiser = value; } get { return initialiser; } } - + public List Plugins { get { return loaded; } @@ -84,25 +98,19 @@ namespace OpenSim.Framework public PluginLoader () { Initialiser = new PluginInitialiserBase(); + initialise_plugin_dir_ ("."); } public PluginLoader (PluginInitialiserBase init) { - Initialiser = init; + Initialiser = init; + initialise_plugin_dir_ ("."); } public PluginLoader (PluginInitialiserBase init, string dir) { - Initialiser = init; - AddPluginDir (dir); - } - - public void AddPluginDir (string dir) - { - suppress_console_output_ (true); - AddinManager.Initialize (dir); - AddinManager.Registry.Update (null); - suppress_console_output_ (false); + Initialiser = init; + initialise_plugin_dir_ (dir); } public void AddExtensionPoint (string extpoint) @@ -114,50 +122,88 @@ namespace OpenSim.Framework { constraints.Add (extpoint, cons); } - - public void Load (string extpoint, string dir) + + public void AddFilter (string extpoint, IPluginFilter filter) + { + filters.Add (extpoint, filter); + } + + public void Load (string extpoint) { - AddPluginDir (dir); AddExtensionPoint (extpoint); Load(); } public void Load () { - suppress_console_output_ (true); - AddinManager.Registry.Update (null); - suppress_console_output_ (false); - foreach (string ext in extpoints) { + log.Info("[PLUGINS]: Loading extension point " + ext); + if (constraints.ContainsKey (ext)) { IPluginConstraint cons = constraints [ext]; - if (cons.Fail (ext)) - throw new PluginConstraintViolatedException (cons.Message); + if (cons.Apply (ext)) + log.Error ("[PLUGINS]: " + ext + " failed constraint: " + cons.Message); } - ExtensionNodeList ns = AddinManager.GetExtensionNodes (ext); - foreach (TypeExtensionNode n in ns) - { - T p = (T) n.CreateInstance(); - Initialiser.Initialise (p); - Plugins.Add (p); + IPluginFilter filter = null; + + if (filters.ContainsKey (ext)) + filter = filters [ext]; - log.Info("[PLUGINS]: Loading plugin " + n.Path); + foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (ext)) + { + log.Info("[PLUGINS]: Trying plugin " + node.Path); + + if ((filter != null) && (filter.Apply (node) == false)) + continue; + + T plugin = (T) node.CreateInstance(); + Initialiser.Initialise (plugin); + Plugins.Add (plugin); } } } public void Dispose () { - foreach (T p in Plugins) - p.Dispose (); + foreach (T plugin in Plugins) + plugin.Dispose (); } - public void ClearCache() + private void initialise_plugin_dir_ (string dir) { - // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache + if (AddinManager.IsInitialized == true) + return; + + log.Info("[PLUGINS]: Initialzing"); + + AddinManager.AddinLoadError += on_addinloaderror_; + AddinManager.AddinLoaded += on_addinloaded_; + + clear_registry_(); + + suppress_console_output_ (true); + AddinManager.Initialize (dir); + AddinManager.Registry.Update (null); + suppress_console_output_ (false); + } + + private void on_addinloaded_(object sender, AddinEventArgs args) + { + log.Info ("[PLUGINS]: Plugin Loaded: " + args.AddinId); + } + + private void on_addinloaderror_(object sender, AddinErrorEventArgs args) + { + log.Error ("[PLUGINS]: Plugin Error: " + args.Message); + } + + private void clear_registry_ () + { + // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) + // occasionally seems to corrupt its addin cache // Hence, as a temporary solution we'll remove it before each startup if (Directory.Exists("addin-db-000")) Directory.Delete("addin-db-000", true); @@ -182,6 +228,9 @@ namespace OpenSim.Framework } } + /// + /// Constraint that bounds the number of plugins to be loaded. + /// public class PluginCountConstraint : IPluginConstraint { private int min; @@ -208,45 +257,32 @@ namespace OpenSim.Framework } } - public bool Fail (string extpoint) + public bool Apply (string extpoint) { - ExtensionNodeList ns = AddinManager.GetExtensionNodes (extpoint); - if ((ns.Count < min) || (ns.Count > max)) - return true; - else - return false; - } - } + int count = AddinManager.GetExtensionNodes (extpoint).Count; - public class PluginFilenameConstraint : IPluginConstraint - { - private string filename; + if ((count < min) || (count > max)) + throw new PluginConstraintViolatedException (Message); - public PluginFilenameConstraint (string name) - { - filename = name; - - } - - public string Message - { - get - { - return "The plugin must have the following name: " + filename; - } + return true; } + } + + /// + /// Filters out which plugin to load based on its "Id", which is name given by the namespace or by Mono.Addins. + /// + public class PluginIdFilter : IPluginFilter + { + private string id; - public bool Fail (string extpoint) + public PluginIdFilter (string id) { - ExtensionNodeList ns = AddinManager.GetExtensionNodes (extpoint); - if (ns.Count != 1) - return true; + this.id = id; + } - string[] path = ns[0].Path.Split('/'); - if (path [path.Length-1] == filename) - return false; - - return true; + public bool Apply (ExtensionNode plugin) + { + return (plugin.Id == id); } } } diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs index c539e66..ebc6ac3 100644 --- a/OpenSim/Grid/GridServer/GridManager.cs +++ b/OpenSim/Grid/GridServer/GridManager.cs @@ -26,6 +26,7 @@ */ using System; +using System.Text; using System.Collections; using System.Collections.Generic; using System.IO; @@ -46,8 +47,8 @@ namespace OpenSim.Grid.GridServer { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private Dictionary _plugins = new Dictionary(); - private Dictionary _logplugins = new Dictionary(); + private List _plugins = new List(); + private List _logplugins = new List(); // This is here so that the grid server can hand out MessageServer settings to regions on registration private List _MessageServers = new List(); @@ -57,42 +58,39 @@ namespace OpenSim.Grid.GridServer /// /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. /// - /// The filename to the grid server plugin DLL - public void AddPlugin(string FileName, string Connect) + /// The name of the grid server plugin DLL + public void AddPlugin(string provider, string connect) { - m_log.Info("[DATA]: Attempting to load " + FileName); - Assembly pluginAssembly = Assembly.LoadFrom(FileName); - - m_log.Info("[DATA]: Found " + pluginAssembly.GetTypes().Length + " interfaces."); - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (!pluginType.IsAbstract) - { - // Regions go here - Type typeInterface = pluginType.GetInterface("IGridData", true); - - if (typeInterface != null) - { - IGridData plug = - (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(Connect); - _plugins.Add(plug.getName(), plug); - m_log.Info("[DATA]: Added IGridData Interface"); - } - - // Logs go here - typeInterface = pluginType.GetInterface("ILogData", true); - - if (typeInterface != null) - { - ILogData plug = - (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(Connect); - _logplugins.Add(plug.getName(), plug); - m_log.Info("[DATA]: Added ILogData Interface"); - } - } - } + // FIXME: convert "provider" DLL file name to Mono.Addins "id", + // which unless it is changed in the source code, is the .NET namespace. + // In the future, the "provider" should be changed to "id" in the + // config files, and is independent of filenames or namespaces. + string[] s = provider.Split ('.'); + int len = s.Length; + if ((len >= 2) && (s [len-1] == "dll")) + s [len-1] = s [len-2]; + + provider = String.Join (".", s); + + PluginLoader gridloader = + new PluginLoader (new GridDataStoreInitialiser (connect)); + + PluginLoader logloader = + new PluginLoader (new LogDataInitialiser (connect)); + + gridloader.AddExtensionPoint ("/OpenSim/GridDataStore"); + logloader.AddExtensionPoint ("/OpenSim/GridLogData"); + + // loader will try to load all providers (MySQL, MSSQL, etc) + // unless it is constrainted to the correct "id" + gridloader.AddFilter ("/OpenSim/GridDataStore", new PluginIdFilter (provider + "GridData")); + logloader.AddFilter ("/OpenSim/GridLogData", new PluginIdFilter (provider + "LogData")); + + gridloader.Load(); + logloader.Load(); + + _plugins = gridloader.Plugins; + _logplugins = logloader.Plugins; } /// @@ -105,15 +103,15 @@ namespace OpenSim.Grid.GridServer /// The message to log private void logToDB(string target, string method, string args, int priority, string message) { - foreach (KeyValuePair kvp in _logplugins) + foreach (ILogDataPlugin plugin in _logplugins) { try { - kvp.Value.saveLog("Gridserver", target, method, args, priority, message); + plugin.saveLog("Gridserver", target, method, args, priority, message); } catch (Exception) { - m_log.Warn("[storage]: Unable to write log via " + kvp.Key); + m_log.Warn("[storage]: Unable to write log via "); } } } @@ -125,11 +123,11 @@ namespace OpenSim.Grid.GridServer /// A SimProfileData for the region public RegionProfileData GetRegion(LLUUID uuid) { - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { try { - return kvp.Value.GetProfileByLLUUID(uuid); + return plugin.GetProfileByLLUUID(uuid); } catch (Exception e) { @@ -146,15 +144,15 @@ namespace OpenSim.Grid.GridServer /// A SimProfileData for the region public RegionProfileData GetRegion(ulong handle) { - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { try { - return kvp.Value.GetProfileByHandle(handle); + return plugin.GetProfileByHandle(handle); } catch { - m_log.Warn("[storage]: Unable to find region " + handle.ToString() + " via " + kvp.Key); + m_log.Warn("[storage]: Unable to find region " + handle.ToString() + " via " + plugin.Name); } } return null; @@ -167,15 +165,15 @@ namespace OpenSim.Grid.GridServer /// A SimProfileData for the region public RegionProfileData GetRegion(string regionName) { - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { try { - return kvp.Value.GetProfileByString(regionName); + return plugin.GetProfileByString(regionName); } catch { - m_log.Warn("[storage]: Unable to find region " + regionName + " via " + kvp.Key); + m_log.Warn("[storage]: Unable to find region " + regionName + " via " + plugin.Name); } } return null; @@ -185,11 +183,11 @@ namespace OpenSim.Grid.GridServer { Dictionary regions = new Dictionary(); - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { try { - RegionProfileData[] neighbours = kvp.Value.GetProfilesInRange(xmin, ymin, xmax, ymax); + RegionProfileData[] neighbours = plugin.GetProfilesInRange(xmin, ymin, xmax, ymax); foreach (RegionProfileData neighbour in neighbours) { regions[neighbour.regionHandle] = neighbour; @@ -197,7 +195,7 @@ namespace OpenSim.Grid.GridServer } catch { - m_log.Warn("[storage]: Unable to query regionblock via " + kvp.Key); + m_log.Warn("[storage]: Unable to query regionblock via " + plugin.Name); } } @@ -404,7 +402,7 @@ namespace OpenSim.Grid.GridServer return e.XmlRpcErrorResponse; } - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { try { @@ -412,11 +410,11 @@ namespace OpenSim.Grid.GridServer if (existingSim == null) { - insertResponse = kvp.Value.AddProfile(sim); + insertResponse = plugin.AddProfile(sim); } else { - insertResponse = kvp.Value.UpdateProfile(sim); + insertResponse = plugin.UpdateProfile(sim); } switch (insertResponse) @@ -441,7 +439,7 @@ namespace OpenSim.Grid.GridServer catch (Exception e) { m_log.Warn("[LOGIN END]: " + - "Unable to login region " + sim.UUID.ToString() + " via " + kvp.Key); + "Unable to login region " + sim.UUID.ToString() + " via " + plugin.Name); m_log.Warn("[LOGIN END]: " + e.ToString()); } } @@ -682,12 +680,12 @@ namespace OpenSim.Grid.GridServer return response; } - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { //OpenSim.Data.MySQL.MySQLGridData dbengine = new OpenSim.Data.MySQL.MySQLGridData(); try { - MySQLGridData mysqldata = (MySQLGridData)(kvp.Value); + MySQLGridData mysqldata = (MySQLGridData)(plugin); //DataResponse insertResponse = mysqldata.DeleteProfile(TheSim); DataResponse insertResponse = mysqldata.DeleteProfile(uuid); switch (insertResponse) @@ -1053,17 +1051,17 @@ namespace OpenSim.Grid.GridServer m_log.Info("[DATA]: " + "Updating / adding via " + _plugins.Count + " storage provider(s) registered."); - foreach (KeyValuePair kvp in _plugins) + foreach (IGridDataPlugin plugin in _plugins) { try { //Check reservations ReservationData reserveData = - kvp.Value.GetReservationAtPoint(theSim.regionLocX, theSim.regionLocY); + plugin.GetReservationAtPoint(theSim.regionLocX, theSim.regionLocY); if ((reserveData != null && reserveData.gridRecvKey == theSim.regionRecvKey) || (reserveData == null && authkeynode.InnerText != theSim.regionRecvKey)) { - kvp.Value.AddProfile(theSim); + plugin.AddProfile(theSim); m_log.Info("[grid]: New sim added to grid (" + theSim.regionName + ")"); logToDB(theSim.UUID.ToString(), "RestSetSimMethod", String.Empty, 5, "Region successfully updated and connected to grid."); @@ -1078,7 +1076,7 @@ namespace OpenSim.Grid.GridServer } catch (Exception e) { - m_log.Warn("[GRID]: GetRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + + m_log.Warn("[GRID]: GetRegionPlugin Handle " + plugin.Name + " unable to add new sim: " + e.ToString()); } } diff --git a/OpenSim/Grid/GridServer/GridServerBase.cs b/OpenSim/Grid/GridServer/GridServerBase.cs index 3cd7489..a8ebd27 100644 --- a/OpenSim/Grid/GridServer/GridServerBase.cs +++ b/OpenSim/Grid/GridServer/GridServerBase.cs @@ -31,7 +31,6 @@ using System.IO; using System.Reflection; using System.Timers; using log4net; -using Mono.Addins; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Framework.Servers; @@ -121,7 +120,7 @@ namespace OpenSim.Grid.GridServer PluginLoader loader = new PluginLoader (new GridPluginInitialiser (this)); - loader.Load ("/OpenSim/GridServer", "."); + loader.Load ("/OpenSim/GridServer"); m_plugins = loader.Plugins; } diff --git a/OpenSim/Grid/GridServer/IGridPlugin.cs b/OpenSim/Grid/GridServer/IGridPlugin.cs index 6593962..418caec 100644 --- a/OpenSim/Grid/GridServer/IGridPlugin.cs +++ b/OpenSim/Grid/GridServer/IGridPlugin.cs @@ -29,7 +29,7 @@ using Mono.Addins; using OpenSim.Framework; -[assembly : AddinRoot("OpenSim", "0.5")] +[assembly : AddinRoot("OpenSim.Grid.GridServer", "0.5")] namespace OpenSim.Grid.GridServer { @@ -37,7 +37,6 @@ namespace OpenSim.Grid.GridServer public interface IGridPlugin : IPlugin { void Initialise(GridServerBase gridServer); - void Close(); } public class GridPluginInitialiser : PluginInitialiserBase diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 380df73..910ec55 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -34,7 +34,6 @@ using System.Text; using System.Threading; using libsecondlife; using log4net; -using Mono.Addins; using Nini.Config; using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; @@ -338,7 +337,7 @@ namespace OpenSim PluginLoader loader = new PluginLoader (new ApplicationPluginInitialiser (this)); - loader.Load ("/OpenSim/Startup", "."); + loader.Load ("/OpenSim/Startup"); m_plugins = loader.Plugins; } -- cgit v1.1