コード例 #1
0
 public override bool IsMessageAfterCheckpointTag(CheckpointTag previous, ProjectionCoreServiceMessage.CommittedEventDistributed comittedEvent)
 {
     if (previous.GetMode() != CheckpointTag.Mode.Stream)
         throw new ArgumentException("Mode.Stream expected", "previous");
     return comittedEvent.PositionStreamId == _stream
            && comittedEvent.PositionSequenceNumber > previous.Streams[_stream];
 }
コード例 #2
0
 public bool Handle(ProjectionCoreServiceMessage.EventReaderIdle message)
 {
     EnsureStarted();
     if (message.CorrelationId != _eventReaderId)
         return false;
     DistributeMessage(message);
     return true;
 }
コード例 #3
0
 public void Handle(ProjectionCoreServiceMessage.EventReaderEof message)
 {
     if (_stopOnEof)
     {
         _eofReached = true;
         EofReached();
         _eofHandler.Handle(
             new ProjectionSubscriptionMessage.EofReached(
                 _projectionCorrelationId, _subscriptionId, _positionTracker.LastTag,
                 _subscriptionMessageSequenceNumber++));
     }
 }
 public void Handle(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     if (message.Data == null)
         throw new NotSupportedException();
     ProjectionCoreServiceMessage.CommittedEventDistributed existing;
     // ignore duplicate messages (when replaying from heading event distribution point)
     if (!_buffer.TryGetValue(message.Position.PreparePosition, out existing))
     {
         _buffer.Add(message.Position.PreparePosition, message);
         var maxTimestamp = _buffer.Max(v => v.Value.Data.Timestamp);
         ProcessAllFor(maxTimestamp);
     }
 }
コード例 #5
0
        public bool Handle(ProjectionCoreServiceMessage.CommittedEventDistributed message)
        {
            EnsureStarted();
            if (message.CorrelationId != _distributionPointId)
                return false;
            if (message.Data == null)
                return true;
            ValidateEventOrder(message);

            CacheRecentMessage(message);
            DistributeMessage(message);
            if (_headSubscribers.Count == 0 && !_headDistributionPointPaused)
            {
                _headDistributionPoint.Pause();
                _headDistributionPointPaused = true;
            }
            return true;
        }
コード例 #6
0
 private void CacheRecentMessage(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     _lastMessages.Enqueue(message);
     if (_lastMessages.Count > _eventCacheSize)
     {
         _lastMessages.Dequeue();
     }
     var lastAvailableCommittedevent = _lastMessages.Peek();
     _subscribeFromPosition = lastAvailableCommittedevent.Position;
 }
 public void Handle(ProjectionCoreServiceMessage.EventReaderIdle message)
 {
     ProcessAllFor(message.IdleTimestampUtc);
 }
コード例 #8
0
 public static CommittedEventReceived FromCommittedEventDistributed(
     ProjectionCoreServiceMessage.CommittedEventDistributed message, CheckpointTag checkpointTag,
     string eventCategory, Guid subscriptionId, long subscriptionMessageSequenceNumber)
 {
     return new CommittedEventReceived(
         message.CorrelationId, subscriptionId, message.Position, checkpointTag, message.PositionStreamId,
         message.PositionSequenceNumber, message.EventStreamId, message.EventSequenceNumber, eventCategory,
         message.ResolvedLinkTo, message.Data, message.Progress, subscriptionMessageSequenceNumber);
 }
コード例 #9
0
 public void Handle(ProjectionCoreServiceMessage.EventReaderEof message)
 {
     _receivedEofNotifications.Add(message);
 }
コード例 #10
0
 public void Handle(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     _receivedEvents.Add(message);
 }
コード例 #11
0
 private void DistributeMessage(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     foreach (var subscriber in _headSubscribers.Values)
         subscriber.Handle(message);
 }
コード例 #12
0
 private void ValidateEventOrder(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     if (_lastEventPosition >= message.Position)
         throw new InvalidOperationException(
             string.Format(
                 "Invalid committed event order.  Last: '{0}' Received: '{1}'", _lastEventPosition,
                 message.Position));
     _lastEventPosition = message.Position;
 }
コード例 #13
0
 protected void ProcessOne(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     // NOTE: we may receive here messages from heading event distribution point
     // and they may not pass out source filter.  Discard them first
     var roundedProgress = (float) Math.Round(message.Progress, 2);
     bool progressChanged = _progress != roundedProgress;
     _progress = roundedProgress;
     if (!_eventFilter.PassesSource(message.ResolvedLinkTo, message.PositionStreamId))
     {
         if (progressChanged)
             _progressHandler.Handle(
                 new ProjectionSubscriptionMessage.ProgressChanged(
                     _projectionCorrelationId, _subscriptionId, _positionTracker.LastTag, _progress,
                     _subscriptionMessageSequenceNumber++));
         return;
     }
     // NOTE: after joining heading distribution point it delivers all cached events to the subscription
     // some of this events we may have already received. The delivered events may have different order
     // (in case of partially ordered cases multi-stream reader etc). We discard all the messages that are not
     // after the last available checkpoint tag
     if (!_positionTagger.IsMessageAfterCheckpointTag(_positionTracker.LastTag, message))
     {
         _logger.Trace(
             "Skipping replayed event {0}@{1} at position {2}. the last processed event checkpoint tag is: {3}",
             message.PositionSequenceNumber, message.PositionStreamId, message.Position, _positionTracker.LastTag);
         return;
     }
     var eventCheckpointTag = _positionTagger.MakeCheckpointTag(_positionTracker.LastTag, message);
     if (eventCheckpointTag <= _positionTracker.LastTag)
         throw new Exception(
             string.Format(
                 "Invalid checkpoint tag was built.  Tag '{0}' must be greater than '{1}'", eventCheckpointTag,
                 _positionTracker.LastTag));
     _positionTracker.UpdateByCheckpointTagForward(eventCheckpointTag);
     if (_eventFilter.Passes(message.ResolvedLinkTo, message.PositionStreamId, message.Data.EventType))
     {
         _lastPassedOrCheckpointedEventPosition = message.Position.PreparePosition;
         var convertedMessage =
             ProjectionSubscriptionMessage.CommittedEventReceived.FromCommittedEventDistributed(
                 message, eventCheckpointTag, _eventFilter.GetCategory(message.PositionStreamId), _subscriptionId,
                 _subscriptionMessageSequenceNumber++);
         _eventHandler.Handle(convertedMessage);
     }
     else
     {
         if (_checkpointUnhandledBytesThreshold != null
             && (_lastPassedOrCheckpointedEventPosition != null
                 && message.Position.PreparePosition - _lastPassedOrCheckpointedEventPosition.Value
                 > _checkpointUnhandledBytesThreshold))
         {
             _lastPassedOrCheckpointedEventPosition = message.Position.PreparePosition;
             _checkpointHandler.Handle(
                 new ProjectionSubscriptionMessage.CheckpointSuggested(
                     _projectionCorrelationId, _subscriptionId, _positionTracker.LastTag, message.Progress,
                     _subscriptionMessageSequenceNumber++));
         }
         else
         {
             if (progressChanged)
                 _progressHandler.Handle(
                     new ProjectionSubscriptionMessage.ProgressChanged(
                         _projectionCorrelationId, _subscriptionId, _positionTracker.LastTag, _progress,
                         _subscriptionMessageSequenceNumber++));
         }
     }
     // initialize checkpointing based on first message
     if (_lastPassedOrCheckpointedEventPosition == null)
         _lastPassedOrCheckpointedEventPosition = message.Position.PreparePosition;
 }
コード例 #14
0
 public bool Handle(ProjectionCoreServiceMessage.EventReaderEof message)
 {
     throw new NotImplementedException();
 }
コード例 #15
0
 public override CheckpointTag MakeCheckpointTag(CheckpointTag previous, ProjectionCoreServiceMessage.CommittedEventDistributed comittedEvent)
 {
     if (comittedEvent.PositionStreamId != _stream)
         throw new InvalidOperationException(string.Format("Invalid stream '{0}'.  Expected stream is '{1}'", comittedEvent.EventStreamId, _stream));
     return CheckpointTag.FromStreamPosition(comittedEvent.PositionStreamId, comittedEvent.PositionSequenceNumber);
 }
コード例 #16
0
 public override bool IsMessageAfterCheckpointTag(CheckpointTag previous, ProjectionCoreServiceMessage.CommittedEventDistributed comittedEvent)
 {
     return comittedEvent.Position.PreparePosition > previous.PreparePosition;
 }
コード例 #17
0
 public override CheckpointTag MakeCheckpointTag(CheckpointTag previous, ProjectionCoreServiceMessage.CommittedEventDistributed comittedEvent)
 {
     return CheckpointTag.FromPreparePosition(comittedEvent.Position.PreparePosition);
 }