/// <summary>
        ///     Bootstraps the <see cref="Disruptor" /> and starts it.
        /// </summary>
        public void Start()
        {
            if (_exceptionHandler == null)
            {
                throw new ArgumentNullException("Exception EventHandler cannot be null");
            }

            _disruptor.SetDefaultExceptionHandler(_exceptionHandler);

            if (_listTasks == null || _listTasks.Length <= 0)
            {
                throw new ArgumentNullException("list task still null");
            }

            EventHandlerGroup <T> group = null;

            foreach (var eventHandler in _listTasks)
            {
                if (group == null)
                {
                    group = _disruptor.HandleEventsWith(eventHandler);
                }
                else
                {
                    group = group.Then(eventHandler);
                }
            }

            _ringBuffer = _disruptor.Start();
        }
示例#2
0
        public RingBuffer <TEvent> Build()
        {
            if (_bufferSize == 0)
            {
                throw new InvalidOperationException("Buffer size must be set.");
            }

            if (_eventFactory == null)
            {
                throw new InvalidOperationException("Event factory must be specified.");
            }

            if (_claimStrategyFactory == null)
            {
                throw new InvalidOperationException("Claim strategy must be specified.");
            }

            if (_waitStrategy == null)
            {
                throw new InvalidOperationException("Wait strategy must be specified.");
            }

            if (!_eventHandlers.Any())
            {
                throw new InvalidOperationException("At least one event handler must be specified.");
            }

            var disruptor = new Disruptor <TEvent>(
                _eventFactory,
                _claimStrategyFactory(_bufferSize),
                _waitStrategy,
                TaskScheduler.Default);

            EventHandlerGroup <TEvent> handlerGroup = null;

            foreach (var handler in _eventHandlers)
            {
                if (handlerGroup == null)
                {
                    handlerGroup = disruptor.HandleEventsWith(handler);
                }
                else
                {
                    handlerGroup.Then(handler);
                }
            }

            return(disruptor.Start());
        }
示例#3
0
        public FxPricingEngine(params IEventHandler <FxPricingEvent>[] handlers)
        {
            Disruptor = new Disruptor <FxPricingEvent>(() => new FxPricingEvent(), 16384, TaskScheduler.Default, ProducerType.Single, new BusySpinWaitStrategy());

            EventHandlerGroup <FxPricingEvent> group = null;

            foreach (var handler in handlers)
            {
                if (null == group)
                {
                    group = Disruptor.HandleEventsWith(handler);
                }
                else
                {
                    group = group.Then(handler);
                }
            }

            RingBuffer = Disruptor.RingBuffer;

            Disruptor.Start();
        }
示例#4
0
 /// <summary>
 /// Create a new event handler group that combines the consumers in this group with <paramref name="otherHandlerGroup"/>
 /// </summary>
 /// <param name="otherHandlerGroup">the event handler group to combine</param>
 /// <returns>a new EventHandlerGroup combining the existing and new consumers into a single dependency group</returns>
 public EventHandlerGroup <T> And(EventHandlerGroup <T> otherHandlerGroup)
 {
     return(new EventHandlerGroup <T>(_disruptor, _consumerRepository, _sequences.Concat(otherHandlerGroup._sequences)));
 }