private void BuiltInCommands() { Command <SaveSnapshotSuccess>(snapshot => { if (Log.IsDebugEnabled) { Log.Debug( "Successfully saved snapshot with SeqNo {0} - purging older entries from journal and snapshotstore", snapshot.Metadata.SequenceNr); } DeleteMessages(snapshot.Metadata.SequenceNr); DeleteSnapshots(new SnapshotSelectionCriteria(snapshot.Metadata.SequenceNr - 1)); }); Command <SaveSnapshotFailure>(failure => { Log.Error(failure.Cause, "Failed to save snapshot {0} - " + "refraining from deleting any messages from journal.", failure.Metadata.SequenceNr); }); Command <PruneSendersTick>(prune => { var pruneResult = _receiverState.Prune(Settings.PruneInterval); _receiverState = pruneResult.newState; if (Log.IsDebugEnabled && pruneResult.prunedSenders.Count > 0) { Log.Debug("Pruned senders [{0}] from ReceiverState. Have not been active for [{1}]", string.Join(",", pruneResult.prunedSenders), Settings.PruneInterval); } }); }
protected void ConfirmDelivery() { if (!IsCurrentMessageConfirmable) { Log.Warning("Attempted to confirm non-confirmable message {0}." + Environment.NewLine + "{1} needs to implement the IConfirmableMessage interface or be wrapped in a " + "ConfirmableMessageEnvelope in order to be de-duplicated by this actor." + Environment.NewLine + "Please see https://devops.petabridge.com/articles/msgdelivery/deduplication.html#iconfirmablemessages for more information.", Context.AsInstanceOf <ActorCell>().CurrentMessage, Context.AsInstanceOf <ActorCell>().CurrentMessage.GetType()); return; } Debug.Assert(CurrentConfirmationId != null, nameof(CurrentConfirmationId) + " != null"); _receiverState = _receiverState.ConfirmProcessing(CurrentConfirmationId.Value, CurrentSenderId); // Persist the current confirmation state Persist(new Confirmation(CurrentConfirmationId.Value, CurrentSenderId), confirmation => { if (LastSequenceNr % Settings.TakeSnapshotEveryNMessages == 0) { SaveSnapshot(_receiverState.ToSnapshot()); } }); }
public void ReceiveMsg() { this._currentState = LogStateTable["PrepareState"]; this._currentState.Execute(); if (this.DataObjs.Count > 0) { this._currentState = LogStateTable["ProcessState"]; this._currentState.Execute(); } }
protected DeDuplicatingReceiveActor(DeDuplicatingReceiverSettings settings) { // force the serializer settings to be injected, if they haven't been already ExtraPersistence.For(Context.System); Settings = settings; _receiverState = CreateInitialState(settings); _pruneTask = CreatePruneTask(); BuiltInRecovers(); BuiltInCommands(); }
public void Should_ChangeToInitialState_When_ExecutedInitialMethod() { //Arrange string expect = "InitialState", actual = string.Empty; //Act this._ctx.Initial(); IReceiverState currentState = this._ctx.CurrentState; actual = currentState.StateName; //Assert actual.Should().NotBeEmpty().And.Be(expect); }
/// <summary> /// INTERNAL API. /// All of the built-in recovery methods needed to re-create this actor's state. /// </summary> private void BuiltInRecovers() { // Confirming a single message from a single sender Recover <Confirmation>(c => { _receiverState.ConfirmProcessing(c.ConfirmationId, c.SenderId); }); Recover <SnapshotOffer>(snapshotOffer => { if (snapshotOffer.Snapshot is IReceiverStateSnapshot receiverStateSnapshot) { _receiverState = _receiverState.FromSnapshot(receiverStateSnapshot); } else { Log.Error("{0} should not be used to persist user-" + "defined state under any circumstances. " + "Tried to recover snapshot of type [{1}]. Read the documentation.", GetType(), snapshotOffer.Snapshot.GetType()); } }); }
protected void ConfirmDelivery() { if (!IsCurrentMessageConfirmable) { Log.Warning("Attempted to confirm non-confirmable message {0}", Context.AsInstanceOf <ActorCell>().CurrentMessage); return; } Debug.Assert(CurrentConfirmationId != null, nameof(CurrentConfirmationId) + " != null"); _receiverState = _receiverState.ConfirmProcessing(CurrentConfirmationId.Value, CurrentSenderId); // Persist the current confirmation state Persist(new Confirmation(CurrentConfirmationId.Value, CurrentSenderId), confirmation => { if (LastSequenceNr % Settings.TakeSnapshotEveryNMessages == 0) { SaveSnapshot(_receiverState.ToSnapshot()); } }); }
public void Initial() { this._currentState = LogStateTable["InitialState"]; this._currentState.Execute(); }
public PrunedResult(IReceiverState newState, IReadOnlyList <string> prunedSenders) { this.newState = newState; this.prunedSenders = prunedSenders; }