From 9765e35c9fafa7854043741ee038ff166ec11f16 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Tue, 20 Jun 2017 16:04:32 +0800 Subject: [PATCH] Rename class. --- .../Consumer/IConsumerHandler.cs | 3 +- ...apper.Base.cs => IBootstrapper.Default.cs} | 33 +++++++++++++------ .../{ITopicServer.cs => IProcessingServer.cs} | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) rename src/Cap.Consistency/{IBootstrapper.Base.cs => IBootstrapper.Default.cs} (68%) rename src/Cap.Consistency/{ITopicServer.cs => IProcessingServer.cs} (75%) diff --git a/src/Cap.Consistency/Consumer/IConsumerHandler.cs b/src/Cap.Consistency/Consumer/IConsumerHandler.cs index f5380ad..5ada307 100644 --- a/src/Cap.Consistency/Consumer/IConsumerHandler.cs +++ b/src/Cap.Consistency/Consumer/IConsumerHandler.cs @@ -1,6 +1,7 @@ namespace Cap.Consistency.Consumer { - public interface IConsumerHandler : ITopicServer + public interface IConsumerHandler : IProcessingServer { + } } \ No newline at end of file diff --git a/src/Cap.Consistency/IBootstrapper.Base.cs b/src/Cap.Consistency/IBootstrapper.Default.cs similarity index 68% rename from src/Cap.Consistency/IBootstrapper.Base.cs rename to src/Cap.Consistency/IBootstrapper.Default.cs index 36e7949..81b3f82 100644 --- a/src/Cap.Consistency/IBootstrapper.Base.cs +++ b/src/Cap.Consistency/IBootstrapper.Default.cs @@ -1,31 +1,34 @@ using System; +using System.Linq; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Cap.Consistency.Infrastructure; using Cap.Consistency.Store; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace Cap.Consistency { - public abstract class BootstrapperBase : IBootstrapper + public class DefaultBootstrapper : IBootstrapper { private IApplicationLifetime _appLifetime; private CancellationTokenSource _cts; private CancellationTokenRegistration _ctsRegistration; private Task _bootstrappingTask; - public BootstrapperBase( - ConsistencyOptions options, + public DefaultBootstrapper( + IOptions options, ConsistencyMessageManager storage, - ITopicServer server, IApplicationLifetime appLifetime, IServiceProvider provider) { - Options = options; + + Options = options.Value; Storage = storage; - Server = server; _appLifetime = appLifetime; Provider = provider; - + Servers = Provider.GetServices(); _cts = new CancellationTokenSource(); _ctsRegistration = appLifetime.ApplicationStopping.Register(() => { _cts.Cancel(); @@ -41,7 +44,7 @@ namespace Cap.Consistency protected ConsistencyMessageManager Storage { get; } - protected ITopicServer Server { get; } + protected IEnumerable Servers { get; } public IServiceProvider Provider { get; private set; } @@ -57,14 +60,24 @@ namespace Cap.Consistency await BootstrapCoreAsync(); if (_cts.IsCancellationRequested) return; - Server.Start(); + foreach (var item in Servers) { + try { + item.Start(); + } + catch (Exception) { + } + } _ctsRegistration.Dispose(); _cts.Dispose(); } public virtual Task BootstrapCoreAsync() { - _appLifetime.ApplicationStopping.Register(() => Server.Dispose()); + _appLifetime.ApplicationStopping.Register(() => { + foreach (var item in Servers) { + item.Dispose(); + } + }); return Task.FromResult(0); } } diff --git a/src/Cap.Consistency/ITopicServer.cs b/src/Cap.Consistency/IProcessingServer.cs similarity index 75% rename from src/Cap.Consistency/ITopicServer.cs rename to src/Cap.Consistency/IProcessingServer.cs index ae38fa0..2a9e9f3 100644 --- a/src/Cap.Consistency/ITopicServer.cs +++ b/src/Cap.Consistency/IProcessingServer.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace Cap.Consistency { - public interface ITopicServer : IDisposable + public interface IProcessingServer : IDisposable { void Start(); }