Esempio n. 1
0
        protected Receive Replaying(int limit)
        {
            return(message =>
            {
                switch (message)
                {
                case ReplayedMessage replayed:
                    var seqNr = replayed.Persistent.SequenceNr;
                    Buffer.Add(new EventEnvelope(
                                   offset: new Sequence(seqNr),
                                   persistenceId: PersistenceId,
                                   sequenceNr: seqNr,
                                   @event: replayed.Persistent.Payload));
                    CurrentSequenceNr = seqNr + 1;
                    Buffer.DeliverBuffer(TotalDemand);
                    return true;

                case RecoverySuccess success:
                    Log.Debug("Replay completed for persistenceId [{0}], currSeqNo [{1}]", PersistenceId, CurrentSequenceNr);
                    ReceiveRecoverySuccess(success.HighestSequenceNr);
                    return true;

                case ReplayMessagesFailure failure:
                    Log.Debug("Replay failed for persistenceId [{0}], due to [{1}]", PersistenceId, failure.Cause.Message);
                    Buffer.DeliverBuffer(TotalDemand);
                    OnErrorThenStop(failure.Cause);
                    return true;

                case Request _:
                    Buffer.DeliverBuffer(TotalDemand);
                    return true;

                case EventsByPersistenceIdPublisher.Continue _:
                case EventAppended _:
                    // skip during replay
                    return true;

                case Cancel _:
                    Context.Stop(Self);
                    return true;
                }

                return false;
            });
        }
Esempio n. 2
0
        private bool Active(object message)
        {
            if (message is CurrentPersistenceIds current)
            {
                _buffer.AddRange(current.AllPersistenceIds);
                _buffer.DeliverBuffer(TotalDemand);

                if (!_liveQuery && _buffer.IsEmpty)
                {
                    OnCompleteThenStop();
                }

                return(true);
            }
            else if (message is PersistenceIdAdded added)
            {
                if (_liveQuery)
                {
                    _buffer.Add(added.PersistenceId);
                    _buffer.DeliverBuffer(TotalDemand);
                }
                return(true);
            }
            else if (message is Request)
            {
                _buffer.DeliverBuffer(TotalDemand);
                if (!_liveQuery && _buffer.IsEmpty)
                {
                    OnCompleteThenStop();
                }
                return(true);
            }
            else if (message is Cancel)
            {
                Context.Stop(Self);
                return(true);
            }
            else
            {
                return(false);
            }
        }