diff --git a/src/Vlingo.Xoom.Actors/IMailboxConfiguration.cs b/src/Vlingo.Xoom.Actors/IMailboxConfiguration.cs index c66b7c0..294a809 100644 --- a/src/Vlingo.Xoom.Actors/IMailboxConfiguration.cs +++ b/src/Vlingo.Xoom.Actors/IMailboxConfiguration.cs @@ -6,6 +6,10 @@ // one at https://mozilla.org/MPL/2.0/. using System.Globalization; +using Vlingo.Xoom.Actors.Plugin; +using Vlingo.Xoom.Actors.Plugin.Mailbox.AgronaMPSCArrayQueue; +using Vlingo.Xoom.Actors.Plugin.Mailbox.ConcurrentQueue; +using Vlingo.Xoom.Actors.Plugin.Mailbox.SharedRingBuffer; namespace Vlingo.Xoom.Actors; @@ -24,6 +28,20 @@ public interface IMailboxConfiguration static IConcurrentQueueConfiguration ConcurrentQueueConfiguration() => new BasicConcurrentQueueConfiguration(); static ISharedRingBufferConfiguration SharedRingBufferConfiguration() => new BasicSharedRingBufferConfiguration(); + + Configuration Configuration { get; } + + string MailboxName { get; } + + bool IsDefaultMailbox { get; } + + IMailboxProvider MailboxProvider { get; } + + IPlugin Plugin { get; } + + IPluginConfiguration PluginConfiguration { get; } + + PluginProperties PluginProperties { get; } } public interface IArrayQueueConfiguration : IMailboxConfiguration @@ -65,15 +83,21 @@ public interface ISharedRingBufferConfiguration : IMailboxConfiguration : IMailboxConfiguration { + private readonly Configuration _configuration; private bool _defaultMailbox; private string? _mailboxImplementationClassname; private string? _pluginName; - protected string? MailboxName; - + protected string? BaseMailboxName; + protected IPlugin? BasePlugin; + protected IPluginConfiguration? BasePluginConfiguration; + protected PluginProperties? BasePluginProperties; + + protected BaseMailboxConfiguration() => _configuration = Configuration.Define(); + public T WithMailboxName(string? mailboxName) { - MailboxName = mailboxName; + BaseMailboxName = mailboxName; return (T)(object) this; } @@ -96,6 +120,8 @@ public virtual Properties ToProperties() { var properties = new Properties(); + properties.SetProperty(PluginDeclaration(), "true"); + properties.SetProperty(BaseMailboxName!, _mailboxImplementationClassname); properties.SetProperty(PluginName(), "true"); properties.SetProperty(PluginName() + ".classname", _mailboxImplementationClassname); properties.SetProperty(PluginName() + ".defaultMailbox", _defaultMailbox.ToString()); @@ -103,15 +129,41 @@ public virtual Properties ToProperties() return properties; } + protected string PluginDeclaration() => "plugin.name." + BaseMailboxName; + + public Configuration Configuration => _configuration; + public string MailboxName => BaseMailboxName!; + public bool IsDefaultMailbox => _defaultMailbox; + public IMailboxProvider MailboxProvider => (IMailboxProvider)Plugin; + public abstract IPlugin Plugin { get; } + public abstract IPluginConfiguration PluginConfiguration { get; } + + public PluginProperties PluginProperties + { + get + { + if (BasePluginProperties == null) + { + BasePluginProperties = new PluginProperties(BaseMailboxName!, ToProperties()); + } + + return BasePluginProperties; + } + } + protected string PluginName() { if (_pluginName == null) { - _pluginName = "plugin.name." + MailboxName; + _pluginName = "plugin." + MailboxName; } return _pluginName; } + + protected TPc TypedPluginConfiguration() { + return (TPc) PluginConfiguration; + } } public class BasicArrayQueueConfiguration : BaseMailboxConfiguration, IArrayQueueConfiguration @@ -169,6 +221,32 @@ public override Properties ToProperties() return properties; } + + public override IPlugin Plugin + { + get + { + if (BasePlugin == null) + { + BasePlugin = new ManyToOneConcurrentArrayQueuePlugin(TypedPluginConfiguration()); + } + + return BasePlugin; + } + } + + public override IPluginConfiguration PluginConfiguration { + get + { + if (BasePluginConfiguration == null) + { + BasePluginConfiguration = ManyToOneConcurrentArrayQueuePluginConfiguration.Define(); + BasePluginConfiguration.BuildWith(Configuration, PluginProperties); + } + + return BasePluginConfiguration; + } + } } public class BasicConcurrentQueueConfiguration : BaseMailboxConfiguration, IConcurrentQueueConfiguration @@ -208,6 +286,32 @@ public override Properties ToProperties() return properties; } + + public override IPlugin Plugin + { + get + { + if (BasePlugin == null) + { + BasePlugin = new ConcurrentQueueMailboxPlugin(TypedPluginConfiguration()); + } + + return BasePlugin; + } + } + + public override IPluginConfiguration PluginConfiguration { + get + { + if (BasePluginConfiguration == null) + { + BasePluginConfiguration = ConcurrentQueueMailboxPluginConfiguration.Define(); + BasePluginConfiguration.BuildWith(Configuration, PluginProperties); + } + + return BasePluginConfiguration; + } + } } public class BasicSharedRingBufferConfiguration : BaseMailboxConfiguration, ISharedRingBufferConfiguration @@ -256,4 +360,30 @@ public override Properties ToProperties() return properties; } + + public override IPlugin Plugin + { + get + { + if (BasePlugin == null) + { + BasePlugin = new SharedRingBufferMailboxPlugin(TypedPluginConfiguration()); + } + + return BasePlugin; + } + } + + public override IPluginConfiguration PluginConfiguration { + get + { + if (BasePluginConfiguration == null) + { + BasePluginConfiguration = SharedRingBufferMailboxPluginConfiguration.Define(); + BasePluginConfiguration.BuildWith(Configuration, PluginProperties); + } + + return BasePluginConfiguration; + } + } } \ No newline at end of file diff --git a/src/Vlingo.Xoom.Actors/Plugin/Mailbox/AgronaMPSCArrayQueue/ManyToOneConcurrentArrayQueuePlugin.cs b/src/Vlingo.Xoom.Actors/Plugin/Mailbox/AgronaMPSCArrayQueue/ManyToOneConcurrentArrayQueuePlugin.cs index ead66cf..82c74ce 100644 --- a/src/Vlingo.Xoom.Actors/Plugin/Mailbox/AgronaMPSCArrayQueue/ManyToOneConcurrentArrayQueuePlugin.cs +++ b/src/Vlingo.Xoom.Actors/Plugin/Mailbox/AgronaMPSCArrayQueue/ManyToOneConcurrentArrayQueuePlugin.cs @@ -16,7 +16,7 @@ public class ManyToOneConcurrentArrayQueuePlugin : AbstractPlugin, IMailboxProvi public ManyToOneConcurrentArrayQueuePlugin(string? name = null) => _configuration = ManyToOneConcurrentArrayQueuePluginConfiguration.Define(); - public ManyToOneConcurrentArrayQueuePlugin(IPluginConfiguration configuration) => + internal ManyToOneConcurrentArrayQueuePlugin(IPluginConfiguration configuration) => _configuration = (ManyToOneConcurrentArrayQueuePluginConfiguration)configuration; public override void Close() diff --git a/src/Vlingo.Xoom.Actors/Plugin/Mailbox/ConcurrentQueue/ConcurrentQueueMailboxPlugin.cs b/src/Vlingo.Xoom.Actors/Plugin/Mailbox/ConcurrentQueue/ConcurrentQueueMailboxPlugin.cs index 2fe0222..c287400 100644 --- a/src/Vlingo.Xoom.Actors/Plugin/Mailbox/ConcurrentQueue/ConcurrentQueueMailboxPlugin.cs +++ b/src/Vlingo.Xoom.Actors/Plugin/Mailbox/ConcurrentQueue/ConcurrentQueueMailboxPlugin.cs @@ -16,7 +16,7 @@ public class ConcurrentQueueMailboxPlugin : AbstractPlugin, IMailboxProvider public ConcurrentQueueMailboxPlugin(string name) => _configuration = ConcurrentQueueMailboxPluginConfiguration.Define(name); - public ConcurrentQueueMailboxPlugin(IPluginConfiguration configuration) => _configuration = (ConcurrentQueueMailboxPluginConfiguration)configuration; + internal ConcurrentQueueMailboxPlugin(IPluginConfiguration configuration) => _configuration = (ConcurrentQueueMailboxPluginConfiguration)configuration; public override string Name => _configuration.Name; diff --git a/src/Vlingo.Xoom.Actors/Plugin/Mailbox/SharedRingBuffer/SharedRingBufferMailboxPlugin.cs b/src/Vlingo.Xoom.Actors/Plugin/Mailbox/SharedRingBuffer/SharedRingBufferMailboxPlugin.cs index 790c3c2..e1e19ec 100644 --- a/src/Vlingo.Xoom.Actors/Plugin/Mailbox/SharedRingBuffer/SharedRingBufferMailboxPlugin.cs +++ b/src/Vlingo.Xoom.Actors/Plugin/Mailbox/SharedRingBuffer/SharedRingBufferMailboxPlugin.cs @@ -22,7 +22,7 @@ public SharedRingBufferMailboxPlugin(string? name = null) _dispatchers = new ConcurrentDictionary(16, 1); } - public SharedRingBufferMailboxPlugin(IPluginConfiguration configuration) + internal SharedRingBufferMailboxPlugin(IPluginConfiguration configuration) { _configuration = (SharedRingBufferMailboxPluginConfiguration)configuration; _dispatchers = new ConcurrentDictionary(16, 1); diff --git a/src/Vlingo.Xoom.Actors/World.cs b/src/Vlingo.Xoom.Actors/World.cs index 7c8dd80..02185f9 100644 --- a/src/Vlingo.Xoom.Actors/World.cs +++ b/src/Vlingo.Xoom.Actors/World.cs @@ -406,7 +406,7 @@ public void RegisterMailboxProviderKeeper(IMailboxProviderKeeper keeper) /// The describing the mailbox type to register /// The type of the mailbox public void RegisterMailboxType(IMailboxConfiguration mailboxConfiguration) => - mailboxConfiguration.Plugin().Start(this); + mailboxConfiguration.Plugin.Start(this); /// /// Registers the dynamic with the key.