Class PersistentView
A view replicates the persistent message stream of a PersistentActor. Implementation classes receive the message stream directly from the Journal. These messages can be processed to update internal state in order to maintain an (eventual consistent) view of the state of the corresponding persistent actor. A persistent view can also run on a different node, provided that a replicated journal is used.
Implementation classes refer to a persistent actors' message stream by implementing persistenceId
with the corresponding (shared) identifier value.
Views can also store snapshots of internal state by calling [[autoUpdate]]. The snapshots of a view are independent of those of the referenced persistent actor. During recovery, a saved snapshot is offered to the view with a SnapshotOffer message, followed by replayed messages, if any, that are younger than the snapshot. Default is to offer the latest saved snapshot.
By default, a view automatically updates itself with an interval returned by autoUpdateInterval
.
This method can be overridden by implementation classes to define a view instance-specific update
interval. The default update interval for all views of an actor system can be configured with the
akka.persistence.view.auto-update-interval
configuration key. Applications may trigger additional
view updates by sending the view Update requests. See also methods
Implements
Inherited Members
Namespace: Akka.Persistence
Assembly: Akka.Persistence.dll
Syntax
public abstract class PersistentView : ActorBase, IInternalActor, ISnapshotter, IPersistentIdentity, IWithUnboundedStash, IActorStash, IRequiresMessageQueue<IUnboundedDequeBasedMessageQueueSemantics>, IPersistenceRecovery
Constructors
| Improve this Doc View SourcePersistentView()
TBD
Declaration
protected PersistentView()
Fields
| Improve this Doc View SourceExtension
TBD
Declaration
protected readonly PersistenceExtension Extension
Field Value
Type | Description |
---|---|
PersistenceExtension |
Properties
| Improve this Doc View SourceAutoUpdateInterval
Time interval to automatic updates. Used only when IsAutoUpdate value is true.
Declaration
public virtual TimeSpan AutoUpdateInterval { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
AutoUpdateReplayMax
The maximum number of messages to replay per update.
Declaration
public virtual long AutoUpdateReplayMax { get; }
Property Value
Type | Description |
---|---|
Int64 |
IsAutoUpdate
If true, this view will update itself automatically within an interval specified by AutoUpdateInterval. If false, application must update this view explicitly with Update requests.
Declaration
public virtual bool IsAutoUpdate { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsPersistent
If true, the currently processed message was persisted - it sent from the Journal. If false, the currently processed message comes from another actor ('/user/*' path).
Declaration
public bool IsPersistent { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsRecovering
Returns true if this persistent view is currently recovering.
Declaration
public bool IsRecovering { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsRecoveryFinished
Returns true if this persistent view has successfully finished recovery.
Declaration
public bool IsRecoveryFinished { get; }
Property Value
Type | Description |
---|---|
Boolean |
Journal
TBD
Declaration
public IActorRef Journal { get; }
Property Value
Type | Description |
---|---|
IActorRef |
JournalPluginId
TBD
Declaration
public string JournalPluginId { get; protected set; }
Property Value
Type | Description |
---|---|
String |
LastSequenceNr
Highest received sequence number so far or 0 it none persistent event has been replayed yet.
Declaration
public long LastSequenceNr { get; }
Property Value
Type | Description |
---|---|
Int64 |
PersistenceId
Id of the persistent entity for which messages should be replayed.
Declaration
public abstract string PersistenceId { get; }
Property Value
Type | Description |
---|---|
String |
Recovery
Called when the persistent view is started for the first time. The returned Recovery object defines how the actor will recover its persistent state before handling the first incoming message.
To skip recovery completely return None.
Declaration
public virtual Recovery Recovery { get; }
Property Value
Type | Description |
---|---|
Recovery |
SnapshotPluginId
TBD
Declaration
public string SnapshotPluginId { get; protected set; }
Property Value
Type | Description |
---|---|
String |
SnapshotSequenceNr
Gets last sequence number.
Declaration
public long SnapshotSequenceNr { get; }
Property Value
Type | Description |
---|---|
Int64 |
SnapshotStore
TBD
Declaration
public IActorRef SnapshotStore { get; }
Property Value
Type | Description |
---|---|
IActorRef |
SnapshotterId
Gets the ViewId.
Declaration
public string SnapshotterId { get; }
Property Value
Type | Description |
---|---|
String |
Stash
TBD
Declaration
public IStash Stash { get; set; }
Property Value
Type | Description |
---|---|
IStash |
ViewId
Used as identifier for snapshots performed by this PersistentView. This allows the View to keep separate snapshots of data than the PersistentActor originating the message stream.
The usual case is to have a different identifiers for ViewId and PersistenceId.
Declaration
public abstract string ViewId { get; }
Property Value
Type | Description |
---|---|
String |
Methods
| Improve this Doc View SourceAroundPreStart()
TBD
Declaration
public override void AroundPreStart()
Overrides
| Improve this Doc View SourceAroundReceive(Receive, Object)
TBD
Declaration
protected override bool AroundReceive(Receive receive, object message)
Parameters
Type | Name | Description |
---|---|---|
Receive | receive | TBD |
Object | message | TBD |
Returns
Type | Description |
---|---|
Boolean | TBD |
DeleteSnapshot(Int64)
Deletes the snapshot identified by sequenceNr
.
The PersistentActor will be notified about the status of the deletion via an DeleteSnapshotSuccess or DeleteSnapshotFailure message.
Declaration
public void DeleteSnapshot(long sequenceNr)
Parameters
Type | Name | Description |
---|---|---|
Int64 | sequenceNr | TBD |
DeleteSnapshots(SnapshotSelectionCriteria)
Deletes all snapshots matching criteria
.
The PersistentActor will be notified about the status of the deletion via an DeleteSnapshotsSuccess or DeleteSnapshotsFailure message.
Declaration
public void DeleteSnapshots(SnapshotSelectionCriteria criteria)
Parameters
Type | Name | Description |
---|---|---|
SnapshotSelectionCriteria | criteria | TBD |
LoadSnapshot(String, SnapshotSelectionCriteria, Int64)
Instructs the snapshot store to load the specified snapshot and send it via an SnapshotOffer to the running PersistentActor.
Declaration
public void LoadSnapshot(string persistenceId, SnapshotSelectionCriteria criteria, long toSequenceNr)
Parameters
Type | Name | Description |
---|---|---|
String | persistenceId | TBD |
SnapshotSelectionCriteria | criteria | TBD |
Int64 | toSequenceNr | TBD |
OnReplayError(Exception)
Called whenever a message replay fails. By default it logs the error. Subclass may override to customize logging. The PersistentView will not stop or throw exception due to this. It will try again on next update.
Declaration
protected virtual void OnReplayError(Exception cause)
Parameters
Type | Name | Description |
---|---|---|
Exception | cause | TBD |
PostStop()
TBD
Declaration
protected override void PostStop()
Overrides
| Improve this Doc View SourcePreRestart(Exception, Object)
TBD
Declaration
protected override void PreRestart(Exception reason, object message)
Parameters
Type | Name | Description |
---|---|---|
Exception | reason | TBD |
Object | message | TBD |
PreStart()
TBD
Declaration
protected override void PreStart()
Overrides
| Improve this Doc View SourceSaveSnapshot(Object)
Saves snapshot
of current ISnapshotter state.
The PersistentActor will be notified about the success or failure of this via an SaveSnapshotSuccess or SaveSnapshotFailure message.
Declaration
public void SaveSnapshot(object snapshot)
Parameters
Type | Name | Description |
---|---|---|
Object | snapshot | TBD |
Unhandled(Object)
TBD
Declaration
protected override void Unhandled(object message)
Parameters
Type | Name | Description |
---|---|---|
Object | message | TBD |