示例#1
0
        /// <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);
            }
        }
示例#2
0
        /// <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="ISequencer.AddGatingSequences"/>
        /// 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);
            }
        }
示例#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="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());
        }
示例#5
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);
        }
示例#6
0
 public ConsumerTrackingConsumerBarrier(RingBuffer <TEntry> ringBuffer, IConsumer[] consumers)
 {
     _ringBuffer     = ringBuffer;
     this._consumers = consumers;
 }
示例#7
0
 /// <summary>
 /// Construct from the ring buffer to be published to.
 /// </summary>
 /// <param name="ringBuffer">ringBuffer into which events will be published.</param>
 public EventPublisher(RingBuffer <T> ringBuffer)
 {
     _ringBuffer = ringBuffer;
 }
示例#8
0
 public EventRef(RingBuffer <T> ringBuffer, long sequence)
 {
     _ringBuffer = ringBuffer;
     _sequence   = sequence;
 }
示例#9
0
 public NullableUnpublishedEventScope(RingBuffer <T> ringBuffer, long sequence)
 {
     _ringBuffer = ringBuffer;
     _sequence   = sequence;
 }
示例#10
0
 public UnpublishedEventBatchScope(RingBuffer <T> ringBuffer, long startSequence, long endSequence)
 {
     _ringBuffer    = ringBuffer;
     _startSequence = startSequence;
     _endSequence   = endSequence;
 }
示例#11
0
 public EventBatchRef(RingBuffer <T> ringBuffer, long startSequence, long endSequence)
 {
     _ringBuffer    = ringBuffer;
     _startSequence = startSequence;
     _endSequence   = endSequence;
 }
示例#12
0
 public SequencerFollowingSequence(RingBuffer <T> sequencer)
 {
     _sequencer = sequencer;
 }
示例#13
0
 /// <summary>
 /// Construct a <see cref="IEventProcessor"/> that simply tracks a <see cref="Disruptor.Sequence"/>.
 /// </summary>
 /// <param name="sequencer">sequencer to track.</param>
 public NoOpEventProcessor(RingBuffer <T> sequencer)
 {
     _sequence = new SequencerFollowingSequence(sequencer);
 }
示例#14
0
 public SequencerFollowingSequence(RingBuffer <T> sequencer)
     : base(InitialCursorValue.INITIAL_CURSOR_VALUE)
 {
     this.sequencer = sequencer;
 }