Commit 313b7844 authored by yangxiaodong's avatar yangxiaodong

Merge branch 'master' of https://github.com/yuleyule66/cap.git

parents 4d220d10 f6b6c12e
...@@ -18,16 +18,21 @@ namespace Cap.Consistency.Server ...@@ -18,16 +18,21 @@ namespace Cap.Consistency.Server
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IConsumer _consumer; private readonly IConsumer _consumer;
public ConsistencyServer(IOptions<ConsistencyServerOptions> options, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) { public ConsistencyServer(IOptions<ConsistencyServerOptions> options, IApplicationLifetime applicationLifetime,
if (options == null) { ILoggerFactory loggerFactory)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options)); throw new ArgumentNullException(nameof(options));
} }
if (applicationLifetime == null) { if (applicationLifetime == null)
{
throw new ArgumentNullException(nameof(applicationLifetime)); throw new ArgumentNullException(nameof(applicationLifetime));
} }
if (loggerFactory == null) { if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory)); throw new ArgumentNullException(nameof(loggerFactory));
} }
...@@ -41,8 +46,10 @@ namespace Cap.Consistency.Server ...@@ -41,8 +46,10 @@ namespace Cap.Consistency.Server
public IFeatureCollection Features { get; set; } public IFeatureCollection Features { get; set; }
public void Start<TContext>(IHttpApplication<TContext> application) { public void Start<TContext>(IHttpApplication<TContext> application)
if (_disposables != null) { {
if (_disposables != null)
{
// The server has already started and/or has not been cleaned up yet // The server has already started and/or has not been cleaned up yet
throw new InvalidOperationException("Server has already started."); throw new InvalidOperationException("Server has already started.");
} }
...@@ -55,23 +62,29 @@ namespace Cap.Consistency.Server ...@@ -55,23 +62,29 @@ namespace Cap.Consistency.Server
var threadCount = Options.ThreadCount; var threadCount = Options.ThreadCount;
if (threadCount <= 0) { if (threadCount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(threadCount), throw new ArgumentOutOfRangeException(nameof(threadCount),
threadCount, threadCount,
"ThreadCount must be positive."); "ThreadCount must be positive.");
} }
try { try
{
_consumer.Start(threadCount); _consumer.Start(threadCount);
} }
catch (Exception ex) { catch (Exception ex)
{
throw ex; throw ex;
} }
} }
public void Dispose() { public void Dispose()
if (_disposables != null) { {
while (_disposables.Count > 0) { if (_disposables != null)
{
while (_disposables.Count > 0)
{
_disposables.Pop().Dispose(); _disposables.Pop().Dispose();
} }
_disposables = null; _disposables = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment