Exemplo n.º 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];
 }
 public bool Handle(ProjectionCoreServiceMessage.EventReaderIdle message)
 {
     EnsureStarted();
     if (message.CorrelationId != _eventReaderId)
         return false;
     DistributeMessage(message);
     return true;
 }
 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);
     }
 }
        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;
        }
 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);
 }
 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);
 }
 public void Handle(ProjectionCoreServiceMessage.EventReaderEof message)
 {
     _receivedEofNotifications.Add(message);
 }
 public void Handle(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     _receivedEvents.Add(message);
 }
 private void DistributeMessage(ProjectionCoreServiceMessage.CommittedEventDistributed message)
 {
     foreach (var subscriber in _headSubscribers.Values)
         subscriber.Handle(message);
 }
 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;
 }
 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;
 }
 public bool Handle(ProjectionCoreServiceMessage.EventReaderEof message)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 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);
 }
 public override bool IsMessageAfterCheckpointTag(CheckpointTag previous, ProjectionCoreServiceMessage.CommittedEventDistributed comittedEvent)
 {
     return comittedEvent.Position.PreparePosition > previous.PreparePosition;
 }
 public override CheckpointTag MakeCheckpointTag(CheckpointTag previous, ProjectionCoreServiceMessage.CommittedEventDistributed comittedEvent)
 {
     return CheckpointTag.FromPreparePosition(comittedEvent.Position.PreparePosition);
 }