Beispiel #1
0
        /// <summary>
        /// It is ok to have another thread rerun this method after a halt().
        /// </summary>
        public void Run()
        {
            if (Interlocked.Exchange(ref _running, 1) != 0)
            {
                throw new InvalidOperationException("Thread is already running");
            }
            _sequenceBarrier.ClearAlert();

            NotifyStart();

            T   evt          = null;
            var nextSequence = _sequence.Value + 1L;

            try
            {
                while (true)
                {
                    try
                    {
                        var availableSequence = _sequenceBarrier.WaitFor(nextSequence);

                        if (_batchStartAware != null)
                        {
                            _batchStartAware.OnBatchStart(availableSequence - nextSequence + 1);
                        }

                        while (nextSequence <= availableSequence)
                        {
                            evt = _dataProvider[nextSequence];
                            _eventHandler.OnEvent(evt, nextSequence, nextSequence == availableSequence);
                            nextSequence++;
                        }

                        _sequence.SetValue(availableSequence);
                    }
                    catch (TimeoutException)
                    {
                        NotifyTimeout(_sequence.Value);
                    }
                    catch (AlertException)
                    {
                        if (_running == 0)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        _exceptionHandler.HandleEventException(ex, nextSequence, evt);
                        _sequence.SetValue(nextSequence);
                        nextSequence++;
                    }
                }
            }
            finally
            {
                NotifyShutdown();
                _running = 0;
            }
        }
 public void OnBatchStart(long batchSize)
 {
     if (batchSize != 0)
     {
         _target.OnBatchStart(batchSize);
     }
 }
 public void OnBatchStart(long batchSize)
 {
     if (_batchStartAware != null && batchSize != 0)
     {
         _batchStartAware.OnBatchStart(batchSize);
     }
 }
        private void ProcessEvents()
        {
            TEvent @event       = null;
            var    nextSequence = _sequence.GetValue() + 1L;

            while (true)
            {
                try
                {
                    var availableSequence = _sequenceBarrier.WaitFor(nextSequence);

                    _batchStartAware?.OnBatchStart(availableSequence - nextSequence + 1);

                    while (nextSequence <= availableSequence)
                    {
                        @event = _dataProvider.Get(nextSequence);
                        _eventHandler.OnEvent(@event, nextSequence, nextSequence == availableSequence);
                        nextSequence++;
                    }

                    _sequence.SetValue(availableSequence);
                }
                catch (TimeoutException)
                {
                    NotifyTimeout(_sequence.GetValue());
                }
                catch (AlertException)
                {
                    if (_running != Running)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    _exceptionHandler?.HandleEventException(e, nextSequence, @event);
                    _sequence.SetValue(nextSequence);
                    nextSequence++;
                }
            }
        }
Beispiel #5
0
 public void OnBatchStart(long batchSize)
 {
     _eventHandler?.OnBatchStart(batchSize);
 }