From f4bec00057fb6987f4ea166347156e1abb985ec1 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 16 Feb 2009 12:20:31 +0000 Subject: From: Alan Webb The change makes two principal implementation changes: [1] It removes the hard coded set of possible asset server client implementations, allowing any arbitrary implementation that has been identified to the PluginLoader as an appropriate extension. The extension point for asset server client extension is /OpenSim/AssetServerClient. All of the old configuration rules have been preserved, and any of the legacy configuration values will still work as they did before, except the implementation is now loaded as a plug-in, rather than as a hard-coded instantiation of a specific class. The re-hashing of IAssetServer as an extension of IPlugin made upgrading of the implementation classes a necessity. Caveat: I have not been able to meaningfully test the crypto-grid clients. I believe they should work correctly, but the refactoring necessary to handle plug-in based initialization (vs constructor-based initialisation) admits the possibility of a problem. [2] The asset cache implementation, previously introduce as a hard-code class instantiation is now implemented as an IPlugin. Once again the previous (configurationless) behavior has been preserved. But now it is possible for those interested in experimenting with cache technologies to do so simply by introducing a new extension for the asset cache extension point (/OpenSim/AssetCache). I've tested all of the configuration settings, after applying the patch to a newly extracted tree, and they seem to work OK. --- .../Framework/Communications/Cache/AssetCache.cs | 80 ++++++++++++++++++---- .../Communications/Cache/AssetServerBase.cs | 55 +++++++++++++++ .../Communications/Cache/CryptoGridAssetClient.cs | 48 ++++++++++--- .../Communications/Cache/FileAssetClient.cs | 37 +++++++++- .../Communications/Cache/GridAssetClient.cs | 31 ++++++++- .../Communications/Cache/SQLAssetServer.cs | 29 ++++++++ .../Communications/Resources/AssetCache.addin.xml | 17 +++++ 7 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 OpenSim/Framework/Communications/Resources/AssetCache.addin.xml (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index 1c8f9d6..76c6045 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -48,8 +48,67 @@ namespace OpenSim.Framework.Communications.Cache /// sends packetised data directly back to the client. The only point where they meet is AssetReceived() and /// AssetNotFound(), which means they do share the same asset and texture caches.I agr - public class AssetCache : IAssetCache, IAssetReceiver + public class AssetCache : IAssetCache { + + #region IPlugin + + /// + /// The methods and properties in this section are needed to + /// support the IPlugin interface. They cann all be overridden + /// as needed by a derived class. + /// + + public virtual string Name + { + get { return "OpenSim.Framework.Communications.Cache.AssetCache"; } + } + + public virtual string Version + { + get { return "1.0"; } + } + + public virtual void Initialise() + { + m_log.Debug("[ASSET CACHE]: Asset cache null initialisation"); + } + + public virtual void Initialise(IAssetServer assetServer) + { + m_log.Debug("[ASSET CACHE]: Asset cache server-specified initialisation"); + m_log.InfoFormat("[ASSET CACHE]: Asset cache initialisation [{0}/{1}]", Name, Version); + + Initialize(); + + m_assetServer = assetServer; + m_assetServer.SetReceiver(this); + + Thread assetCacheThread = new Thread(RunAssetManager); + assetCacheThread.Name = "AssetCacheThread"; + assetCacheThread.IsBackground = true; + assetCacheThread.Start(); + ThreadTracker.Add(assetCacheThread); + + } + + public virtual void Initialise(ConfigSettings settings, IAssetServer assetServer) + { + m_log.Debug("[ASSET CACHE]: Asset cache configured initialisation"); + Initialise(assetServer); + } + + public AssetCache() + { + m_log.Debug("[ASSET CACHE]: Asset cache (plugin constructor)"); + } + + public void Dispose() + { + } + + #endregion + protected ICache m_memcache = new SimpleMemoryCache(); private static readonly ILog m_log @@ -83,7 +142,7 @@ namespace OpenSim.Framework.Communications.Cache /// /// The 'server' from which assets can be requested and to which assets are persisted. /// - private readonly IAssetServer m_assetServer; + private IAssetServer m_assetServer; public IAssetServer AssetServer { @@ -132,17 +191,8 @@ namespace OpenSim.Framework.Communications.Cache /// public AssetCache(IAssetServer assetServer) { - m_log.Info("[ASSET CACHE]: Creating Asset cache"); - Initialize(); - - m_assetServer = assetServer; - m_assetServer.SetReceiver(this); - - Thread assetCacheThread = new Thread(RunAssetManager); - assetCacheThread.Name = "AssetCacheThread"; - assetCacheThread.IsBackground = true; - assetCacheThread.Start(); - ThreadTracker.Add(assetCacheThread); + m_log.Info("[ASSET CACHE]: Asset cache direct constructor"); + Initialise(assetServer); } /// @@ -342,7 +392,7 @@ namespace OpenSim.Framework.Communications.Cache } // See IAssetReceiver - public void AssetReceived(AssetBase asset, bool IsTexture) + public virtual void AssetReceived(AssetBase asset, bool IsTexture) { AssetInfo assetInf = new AssetInfo(asset); @@ -393,7 +443,7 @@ namespace OpenSim.Framework.Communications.Cache } // See IAssetReceiver - public void AssetNotFound(UUID assetID, bool IsTexture) + public virtual void AssetNotFound(UUID assetID, bool IsTexture) { // m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetID); diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs index 5c902ec..7bb2ab9 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs @@ -46,6 +46,61 @@ namespace OpenSim.Framework.Communications.Cache protected Thread m_localAssetServerThread; protected IAssetDataPlugin m_assetProvider; + #region IPlugin + + /// + /// The methods and properties in this region are needed to implement + /// the IPlugin interface and its local extensions. + /// These can all be overridden as appropriate by a derived class. + /// These methods are only applicable when a class is loaded by the + /// IPlugin mechanism. + /// + /// Note that in the case of AssetServerBase, all initialization is + /// performed by the default constructor, so nothing additional is + /// required here. A derived class may wish to do more. + /// + + public virtual string Name + { + // get { return "OpenSim.Framework.Communications.Cache.AssetServerBase"; } + get { return "AssetServerBase"; } + } + + public virtual string Version + { + get { return "1.0"; } + } + + public virtual void Initialise() + { + m_log.Debug("[ASSET SERVER]: IPlugin null initialization"); + } + + public virtual void Initialise(ConfigSettings settings) + { + m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(1)"); + m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version); + } + + public virtual void Initialise(ConfigSettings settings, string p_url) + { + m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(2)"); + m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version); + } + + public virtual void Initialise(ConfigSettings settings, string p_url, string p_dir, bool p_t) + { + m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(3)"); + m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version); + } + + public virtual void Dispose() + { + m_log.Debug("[ASSET SERVER]: dispose"); + } + + #endregion + public IAssetDataPlugin AssetProviderPlugin { get { return m_assetProvider; } diff --git a/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs b/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs index 55db289..0f4e8ac 100644 --- a/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/CryptoGridAssetClient.cs @@ -44,9 +44,37 @@ namespace OpenSim.Framework.Communications.Cache { public class CryptoGridAssetClient : AssetServerBase { + + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private string _assetServerUrl; + private bool m_encryptOnUpload; + private RjinKeyfile m_encryptKey; + private readonly Dictionary m_keyfiles = new Dictionary(); + + #region IPlugin + + public override string Name + { + get { return "Crypto"; } + } + + public override string Version + { + get { return "1.0"; } + } + + public override void Initialise(ConfigSettings p_set, string p_url, string p_dir, bool p_t) + { + m_log.Debug("[CRYPTOGRID] Plugin configured initialisation"); + Initialise(p_url, p_dir, p_t); + } + + #endregion + #region Keyfile Classes [Serializable] - private class RjinKeyfile + public class RjinKeyfile { public string Secret; public string AlsoKnownAs; @@ -94,7 +122,7 @@ namespace OpenSim.Framework.Communications.Cache /// this may not be the most efficient way of handling encryption, so - as /// soon as you feel comfortable with it - you may want to redesign this class. /// - private class UtilRijndael + public class UtilRijndael { /// /// Encrypts specified plaintext using Rijndael symmetric key algorithm @@ -332,15 +360,19 @@ namespace OpenSim.Framework.Communications.Cache } #endregion - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private readonly string _assetServerUrl; - private readonly bool m_encryptOnUpload; - private readonly RjinKeyfile m_encryptKey; - private readonly Dictionary m_keyfiles = new Dictionary(); + public CryptoGridAssetClient() {} public CryptoGridAssetClient(string serverUrl, string keydir, bool decOnly) { + m_log.Debug("[CRYPTOGRID] Direct constructor"); + Initialise(serverUrl, keydir, decOnly); + } + + public void Initialise(string serverUrl, string keydir, bool decOnly) + { + + m_log.Debug("[CRYPTOGRID] Common constructor"); + _assetServerUrl = serverUrl; string[] keys = Directory.GetFiles(keydir, "*.deckey"); diff --git a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs b/OpenSim/Framework/Communications/Cache/FileAssetClient.cs index 9a60b53..e6574a1 100644 --- a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/FileAssetClient.cs @@ -26,16 +26,49 @@ */ using System.IO; +using System.Reflection; +using log4net; using System.Xml.Serialization; namespace OpenSim.Framework.Communications.Cache { public class FileAssetClient : AssetServerBase { - private readonly string m_dir; + + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + #region IPlugin + + public override string Name + { + get { return "File"; } + } + + public override string Version + { + get { return "1.0"; } + } + + public override void Initialise(ConfigSettings p_set, string p_url) + { + m_log.Debug("[FILEASSET] Plugin configured initialisation"); + Initialise(p_url); + } + + #endregion + + private string m_dir; private readonly XmlSerializer m_xs = new XmlSerializer(typeof(AssetBase)); - public FileAssetClient(string dir) + public FileAssetClient() {} + + public FileAssetClient(string p_url) + { + m_log.Debug("[FILEASSET] Direct constructor"); + Initialise(p_url); + } + + public void Initialise(string dir) { if (!Directory.Exists(dir)) { diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs index 1cc9833..6522ad0 100644 --- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs @@ -36,11 +36,40 @@ namespace OpenSim.Framework.Communications.Cache { public class GridAssetClient : AssetServerBase { + + #region IPlugin + + public override string Name + { + get { return "Grid"; } + } + + public override string Version + { + get { return "1.0"; } + } + + public override void Initialise(ConfigSettings p_set, string p_url) + { + m_log.Debug("[GRIDASSET] Plugin configured initialisation"); + Initialise(p_url); + } + + #endregion + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private string _assetServerUrl; - public GridAssetClient(string serverUrl) + public GridAssetClient() {} + + public GridAssetClient(string p_url) + { + m_log.Debug("[GRIDASSET] Direct constructor"); + Initialise(p_url); + } + + public void Initialise(string serverUrl) { _assetServerUrl = serverUrl; } diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs index 6266bf0..5274288 100644 --- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs @@ -34,10 +34,39 @@ namespace OpenSim.Framework.Communications.Cache { public class SQLAssetServer : AssetServerBase { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + #region IPlugin + + public override string Name + { + get { return "SQL"; } + } + + public override string Version + { + get { return "1.0"; } + } + + public override void Initialise(ConfigSettings p_set) + { + m_log.Debug("[SQLASSET] Plugin configured initialisation"); + Initialise(p_set.StandaloneAssetPlugin,p_set.StandaloneAssetSource); + } + + #endregion + + public SQLAssetServer() {} + public SQLAssetServer(string pluginName, string connect) { + m_log.Debug("[SQLASSET] Direct constructor"); + Initialise(pluginName, connect); + } + + public void Initialise(string pluginName, string connect) + { AddPlugin(pluginName, connect); } diff --git a/OpenSim/Framework/Communications/Resources/AssetCache.addin.xml b/OpenSim/Framework/Communications/Resources/AssetCache.addin.xml new file mode 100644 index 0000000..61a9f0f --- /dev/null +++ b/OpenSim/Framework/Communications/Resources/AssetCache.addin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + -- cgit v1.1