/// <summary> /// Create a worker pool to enable an array of <see cref="IWorkHandler{T}"/>s to consume published sequences. /// /// This option requires a pre-configured <see cref="RingBuffer{T}"/> which must have <see cref="Sequencer.SetGatingSequences"/> /// called before the work pool is started. /// </summary> /// <param name="ringBuffer">ringBuffer of events to be consumed.</param> /// <param name="sequenceBarrier">sequenceBarrier on which the workers will depend.</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(RingBuffer <T> ringBuffer, ISequenceBarrier sequenceBarrier, IExceptionHandler <T> exceptionHandler, params IWorkHandler <T>[] workHandlers) { _ringBuffer = ringBuffer; _workProcessors = new WorkProcessor <T> [workHandlers.Length]; for (var i = 0; i < workHandlers.Length; i++) { _workProcessors[i] = new WorkProcessor <T>(ringBuffer, sequenceBarrier, workHandlers[i], exceptionHandler, _workSequence); } }
/// <summary> /// Create a worker pool to enable an array of <see cref="IWorkHandler{T}"/>s to consume published sequences. /// /// This option requires a pre-configured <see cref="RingBuffer{T}"/> which must have <see cref="Sequencer.SetGatingSequences"/> /// called before the work pool is started. /// </summary> /// <param name="ringBuffer">ringBuffer of events to be consumed.</param> /// <param name="sequenceBarrier">sequenceBarrier on which the workers will depend.</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(RingBuffer <T> ringBuffer, ISequenceBarrier sequenceBarrier, IExceptionHandler exceptionHandler, params IWorkHandler <T>[] workHandlers) { _ringBuffer = ringBuffer; int numWorkers = workHandlers.Length; _workProcessors = new WorkProcessor <T> [numWorkers]; for (int i = 0; i < numWorkers; i++) { _workProcessors[i] = new WorkProcessor <T>(ringBuffer, sequenceBarrier, workHandlers[i], exceptionHandler, _workSequence); } }
/// <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()); }
/// <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); }
public EventReleaser(WorkProcessor <T> workProcessor) { _workProcessor = workProcessor; }