예제 #1
0
        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);
                }
            });
        }
예제 #2
0
        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());
                }
            });
        }
예제 #3
0
        public void ReceiveMsg()
        {
            this._currentState = LogStateTable["PrepareState"];
            this._currentState.Execute();

            if (this.DataObjs.Count > 0)
            {
                this._currentState = LogStateTable["ProcessState"];
                this._currentState.Execute();
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
        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);
        }
예제 #6
0
 /// <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());
         }
     });
 }
예제 #7
0
        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());
                }
            });
        }
예제 #8
0
 public void Initial()
 {
     this._currentState = LogStateTable["InitialState"];
     this._currentState.Execute();
 }
예제 #9
0
 public PrunedResult(IReceiverState newState, IReadOnlyList <string> prunedSenders)
 {
     this.newState      = newState;
     this.prunedSenders = prunedSenders;
 }