Ejemplo n.º 1
0
        internal ValueEventHandlerGroup <T> CreateEventProcessors(ISequence[] barrierSequences, IValueEventHandler <T>[] eventHandlers)
        {
            CheckNotStarted();

            var processorSequences = new ISequence[eventHandlers.Length];
            var barrier            = _ringBuffer.NewBarrier(barrierSequences);

            for (int i = 0; i < eventHandlers.Length; i++)
            {
                var eventHandler = eventHandlers[i];

                var batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, barrier, eventHandler);

                if (_exceptionHandler != null)
                {
                    batchEventProcessor.SetExceptionHandler(_exceptionHandler);
                }

                _consumerRepository.Add(batchEventProcessor, eventHandler, barrier);
                processorSequences[i] = batchEventProcessor.Sequence;
            }

            UpdateGatingSequencesForNextInChain(barrierSequences, processorSequences);

            return(new ValueEventHandlerGroup <T>(this, _consumerRepository, processorSequences));
        }
Ejemplo n.º 2
0
        public void ShouldReportProgressByUpdatingSequenceViaCallback()
        {
            var ringBuffer = RingBuffer <StubEvent> .CreateMultiProducer(() => new StubEvent(-1), 16);

            var sequenceBarrier = ringBuffer.NewBarrier();
            ISequenceReportingEventHandler <StubEvent> handler = new TestSequenceReportingEventHandler(_callbackSignal, _onEndOfBatchSignal);
            var batchEventProcessor = BatchEventProcessorFactory.Create(ringBuffer, sequenceBarrier, handler);

            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);

            var thread = new Thread(batchEventProcessor.Run)
            {
                IsBackground = true
            };

            thread.Start();

            Assert.AreEqual(-1L, batchEventProcessor.Sequence.Value);
            ringBuffer.Publish(ringBuffer.Next());

            _callbackSignal.WaitOne();
            Assert.AreEqual(0L, batchEventProcessor.Sequence.Value);

            _onEndOfBatchSignal.Set();
            Assert.AreEqual(0L, batchEventProcessor.Sequence.Value);

            batchEventProcessor.Halt();
            thread.Join();
        }
Ejemplo n.º 3
0
        public OneToThreeDiamondSequencedThroughputTest()
        {
            var sequenceBarrier = _ringBuffer.NewBarrier();

            var fizzHandler = new FizzBuzzEventHandler(FizzBuzzStep.Fizz);

            _batchProcessorFizz = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, fizzHandler);

            var buzzHandler = new FizzBuzzEventHandler(FizzBuzzStep.Buzz);

            _batchProcessorBuzz = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, buzzHandler);

            var sequenceBarrierFizzBuzz = _ringBuffer.NewBarrier(_batchProcessorFizz.Sequence, _batchProcessorBuzz.Sequence);

            _fizzBuzzHandler        = new FizzBuzzEventHandler(FizzBuzzStep.FizzBuzz);
            _batchProcessorFizzBuzz = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrierFizzBuzz, _fizzBuzzHandler);

            var temp = 0L;

            for (long i = 0; i < _iterations; i++)
            {
                var fizz = 0 == (i % 3L);
                var buzz = 0 == (i % 5L);

                if (fizz && buzz)
                {
                    ++temp;
                }
            }
            _expectedResult = temp;

            _ringBuffer.AddGatingSequences(_batchProcessorFizzBuzz.Sequence);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            var executor   = new BasicExecutor(TaskScheduler.Current);
            var disruptor  = new Disruptor <DynamicEvent>(() => new DynamicEvent(), 1024, TaskScheduler.Current);
            var ringBuffer = disruptor.Start();

            // Construct 2 batch event processors.
            var handler1   = new DynamicHandler();
            var processor1 = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), handler1);

            var handler2   = new DynamicHandler();
            var processor2 = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(processor1.Sequence), handler2);

            // Dynamically add both sequences to the ring buffer
            ringBuffer.AddGatingSequences(processor1.Sequence, processor2.Sequence);

            // Start the new batch processors.
            executor.Execute(processor1.Run);
            executor.Execute(processor2.Run);

            // Remove a processor.

            // Stop the processor
            processor2.Halt();
            // Wait for shutdown the complete
            handler2.WaitShutdown();
            // Remove the gating sequence from the ring buffer
            ringBuffer.RemoveGatingSequence(processor2.Sequence);
        }
Ejemplo n.º 5
0
        private void InitializeCommand()
        {
            var rootRebuilder         = _provider.GetRequiredService <IAggregateRootRebuilder>();
            var loggerFactory         = _provider.GetRequiredService <ILoggerFactory>();
            var commandHandlerFactory = _provider.GetRequiredService <ICommandHandlerFactory>();
            var eventStore            = _provider.GetRequiredService <IEventStore>();
            var eventBus        = _provider.GetRequiredService <IEventBus>();
            var commandRegister = _provider.GetRequiredService <ICommandRegister>();

            IContextCache contextCache = _provider.GetRequiredService <IContextCache>();

            var size         = _options.CommandQueueSize;
            var waitStrategy = new SpinWaitWaitStrategy();

            var queue = RingBuffer <WrapMessage <CommandMessage> > .CreateMultiProducer(() => new WrapMessage <CommandMessage>(), size, waitStrategy);

            var barrier = queue.NewBarrier();

            var commandMappingProvider = _provider.GetService <ICommandMappingProvider>();

            if (commandMappingProvider != null)
            {
                var cacheHandler = new RingCommandCacheHandler(
                    commandMappingProvider
                    , rootRebuilder
                    , contextCache
                    , loggerFactory
                    , _options.CommandMaxHandleCount);


                var cacheConsumer = BatchEventProcessorFactory.Create <WrapMessage <CommandMessage> >(queue, barrier, cacheHandler);

                barrier = queue.NewBarrier(cacheConsumer.Sequence);
                consumers.Add(cacheConsumer);
            }


            var executorHandler = new RingCommandBusinessHandler(
                contextCache
                , commandHandlerFactory
                , eventStore
                , eventBus
                , commandRegister
                , rootRebuilder
                , loggerFactory
                , _options.CommandMaxHandleCount
                );

            var executorConsumer = BatchEventProcessorFactory.Create <WrapMessage <CommandMessage> >(queue, barrier, executorHandler);

            consumers.Add(executorConsumer);

            queue.AddGatingSequences(executorConsumer.Sequence);

            _commandQueue = queue;
        }
        public BatchEventProcessorBenchmarks()
        {
            _ringBuffer   = new RingBuffer <TestEvent>(() => new TestEvent(), new SingleProducerSequencer(4096, new SpinWaitWaitStrategy()));
            _eventHandler = new TestEventHandler();
            _processor    = BatchEventProcessorFactory.Create(_ringBuffer, _ringBuffer.NewBarrier(), _eventHandler);

            _eventHandler.Processor  = _processor;
            _eventHandler.RingBuffer = _ringBuffer;
            _ringBuffer.AddGatingSequences(_processor.Sequence);
        }
Ejemplo n.º 7
0
        public OneToOneSequencedBatchValueThroughputTest()
        {
            _ringBuffer = ValueRingBuffer <PerfValueEvent> .CreateSingleProducer(PerfValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());

            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handler             = new AdditionEventHandler();
            _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
 public ThreeToOneSequencedThroughputTest()
 {
     _sequenceBarrier     = _ringBuffer.NewBarrier();
     _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, _sequenceBarrier, _handler);
     for (var i = 0; i < _numPublishers; i++)
     {
         _valuePublishers[i] = ValuePublisher;
     }
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
Ejemplo n.º 9
0
        public OneToOneSequencedLongArrayThroughputTest()
        {
            _ringBuffer = RingBuffer <long[]> .CreateSingleProducer(() => new long[_arraySize], _bufferSize, new YieldingWaitStrategy());

            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handler             = new LongArrayEventHandler();
            _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
Ejemplo n.º 10
0
        public OneToOneSequencedBatchUnmanagedThroughputTest()
        {
            _memory     = UnmanagedRingBufferMemory.Allocate(_bufferSize, PerfValueEvent.Size);
            _ringBuffer = new UnmanagedRingBuffer <PerfValueEvent>(_memory, ProducerType.Single, new YieldingWaitStrategy());
            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handler             = new AdditionEventHandler();
            _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
Ejemplo n.º 11
0
        public OneToOneSequencedThroughputTest()
        {
            _latch        = new ManualResetEvent(false);
            _eventHandler = new ValueAdditionEventHandler();
            _ringBuffer   = RingBuffer <ValueEvent> .CreateSingleProducer(ValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());

            var sequenceBarrier = _ringBuffer.NewBarrier();

            _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _eventHandler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
        public ThreeToOneSequencedBatchThroughputTest()
        {
            var sequenceBarrier = _ringBuffer.NewBarrier();

            for (var i = 0; i < _numPublishers; i++)
            {
                _valuePublishers[i] = new ValueBatchPublisher(_cyclicBarrier, _ringBuffer, _iterations / _numPublishers, 10);
            }

            _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
Ejemplo n.º 13
0
        private void InitializeEvent()
        {
            var snapshootStoreFactory = _provider.GetRequiredService <ISnapshootStoreFactory>();
            var loggerFactory         = _provider.GetRequiredService <ILoggerFactory>();
            var eventHandlerFactory   = _provider.GetRequiredService <IEventHandlerFactory>();
            var snapshootCache        = _provider.GetRequiredService <ISnapshootCache>();
            var eventRegister         = _provider.GetRequiredService <IEventRegister>();
            var assemblyProvider      = _provider.GetRequiredService <IAssemblyProvider>();
            var eventRebuildHandler   = _provider.GetRequiredService <IEventRebuildHandler>();
            var subscribeEventStore   = _provider.GetRequiredService <ISubscribeEventStore>();
            var eventHandleSubject    = _provider.GetRequiredService <IEventHandleSubject>();

            var size         = _options.EventQueueSize;
            var waitStrategy = new SpinWaitWaitStrategy();

            var queue = RingBuffer <WrapMessage <IEvent> > .CreateMultiProducer(() => new WrapMessage <IEvent>(), size, waitStrategy);

            var barrier = queue.NewBarrier();

            var snapshootHandler = new RingEventSnapshootHandler(
                assemblyProvider
                , snapshootStoreFactory
                , eventRebuildHandler
                , subscribeEventStore
                , snapshootCache
                , loggerFactory
                , eventHandleSubject
                , _options.EventMaxHandleCount);

            var snapshootConsumer = BatchEventProcessorFactory.Create <WrapMessage <IEvent> >(queue, barrier, snapshootHandler);

            barrier = queue.NewBarrier(snapshootConsumer.Sequence);
            consumers.Add(snapshootConsumer);


            var executorHandler = new RingEventBusinessHandler(
                eventRegister
                , eventHandlerFactory
                , subscribeEventStore
                , loggerFactory
                , eventHandleSubject
                , _options.EventMaxHandleCount);

            var executorConsumer = BatchEventProcessorFactory.Create <WrapMessage <IEvent> >(queue, barrier, executorHandler);


            consumers.Add(executorConsumer);

            queue.AddGatingSequences(executorConsumer.Sequence);

            _eventQueue = queue;
        }
Ejemplo n.º 14
0
        public void ShouldMakeEntriesAvailableToFirstCustomProcessorsImmediately()
        {
            var countDownLatch = new CountdownEvent(2);
            var eventHandler   = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(new TestEventProcessorFactory <TestEvent>((ringBuffer, barrierSequences) =>
            {
                Assert.AreEqual(0, barrierSequences.Length, "Should not have had any barrier sequences");
                return(BatchEventProcessorFactory.Create(_disruptor.RingBuffer, ringBuffer.NewBarrier(barrierSequences), eventHandler));
            }));

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch);
        }
Ejemplo n.º 15
0
        public void ShouldHonourDependenciesForCustomProcessors()
        {
            var countDownLatch      = new CountdownEvent(2);
            var eventHandler        = new CountDownEventHandler <TestEvent>(countDownLatch);
            var delayedEventHandler = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler).Then(new TestEventProcessorFactory <TestEvent>((ringBuffer, barrierSequences) =>
            {
                Assert.AreEqual(1, barrierSequences.Length, "Should have had a barrier sequence");
                return(BatchEventProcessorFactory.Create(_disruptor.RingBuffer, ringBuffer.NewBarrier(barrierSequences), eventHandler));
            }));

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
Ejemplo n.º 16
0
        public void ShouldSupportCustomProcessorsAsDependencies()
        {
            var ringBuffer = _disruptor.RingBuffer;

            var delayedEventHandler = CreateDelayedEventHandler();

            var countDownLatch = new CountdownEvent(2);
            IEventHandler <TestEvent> handlerWithBarrier = new EventHandlerStub <TestEvent>(countDownLatch);

            var processor = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler);

            _disruptor.HandleEventsWith(processor).Then(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
Ejemplo n.º 17
0
        public void ShouldSupportAddingCustomEventProcessorWithFactory()
        {
            var rb = _disruptor.RingBuffer;
            var b1 = BatchEventProcessorFactory.Create(rb, rb.NewBarrier(), new SleepingEventHandler());
            var b2 = new TestEventProcessorFactory <TestEvent>((ringBuffer, barrierSequences) =>
            {
                return(new BatchEventProcessor <TestEvent>(ringBuffer, ringBuffer.NewBarrier(barrierSequences), new SleepingEventHandler()));
            });

            _disruptor.HandleEventsWith(b1).Then(b2);

            _disruptor.Start();

            Assert.That(_executor.GetExecutionCount(), Is.EqualTo(2));
        }
Ejemplo n.º 18
0
        private IBatchEventProcessor <T> CreateBatchEventProcessor <T>(IDataProvider <T> dataProvider, ISequenceBarrier sequenceBarrier, IEventHandler <T> eventHandler)
            where T : class
        {
            switch (_targetType)
            {
            case BatchEventProcessorType.Legacy:
                return(new BatchEventProcessor <T>(dataProvider, sequenceBarrier, eventHandler));

            case BatchEventProcessorType.Optimized:
                return(BatchEventProcessorFactory.Create(dataProvider, sequenceBarrier, eventHandler));

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 19
0
        public void ShouldSupportCustomProcessorsAsDependencies()
        {
            var ringBuffer = _disruptor.RingBuffer;

            var delayedEventHandler = CreateDelayedEventHandler();

            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownValueEventHandler <TestValueEvent>(countDownLatch);

            var processor = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler);

            _disruptor.HandleEventsWith(processor).Then(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);

            Assert.That(_executor.GetExecutionCount(), Is.EqualTo(2));
        }
Ejemplo n.º 20
0
        public void ShouldSupportHandlersAsDependenciesToCustomProcessors()
        {
            var delayedEventHandler = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler);

            var ringBuffer         = _disruptor.RingBuffer;
            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownValueEventHandler <TestValueEvent>(countDownLatch);

            var sequenceBarrier = _disruptor.After(delayedEventHandler).AsSequenceBarrier();
            var processor       = BatchEventProcessorFactory.Create(ringBuffer, sequenceBarrier, handlerWithBarrier);

            _disruptor.HandleEventsWith(processor);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
Ejemplo n.º 21
0
        public PingPongSequencedValueLatencyTest()
        {
            _pingBuffer = ValueRingBuffer <PerfValueEvent> .CreateSingleProducer(PerfValueEvent.EventFactory, _bufferSize, new BlockingWaitStrategy());

            _pongBuffer = ValueRingBuffer <PerfValueEvent> .CreateSingleProducer(PerfValueEvent.EventFactory, _bufferSize, new BlockingWaitStrategy());

            _pingBarrier = _pingBuffer.NewBarrier();
            _pongBarrier = _pongBuffer.NewBarrier();

            _pinger = new Pinger(_pingBuffer, _iterations, _pauseNanos);
            _ponger = new Ponger(_pongBuffer);

            _pingProcessor = BatchEventProcessorFactory.Create(_pongBuffer, _pongBarrier, _pinger);
            _pongProcessor = BatchEventProcessorFactory.Create(_pingBuffer, _pingBarrier, _ponger);

            _pingBuffer.AddGatingSequences(_pongProcessor.Sequence);
            _pongBuffer.AddGatingSequences(_pingProcessor.Sequence);
        }
Ejemplo n.º 22
0
        public void ShouldSupportMultipleCustomProcessorsAndHandlersAsDependencies()
        {
            var ringBuffer         = _disruptor.RingBuffer;
            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownValueEventHandler <TestValueEvent>(countDownLatch);

            var delayedEventHandler1 = CreateDelayedEventHandler();
            var processor1           = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler1);

            var delayedEventHandler2 = CreateDelayedEventHandler();
            var processor2           = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler2);

            _disruptor.HandleEventsWith(processor1, processor2);
            _disruptor.After(processor1, processor2).HandleEventsWith(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);

            Assert.That(_taskScheduler.TaskCount, Is.EqualTo(3));
        }
Ejemplo n.º 23
0
        public void ShouldSupportCustomProcessorsAndHandlersAsDependencies()
        {
            var delayedEventHandler1 = CreateDelayedEventHandler();
            var delayedEventHandler2 = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler1);

            var ringBuffer         = _disruptor.RingBuffer;
            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            var sequenceBarrier = _disruptor.After(delayedEventHandler1).AsSequenceBarrier();
            var processor       = BatchEventProcessorFactory.Create(ringBuffer, sequenceBarrier, delayedEventHandler2);

            _disruptor.After(delayedEventHandler1).And(processor).HandleEventsWith(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);

            Assert.That(_executor.GetExecutionCount(), Is.EqualTo(3));
        }
Ejemplo n.º 24
0
        public void Run()
        {
            if (IsRunning)
            {
                return;
            }

            var sequenceBarrier   = _ringBuffer.NewBarrier();
            var orderEventHandler = new OrderEventHandler();

            _orderBatchProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, orderEventHandler);
            _orderBatchProcessor.WaitUntilStarted(TimeSpan.FromSeconds(3));
            _tasks.Add(Task.Run(() => _orderBatchProcessor.Run()));

            IsRunning = true;
            _latch.WaitOne();
            _orderBatchProcessor.Halt();
            Task.WaitAll(_tasks.ToArray());

            IsRunning = false;
        }
        public void ShouldReportValueEventHandlerProgressByUpdatingSequenceViaCallback()
        {
            var ringBuffer = ValueRingBuffer <StubValueEvent> .CreateMultiProducer(() => new StubValueEvent(-1), 16);

            var sequenceBarrier     = ringBuffer.NewBarrier();
            var handler             = new TestSequenceReportingEventHandler();
            var batchEventProcessor = BatchEventProcessorFactory.Create(ringBuffer, sequenceBarrier, handler);

            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);

            var task = Task.Run(batchEventProcessor.Run);

            Assert.AreEqual(-1L, batchEventProcessor.Sequence.Value);
            ringBuffer.Publish(ringBuffer.Next());

            handler.CallbackSignal.WaitOne();
            Assert.AreEqual(0L, batchEventProcessor.Sequence.Value);

            handler.OnEndOfBatchSignal.Set();
            Assert.AreEqual(0L, batchEventProcessor.Sequence.Value);

            batchEventProcessor.Halt();
            Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(10)));
        }
Ejemplo n.º 26
0
        public void ShouldAddEventProcessorsAfterPublishing()
        {
            var rb = _disruptor.RingBuffer;
            var b1 = BatchEventProcessorFactory.Create(rb, rb.NewBarrier(), new SleepingEventHandler());
            var b2 = BatchEventProcessorFactory.Create(rb, rb.NewBarrier(b1.Sequence), new SleepingEventHandler());
            var b3 = BatchEventProcessorFactory.Create(rb, rb.NewBarrier(b2.Sequence), new SleepingEventHandler());

            Assert.That(b1.Sequence.Value, Is.EqualTo(-1L));
            Assert.That(b2.Sequence.Value, Is.EqualTo(-1L));
            Assert.That(b3.Sequence.Value, Is.EqualTo(-1L));

            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());

            _disruptor.HandleEventsWith(b1, b2, b3);

            Assert.That(b1.Sequence.Value, Is.EqualTo(5L));
            Assert.That(b2.Sequence.Value, Is.EqualTo(5L));
            Assert.That(b3.Sequence.Value, Is.EqualTo(5L));
        }
Ejemplo n.º 27
0
        public OneToThreeSequencedThroughputTest()
        {
            for (long i = 0; i < _iterations; i++)
            {
                _results[0] = Operation.Addition.Op(_results[0], i);
                _results[1] = Operation.Subtraction.Op(_results[1], i);
                _results[2] = Operation.And.Op(_results[2], i);
            }

            _ringBuffer = RingBuffer <ValueEvent> .CreateSingleProducer(ValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());

            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handlers[0] = new ValueMutationEventHandler(Operation.Addition);
            _handlers[1] = new ValueMutationEventHandler(Operation.Subtraction);
            _handlers[2] = new ValueMutationEventHandler(Operation.And);


            for (var i = 0; i < _numEventProcessors; i++)
            {
                _batchEventProcessors[i] = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _handlers[i]);
            }
            _ringBuffer.AddGatingSequences(_batchEventProcessors.Select(x => x.Sequence).ToArray());
        }
Ejemplo n.º 28
0
        public OneToThreePipelineSequencedThroughputTest()
        {
            var stepOneFunctionHandler = new FunctionEventHandler(FunctionStep.One);
            var stepTwoFunctionHandler = new FunctionEventHandler(FunctionStep.Two);

            _stepThreeFunctionHandler = new FunctionEventHandler(FunctionStep.Three);

            var stepOneSequenceBarrier = _ringBuffer.NewBarrier();

            _stepOneBatchProcessor = BatchEventProcessorFactory.Create(_ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);

            var stepTwoSequenceBarrier = _ringBuffer.NewBarrier(_stepOneBatchProcessor.Sequence);

            _stepTwoBatchProcessor = BatchEventProcessorFactory.Create(_ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);

            var stepThreeSequenceBarrier = _ringBuffer.NewBarrier(_stepTwoBatchProcessor.Sequence);

            _stepThreeBatchProcessor = BatchEventProcessorFactory.Create(_ringBuffer, stepThreeSequenceBarrier, _stepThreeFunctionHandler);

            var temp       = 0L;
            var operandTwo = _operandTwoInitialValue;

            for (long i = 0; i < _iterations; i++)
            {
                var stepOneResult = i + operandTwo--;
                var stepTwoResult = stepOneResult + 3;

                if ((stepTwoResult & 4L) == 4L)
                {
                    ++temp;
                }
            }
            _expectedResult = temp;

            _ringBuffer.AddGatingSequences(_stepThreeBatchProcessor.Sequence);
        }
 public void Setup()
 {
     _processor    = BatchEventProcessorFactory.Create(_ringBuffer, _ringBuffer.NewBarrier(), new XEventHandler(() => _processor.Halt()));
     _processorRef = BatchEventProcessorFactory.Create(_ringBuffer, _ringBuffer.NewBarrier(), new XEventHandler(() => _processorRef.Halt()), typeof(BatchEventProcessorRef <, , , ,>));
 }
Ejemplo n.º 30
0
 public IEventProcessor CreateEventProcessor(RingBuffer <TestEvent> ringBuffer, ISequence[] barrierSequences)
 {
     Assert.AreEqual(_sequenceLength, barrierSequences.Length, "Should not have had any barrier sequences");
     return(BatchEventProcessorFactory.Create(_disruptor.RingBuffer, ringBuffer.NewBarrier(barrierSequences), _eventHandler));
 }