Example #1
0
        /// <summary>
        /// Construct a work pool with an internal <see cref="RingBuffer{T}"/> for convenience.
        ///
        /// This option does not require <see cref="Sequencer.SetGatingSequences"/> to be called before the work pool is started.
        /// </summary>
        /// <param name="eventFactory">eventFactory for filling the <see cref="RingBuffer{T}"/></param>
        /// <param name="exceptionHandler">exceptionHandler to callback when an error occurs which is not handled by the <see cref="IWorkHandler{T}"/>s.</param>
        /// <param name="workHandlers">workHandlers to distribute the work load across.</param>
        public WorkerPool(Func <T> eventFactory,
                          IExceptionHandler <T> exceptionHandler,
                          params IWorkHandler <T>[] workHandlers)

        {
            _ringBuffer = RingBuffer <T> .CreateMultiProducer(eventFactory, 1024, new BlockingWaitStrategy());

            var barrier = _ringBuffer.NewBarrier();

            _workProcessors = new WorkProcessor <T> [workHandlers.Length];

            for (var i = 0; i < workHandlers.Length; i++)
            {
                _workProcessors[i] = new WorkProcessor <T>(_ringBuffer,
                                                           barrier,
                                                           workHandlers[i],
                                                           exceptionHandler,
                                                           _workSequence);
            }

            _ringBuffer.AddGatingSequences(GetWorkerSequences());
        }
        /// <summary>
        /// Construct a work pool with an internal {@link RingBuffer} for convenience.
        /// This option does not require {@link RingBuffer#AddGatingSequences(Sequence...)} to be called before the work pool is started.
        /// </summary>
        /// <param name="eventFactory">for filling the {@link RingBuffer}</param>
        /// <param name="exceptionHandler">to callback when an error occurs which is not handled by the {@link WorkHandler}s.</param>
        /// <param name="workHandlers">to distribute the work load across.</param>
        public WorkerPool(Func <T> eventFactory,
                          IExceptionHandler exceptionHandler,
                          params IWorkHandler <T>[] workHandlers)
        {
            ringBuffer = RingBuffer <T> .CreateMultiProducer(eventFactory, 1024, new BlockingWaitStrategy());

            ISequenceBarrier barrier = ringBuffer.NewBarrier();
            var numWorkers           = workHandlers.Length;

            workProcessors = new WorkProcessor <T> [numWorkers];

            for (var i = 0; i < numWorkers; i++)
            {
                workProcessors[i] = new WorkProcessor <T>(ringBuffer,
                                                          barrier,
                                                          workHandlers[i],
                                                          exceptionHandler,
                                                          workSequence);
            }

            ringBuffer.AddGatingSequences(getWorkerSequences());
        }
Example #3
0
        /// <summary>
        /// Construct a work pool with an internal <see cref="RingBuffer{T}"/> for convenience.
        ///
        /// This option does not require <see cref="Sequencer.SetGatingSequences"/> to be called before the work pool is started.
        /// </summary>
        /// <param name="eventFactory">eventFactory for filling the <see cref="RingBuffer{T}"/></param>
        /// <param name="claimStrategy">claimStrategy for the <see cref="RingBuffer{T}"/></param>
        /// <param name="waitStrategy">waitStrategy for the <see cref="RingBuffer{T}"/></param>
        /// <param name="exceptionHandler">exceptionHandler to callback when an error occurs which is not handled by the <see cref="IWorkHandler{T}"/>s.</param>
        /// <param name="workHandlers">workHandlers to distribute the work load across.</param>
        public WorkerPool(Func <T> eventFactory,
                          IClaimStrategy claimStrategy,
                          IWaitStrategy waitStrategy,
                          IExceptionHandler exceptionHandler,
                          params IWorkHandler <T>[] workHandlers)

        {
            _ringBuffer = new RingBuffer <T>(eventFactory, claimStrategy, waitStrategy);
            var barrier    = _ringBuffer.NewBarrier();
            int numWorkers = workHandlers.Length;

            _workProcessors = new WorkProcessor <T> [numWorkers];

            for (int i = 0; i < numWorkers; i++)
            {
                _workProcessors[i] = new WorkProcessor <T>(_ringBuffer,
                                                           barrier,
                                                           workHandlers[i],
                                                           exceptionHandler,
                                                           _workSequence);
            }

            _ringBuffer.SetGatingSequences(WorkerSequences);
        }