Commit 2825ccea authored by Savorboard's avatar Savorboard

rename namespace.

parent 6e6812a5
......@@ -2,9 +2,10 @@
using System.Collections.Generic;
using System.Text;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public interface IAdditionalProcessor : IJobProcessor
{
}
}
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public class InfiniteRetryProcessor : IJobProcessor
{
......@@ -24,7 +23,6 @@ namespace DotNetCore.CAP.Job
{
while (!context.IsStopping)
{
Debug.WriteLine("InfiniteRetryProcessor在开线程:" + _inner.ToString() + " : " + DateTime.Now);
try
{
await _inner.ProcessAsync(context);
......@@ -35,10 +33,7 @@ namespace DotNetCore.CAP.Job
}
catch (Exception ex)
{
_logger.LogWarning(
1,
ex,
"Prcessor '{ProcessorName}' failed. Retrying...", _inner.ToString());
_logger.LogWarning(1, ex, "Prcessor '{ProcessorName}' failed. Retrying...", _inner.ToString());
}
}
}
......
......@@ -6,7 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public class DefaultMessageJobProcessor : IMessageJobProcessor
{
......
......@@ -2,15 +2,15 @@
using System.Threading;
using System.Threading.Tasks;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Job.States;
using DotNetCore.CAP.Processor.States;
using DotNetCore.CAP.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public class JobQueuer : IJobProcessor
public class PublishQueuer : IJobProcessor
{
private ILogger _logger;
private CapOptions _options;
......@@ -18,8 +18,10 @@ namespace DotNetCore.CAP.Job
private IServiceProvider _provider;
private TimeSpan _pollingDelay;
public JobQueuer(
ILogger<JobQueuer> logger,
internal static readonly AutoResetEvent PulseEvent = new AutoResetEvent(true);
public PublishQueuer(
ILogger<PublishQueuer> logger,
IOptions<CapOptions> options,
IStateChanger stateChanger,
IServiceProvider provider)
......@@ -57,8 +59,9 @@ namespace DotNetCore.CAP.Job
context.ThrowIfStopping();
WaitHandleEx.SentPulseEvent.Set();
await WaitHandleEx.WaitAnyAsync(WaitHandleEx.QueuePulseEvent,
DefaultMessageJobProcessor.PulseEvent.Set();
await WaitHandleEx.WaitAnyAsync(PulseEvent,
context.CancellationToken.WaitHandle, _pollingDelay);
}
}
......
using System;
using System.Threading;
using System.Threading.Tasks;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Processor.States;
using DotNetCore.CAP.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace DotNetCore.CAP.Processor
{
public class SubscribeQueuer : IJobProcessor
{
private ILogger _logger;
private CapOptions _options;
private IStateChanger _stateChanger;
private IServiceProvider _provider;
private TimeSpan _pollingDelay;
internal static readonly AutoResetEvent PulseEvent = new AutoResetEvent(true);
public SubscribeQueuer(
ILogger<SubscribeQueuer> logger,
IOptions<CapOptions> options,
IStateChanger stateChanger,
IServiceProvider provider)
{
_logger = logger;
_options = options.Value;
_stateChanger = stateChanger;
_provider = provider;
_pollingDelay = TimeSpan.FromSeconds(_options.PollingDelay);
}
public async Task ProcessAsync(ProcessingContext context)
{
using (var scope = _provider.CreateScope())
{
CapReceivedMessage message;
var provider = scope.ServiceProvider;
var connection = provider.GetRequiredService<IStorageConnection>();
while (
!context.IsStopping &&
(message = await connection.GetNextReceviedMessageToBeEnqueuedAsync()) != null)
{
var state = new EnqueuedState();
using (var transaction = connection.CreateTransaction())
{
_stateChanger.ChangeState(message, state, transaction);
await transaction.CommitAsync();
}
}
}
context.ThrowIfStopping();
DefaultMessageJobProcessor.PulseEvent.Set();
await WaitHandleEx.WaitAnyAsync(PulseEvent,
context.CancellationToken.WaitHandle, _pollingDelay);
}
}
}
using System.Threading.Tasks;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public interface IJobProcessor
{
......
......@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public interface IMessageJobProcessor : IJobProcessor
{
......
......@@ -3,14 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DotNetCore.CAP.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public class JobProcessingServer : IProcessingServer, IDisposable
public class CapProcessingServer : IProcessingServer, IDisposable
{
private readonly ILogger _logger;
private readonly ILoggerFactory _loggerFactory;
......@@ -19,13 +18,13 @@ namespace DotNetCore.CAP.Job
private readonly CapOptions _options;
private IJobProcessor[] _processors;
private IMessageJobProcessor[] _messageProcessors;
private IList<IMessageJobProcessor> _messageProcessors;
private ProcessingContext _context;
private Task _compositeTask;
private bool _disposed;
public JobProcessingServer(
ILogger<JobProcessingServer> logger,
public CapProcessingServer(
ILogger<CapProcessingServer> logger,
ILoggerFactory loggerFactory,
IServiceProvider provider,
IOptions<CapOptions> options)
......@@ -40,9 +39,8 @@ namespace DotNetCore.CAP.Job
public void Start()
{
var processorCount = Environment.ProcessorCount;
processorCount = 1;
_processors = GetProcessors(processorCount);
_logger.ServerStarting(processorCount, processorCount);
_logger.ServerStarting(processorCount, _processors.Length);
_context = new ProcessingContext(_provider, _cts.Token);
......@@ -62,19 +60,8 @@ namespace DotNetCore.CAP.Job
_logger.LogTrace("Pulsing the JobQueuer.");
WaitHandleEx.QueuePulseEvent.Set();
}
private bool AllProcessorsWaiting()
{
foreach (var processor in _messageProcessors)
{
if (!processor.Waiting)
{
return false;
}
}
return true;
PublishQueuer.PulseEvent.Set();
SubscribeQueuer.PulseEvent.Set();
}
public void Dispose()
......@@ -101,6 +88,18 @@ namespace DotNetCore.CAP.Job
}
}
private bool AllProcessorsWaiting()
{
foreach (var processor in _messageProcessors)
{
if (!processor.Waiting)
{
return false;
}
}
return true;
}
private IJobProcessor InfiniteRetry(IJobProcessor inner)
{
return new InfiniteRetryProcessor(inner, _loggerFactory);
......@@ -111,13 +110,15 @@ namespace DotNetCore.CAP.Job
var returnedProcessors = new List<IJobProcessor>();
for (int i = 0; i < processorCount; i++)
{
var messageProcessors = _provider.GetServices<IMessageJobProcessor>();
_messageProcessors = messageProcessors.ToArray();
returnedProcessors.AddRange(messageProcessors);
var messageProcessors = _provider.GetService<IMessageJobProcessor>();
_messageProcessors.Add(messageProcessors);
}
returnedProcessors.AddRange(_messageProcessors);
returnedProcessors.Add(_provider.GetService<PublishQueuer>());
returnedProcessors.Add(_provider.GetService<SubscribeQueuer>());
returnedProcessors.Add(_provider.GetService<JobQueuer>());
//returnedProcessors.Add(_provider.GetService<IAdditionalProcessor>());
returnedProcessors.Add(_provider.GetService<IAdditionalProcessor>());
return returnedProcessors.ToArray();
}
......
......@@ -3,7 +3,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public class ProcessingContext : IDisposable
{
......
using System;
namespace DotNetCore.CAP.Job
namespace DotNetCore.CAP.Processor
{
public class RetryBehavior
{
......
using System;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public class EnqueuedState : IState
{
......
using System;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public class FailedState : IState
{
......
using System;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public class ProcessingState : IState
{
......
using System;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public class ScheduledState : IState
{
......
using System;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public class SucceededState : IState
{
......
using System;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public interface IState
{
......
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public class StateChanger : IStateChanger
{
......
using System.Threading.Tasks;
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public static class StateChangerExtensions
{
......
using DotNetCore.CAP.Models;
namespace DotNetCore.CAP.Job.States
namespace DotNetCore.CAP.Processor.States
{
public interface IStateChanger
{
......
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