protected DomainEventSourcedActor(IConstructAggregates aggregateConstructor, IConstructSnapshots snapshotsConstructor, ISnapshotsPersistencePolicy policy) { _snapshotsConstructor = snapshotsConstructor; _snapshotsPolicy = policy; _snapshotsSaveTracker = (policy as ISnapshotsSavePolicy).Tracking; _snapshotsDeleteTracker = (policy as ISnapshotsDeletePolicy).Tracking; PersistenceId = Self.Path.Name; Id = EntityActorName.Parse <T>(Self.Path.Name).Id; State = (T)aggregateConstructor.Build(typeof(T), Id, null); Monitor = new ActorMonitor(Context, typeof(T).Name); Behavior = new BehaviorQueue(Become); DefaultBehavior(); Recover <DomainEvent>(e => State.Apply(e)); Recover <SnapshotOffer>(offer => { _snapshotsPolicy.MarkSnapshotApplied(offer.Metadata.SequenceNr); State = (T)aggregateConstructor.Build(typeof(T), Id, (IMemento)offer.Snapshot); Log.Debug("Built state from snapshot #{snapshotNum}", offer.Metadata.SequenceNr); }); Recover <RecoveryCompleted>(message => { Log.Debug("Recovery completed"); NotifyPersistenceWatchers(message); }); }
public AggregateActor() { Behavior = new BehaviorQueue(Become); Behavior.Become(AwaitingCommandBehavior, nameof(AwaitingCommandBehavior)); PersistenceId = Self.Path.Name; Id = EntityActorName.Parse <TAggregate>(Self.Path.Name).Id; var aggregateExtensions = Context.System.GetAggregatesExtension(); var dependencies = aggregateExtensions.GetDependencies <TAggregate>(); Aggregate = dependencies.AggregateFactory.Build(); Recover <DomainEvent>(e => Aggregate.Apply(e)); }
public ProcessActor(IProcess <TState> process, IProcessStateFactory <TState> processStateFactory) { Process = process; Monitor = new ActorMonitor(Context, "Process" + typeof(TState).Name); Behavior = new BehaviorQueue(Become); if (!EntityActorName.TryParseId(Self.Path.Name, out var id)) { throw new BadNameFormatException(); } Id = id; _publisher = Context.System.GetTransport(); _processStateFactory = processStateFactory; _log = Context.GetSeriLogger(); _exceptionOnTransit = ProcessManagerActorConstants.ExceptionOnTransit(Self.Path.Name); _producedCommand = ProcessManagerActorConstants.ProcessProduceCommands(Self.Path.Name); _stateActorSelection = Context.System.ActorSelection(ProcessStateActorSelection); Behavior.Become(InitializingBehavior, nameof(InitializingBehavior)); }