Beispiel #1
0
        private void Received(OrderedCommitNotification msg)
        {
            //if their previous matches our current, project
            //if their previous is less than our current, ignore
            //if their previous is > our current, catchup
            var comparer    = new CheckpointComparer();
            var comparision = comparer.Compare(Checkpoint, msg.PreviousCheckpoint);

            if (comparision == 0)
            {
                Project(msg.Commit); //order matched, project
            }
            else if (comparision > 0)
            {
                //we are ahead of this commit so no-op, this is a bit odd, so log it
                Context.GetLogger().Debug("Received a commit notification  (checkpoint {0}) behind our checkpoint ({1})", msg.Commit.CheckpointToken, Checkpoint.Get());
            }
            else
            {
                //we are behind the head, should catch up
                var fromPoint = Checkpoint.Map(x => x.ToString()).GetOrElse("beginning of time");
                Context.GetLogger().Info("Catchup started from checkpoint {0} after receiving out-of-sequence commit with checkpoint {1} and previous checkpoint {2}", fromPoint, msg.Commit.CheckpointToken, msg.PreviousCheckpoint);
                Catchup();
                Context.GetLogger().Info("Catchup finished from {0} to checkpoint {1} after receiving commit with checkpoint {2}", fromPoint, Checkpoint.Map(x => x.ToString()).GetOrElse("beginning of time"), msg.Commit.CheckpointToken);
            }
        }
 /// <summary>
 /// Message sent by the event store poller
 /// </summary>
 /// <param name="msg"></param>
 private void Received(OrderedCommitNotification msg)
 {
     //guard against old messages being streamed from the poller, we can safely ignore them
     if (_orderer.IsNextCheckpoint(_currentCheckpoint, msg))
     {
         SendCommitToProjectors(msg);
     }
 }
 /// <summary>
 /// Sends the commit to the projectors for projection
 /// </summary>
 /// <param name="msg"></param>
 private void SendCommitToProjectors(OrderedCommitNotification msg)
 {
     _backlogCommitCount = 0;                                      //reset the backlog counter
     _currentCheckpoint  = msg.Commit.CheckpointToken.ToSome();    //update head pointer
     Context.ActorSelection(_projectorsBroadCastRouter).Tell(msg); //pass message on for projection
 }
 /// <summary>
 /// Pass your current checkpoint and a new orderedcommitnotification message to determine if this is the next commit for you to process
 /// </summary>
 /// <param name="currentCheckpoint"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public bool IsNextCheckpoint(Option <long> currentCheckpoint, OrderedCommitNotification msg)
 {
     return(_comparer.Compare(currentCheckpoint, msg.PreviousCheckpoint) == 0);
 }