protected Receive Replaying(int limit)
        {
            return(message => message.Match()
                   .With <ReplayedTaggedMessage>(replayed => {
                Buffer.Add(new EventEnvelope(
                               offset: new Sequence(replayed.Offset),
                               persistenceId: replayed.Persistent.PersistenceId,
                               sequenceNr: replayed.Persistent.SequenceNr,
                               @event: replayed.Persistent.Payload));

                CurrentOffset = replayed.Offset;
                Buffer.DeliverBuffer(TotalDemand);
            })
                   .With <RecoverySuccess>(success => {
                Log.Debug("replay completed for tag [{0}], currOffset [{1}]", Tag, CurrentOffset);
                ReceiveRecoverySuccess(success.HighestSequenceNr);
            })
                   .With <ReplayMessagesFailure>(failure => {
                Log.Debug("replay failed for tag [{0}], due to [{1}]", Tag, failure.Cause.Message);
                Buffer.DeliverBuffer(TotalDemand);
                OnErrorThenStop(failure.Cause);
            })
                   .With <Request>(_ => Buffer.DeliverBuffer(TotalDemand))
                   .With <EventsByTagPublisher.Continue>(() => { })
                   .With <TaggedEventAppended>(() => { })
                   .With <Cancel>(() => Context.Stop(Self))
                   .WasHandled);
        }
Ejemplo n.º 2
0
 protected Receive Replaying(int limit)
 {
     return(message => message.Match()
            .With <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);
     })
            .With <RecoverySuccess>(success => {
         Log.Debug("replay completed for persistenceId [{0}], currSeqNo [{1}]", PersistenceId, CurrentSequenceNr);
         ReceiveRecoverySuccess(success.HighestSequenceNr);
     })
            .With <ReplayMessagesFailure>(failure => {
         Log.Debug("replay failed for persistenceId [{0}], due to [{1}]", PersistenceId, failure.Cause.Message);
         Buffer.DeliverBuffer(TotalDemand);
         OnErrorThenStop(failure.Cause);
     })
            .With <Request>(_ => Buffer.DeliverBuffer(TotalDemand))
            .With <EventsByPersistenceIdPublisher.Continue>(() => { }) // skip during replay
            .With <EventAppended>(() => { })                           // skip during replay
            .With <Cancel>(_ => Context.Stop(Self))
            .WasHandled);
 }
Ejemplo n.º 3
0
        private bool Active(object message) => message.Match()
        .With <CurrentPersistenceIds>(current => {
            _buffer.AddRange(current.AllPersistenceIds);
            _buffer.DeliverBuffer(TotalDemand);

            if (!_liveQuery && _buffer.IsEmpty)
            {
                OnCompleteThenStop();
            }
        })
        .With <PersistenceIdAdded>(added => {
            if (_liveQuery)
            {
                _buffer.Add(added.PersistenceId);
                _buffer.DeliverBuffer(TotalDemand);
            }
        })
        .With <Request>(_ => {
            _buffer.DeliverBuffer(TotalDemand);
            if (!_liveQuery && _buffer.IsEmpty)
            {
                OnCompleteThenStop();
            }
        })
        .With <Cancel>(_ => Context.Stop(Self))
        .WasHandled;
Ejemplo n.º 4
0
        protected Receive Replaying(int limit)
        {
            return(message =>
            {
                switch (message)
                {
                case ReplayedTaggedMessage replayed:
                    Buffer.Add(new EventEnvelope(
                                   offset: new Sequence(replayed.Offset),
                                   persistenceId: replayed.Persistent.PersistenceId,
                                   sequenceNr: replayed.Persistent.SequenceNr,
                                   timestamp: replayed.Persistent.Timestamp,
                                   @event: replayed.Persistent.Payload));

                    CurrentOffset = replayed.Offset;
                    Buffer.DeliverBuffer(TotalDemand);
                    break;

                case RecoverySuccess success:
                    Log.Debug("replay completed for tag [{0}], currOffset [{1}]", Tag, CurrentOffset);
                    ReceiveRecoverySuccess(success.HighestSequenceNr);
                    break;

                case ReplayMessagesFailure failure:
                    Log.Debug("replay failed for tag [{0}], due to [{1}]", Tag, failure.Cause.Message);
                    Buffer.DeliverBuffer(TotalDemand);
                    OnErrorThenStop(failure.Cause);
                    break;

                case Request _:
                    Buffer.DeliverBuffer(TotalDemand);
                    break;

                case EventsByTagPublisher.Continue _:
                case TaggedEventAppended _:
                    // ignore
                    break;

                case Cancel _:
                    Context.Stop(Self);
                    break;

                default:
                    return false;
                }

                return true;
            });
        }
Ejemplo n.º 5
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,
                                   timestamp: replayed.Persistent.Timestamp,
                                   @event: replayed.Persistent.Payload));
                    CurrentSequenceNr = seqNr + 1;
                    Buffer.DeliverBuffer(TotalDemand);
                    break;

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

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

                case Request _:
                    Buffer.DeliverBuffer(TotalDemand);
                    break;

                case EventsByPersistenceIdPublisher.Continue _:
                case EventAppended _:
                    // Skip during replay
                    break;

                case Cancel _:
                    Context.Stop(Self);
                    break;

                default:
                    return false;
                }

                return true;
            });
        }