protected Receive Replaying() { 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, timestamp: replayed.Persistent.Timestamp)); 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>(() => { }) .With <EventAppended>(() => { }) .With <Cancel>(_ => Context.Stop(Self)) .WasHandled); }
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;
private bool Active(object message) { return(message .Match() .With <CaughtUp>(_ => { _isCaughtUp = true; _buffer.DeliverBuffer(TotalDemand); if (!_isLive && _buffer.IsEmpty) { OnCompleteThenStop(); } }) .With <SubscriptionDroppedException>(OnErrorThenStop) .With <IPersistentRepresentation>(@event => { _buffer.Add(@event.PersistenceId); _buffer.DeliverBuffer(TotalDemand); if (_isCaughtUp && !_isLive && _buffer.IsEmpty) { OnCompleteThenStop(); } }) .With <Request>(_ => { _buffer.DeliverBuffer(TotalDemand); if (_isCaughtUp && !_isLive && _buffer.IsEmpty) { OnCompleteThenStop(); } }) .With <Cancel>(_ => Context.Stop(Self)) .WasHandled); }
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, timestamp: replayed.Persistent.Timestamp, @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); }
private Receive Replaying() { return(message => message.Match() .With <ReplayedTaggedMessage>(replayed => { if (_replayed.Contains(replayed.Offset)) { return; } 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)); Buffer.DeliverBuffer(TotalDemand); if (replayed.Offset > CurrentOffset) { CurrentOffset = replayed.Offset; } if (replayed.Offset > _maxAssuredOffset) { _replayed.Add(replayed.Offset); } }) .With <TagCatchupFinished>(giveUp => GiveUpOnMissingItems(giveUp.HighestSequenceNr)) .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); }
private void MaybeReply() { if (_requestedCount > 0) { var deliver = _buffer.Length > _requestedCount ? _requestedCount : _buffer.Length; _requestedCount -= deliver; _buffer.DeliverBuffer(deliver); } if (_buffer.IsEmpty && (_currentOffset >= _toOffset || _isCaughtUp && !_isLive)) { OnCompleteThenStop(); } }