Gracefully shuts down a IWorker instance(s)
コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConsumerQueueAsync" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="workerFactory">The worker factory.</param>
        /// <param name="log">The log.</param>
        /// <param name="registerMessagesAsync">The register messages asynchronous.</param>
        /// <param name="stopWorker">The stop worker.</param>
        /// <param name="queueMonitor">The queue monitor.</param>
        public ConsumerQueueAsync(
            QueueConsumerConfiguration configuration,
            IPrimaryWorkerFactory workerFactory,
            ILogger log,
            IRegisterMessagesAsync registerMessagesAsync,
            StopWorker stopWorker,
            IQueueMonitor queueMonitor)
            : base(log)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => workerFactory, workerFactory);
            Guard.NotNull(() => log, log);
            Guard.NotNull(() => registerMessagesAsync, registerMessagesAsync);
            Guard.NotNull(() => stopWorker, stopWorker);
            Guard.NotNull(() => queueMonitor, queueMonitor);

            _configuration = configuration;
            _primaryWorker = new Lazy <IPrimaryWorker>(() =>
            {
                var worker              = workerFactory.Create();
                worker.UserException   += LogUserException;
                worker.SystemException += LogSystemException;
                return(worker);
            });

            _stopWorker            = stopWorker;
            _queueMonitor          = queueMonitor;
            _registerMessagesAsync = registerMessagesAsync;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkerCollection"/> class.
        /// </summary>
        /// <param name="workerConfiguration">The worker configuration.</param>
        /// <param name="workerFactory">The worker factory.</param>
        /// <param name="stopWorker">The stop worker.</param>
        /// <param name="log">The log.</param>
        /// <param name="workerPause">The worker pause.</param>
        public WorkerCollection(IWorkerConfiguration workerConfiguration,
                                IWorkerFactory workerFactory,
                                StopWorker stopWorker,
                                ILogFactory log,
                                IWorkerWaitForEventOrCancel workerPause)
        {
            Guard.NotNull(() => workerConfiguration, workerConfiguration);
            Guard.NotNull(() => workerFactory, workerFactory);
            Guard.NotNull(() => stopWorker, stopWorker);
            Guard.NotNull(() => log, log);
            Guard.NotNull(() => workerPause, workerPause);

            _workerConfiguration = workerConfiguration;
            _workerFactory       = workerFactory;
            _stopWorker          = stopWorker;
            _log         = log.Create();
            _workerPause = workerPause;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkerCollection"/> class.
        /// </summary>
        /// <param name="workerConfiguration">The worker configuration.</param>
        /// <param name="workerFactory">The worker factory.</param>
        /// <param name="stopWorker">The stop worker.</param>
        /// <param name="log">The log.</param>
        /// <param name="workerPause">The worker pause.</param>
        public WorkerCollection(IWorkerConfiguration workerConfiguration,
            IWorkerFactory workerFactory,
            StopWorker stopWorker,
            ILogFactory log,
            IWorkerWaitForEventOrCancel workerPause)
        {
            Guard.NotNull(() => workerConfiguration, workerConfiguration);
            Guard.NotNull(() => workerFactory, workerFactory);
            Guard.NotNull(() => stopWorker, stopWorker);
            Guard.NotNull(() => log, log);
            Guard.NotNull(() => workerPause, workerPause);

            _workerConfiguration = workerConfiguration;
            _workerFactory = workerFactory;
            _stopWorker = stopWorker;
            _log = log.Create();
            _workerPause = workerPause;
        }