public interface PersistentView extends Actor, Snapshotter, Stash, StashFactory, PersistenceIdentity, PersistenceRecovery, ActorLogging
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
- autoUpdate()
for turning automated updates on or off
- autoUpdateReplayMax()
for limiting the number of replayed messages per view update cycle
Modifier and Type | Interface and Description |
---|---|
static class |
PersistentView.ScheduledUpdate
Deprecated.
|
static class |
PersistentView.ScheduledUpdate$
Deprecated.
|
static interface |
PersistentView.State
Deprecated.
|
Actor.emptyBehavior$, Actor.ignoringBehavior$
Modifier and Type | Method and Description |
---|---|
void |
aroundPreStart()
Deprecated.
INTERNAL API.
|
void |
aroundReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive,
java.lang.Object message)
Deprecated.
INTERNAL API.
|
boolean |
autoUpdate()
Deprecated.
If
true , this view automatically updates itself with an interval specified by autoUpdateInterval . |
scala.concurrent.duration.FiniteDuration |
autoUpdateInterval()
Deprecated.
The interval for automated updates.
|
long |
autoUpdateReplayMax()
Deprecated.
The maximum number of messages to replay per update.
|
void |
changeState(PersistentView.State state)
Deprecated.
|
java.lang.Object |
ignoreRemainingReplay(java.lang.Throwable cause)
Deprecated.
|
boolean |
isPersistent()
Deprecated.
If
true , the currently processed message was persisted (is sent from the Journal). |
ActorRef |
journal()
Deprecated.
|
long |
lastSequenceNr()
Deprecated.
Highest received sequence number so far or
0L if this actor hasn't replayed
any persistent events yet. |
void |
onReplayError(java.lang.Throwable cause)
Deprecated.
Called whenever a message replay fails.
|
void |
postStop()
Deprecated.
User overridable callback.
|
void |
preRestart(java.lang.Throwable reason,
scala.Option<java.lang.Object> message)
Deprecated.
User overridable callback: '''By default it disposes of all children and then calls
postStop() .''' |
void |
preStart()
Deprecated.
Triggers an initial recovery, starting form a snapshot, if any, and replaying at most
autoUpdateReplayMax
messages (following that snapshot). |
Recovery |
recovery()
Deprecated.
Called when the persistent actor is started for the first time.
|
java.lang.Object |
recoveryStarted(long replayMax)
Deprecated.
|
java.lang.Object |
replayStarted(boolean await)
Deprecated.
|
void |
setLastSequenceNr(long value)
Deprecated.
|
long |
snapshotSequenceNr()
Deprecated.
Returns
lastSequenceNr . |
ActorRef |
snapshotStore()
Deprecated.
Snapshot store plugin actor.
|
java.lang.String |
snapshotterId()
Deprecated.
Returns
viewId . |
void |
startRecovery(Recovery recovery)
Deprecated.
|
void |
updateLastSequenceNr(PersistentRepr persistent)
Deprecated.
|
java.lang.String |
viewId()
Deprecated.
View id is used as identifier for snapshots performed by this
PersistentView . |
deleteSnapshot, deleteSnapshots, loadSnapshot, saveSnapshot
aroundPostRestart, aroundPostStop, aroundPreRestart, context, postRestart, receive, self, sender, supervisorStrategy, unhandled
actorCell, clearStash, context, enqueueFirst, mailbox, prepend, self, stash, unstash, unstashAll, unstashAll
createStash
journalPluginId, persistenceId, snapshotPluginId
log
ActorRef journal()
ActorRef snapshotStore()
Snapshotter
snapshotStore
in interface Snapshotter
java.lang.String viewId()
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* id set as viewId
than persistenceId
,
although it is possible to share the same id with an PersistentActor
- for example to decide about snapshots
based on some average or sum, calculated by this view.
Example:
class SummingView extends PersistentView {
override def persistenceId = "count-123"
override def viewId = "count-123-sum" // this view is performing summing,
// so this view's snapshots reside under the "-sum" suffixed id
// ...
}
java.lang.String snapshotterId()
viewId
.snapshotterId
in interface Snapshotter
boolean isPersistent()
true
, the currently processed message was persisted (is sent from the Journal).
If false
, the currently processed message comes from another actor (from "user-land").boolean autoUpdate()
true
, this view automatically updates itself with an interval specified by autoUpdateInterval
.
If false
, applications must explicitly update this view by sending Update
requests. The default
value can be configured with the akka.persistence.view.auto-update
configuration key. This method
can be overridden by implementation classes to return non-default values.scala.concurrent.duration.FiniteDuration autoUpdateInterval()
akka.persistence.view.auto-update-interval
configuration key. This method can be
overridden by implementation classes to return non-default values.long autoUpdateReplayMax()
akka.persistence.view.auto-update-replay-max
configuration key. This method can be overridden by
implementation classes to return non-default values.long lastSequenceNr()
0L
if this actor hasn't replayed
any persistent events yet.long snapshotSequenceNr()
lastSequenceNr
.snapshotSequenceNr
in interface Snapshotter
void setLastSequenceNr(long value)
void updateLastSequenceNr(PersistentRepr persistent)
Recovery recovery()
PersistenceRecovery
Recovery
object defines how the Actor will recover its persistent state before
handling the first incoming message.
To skip recovery completely return Recovery.none
.
recovery
in interface PersistenceRecovery
void preStart()
autoUpdateReplayMax
messages (following that snapshot).void startRecovery(Recovery recovery)
void aroundReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive, java.lang.Object message)
aroundReceive
in interface Actor
receive
- current behavior.message
- current message.void aroundPreStart()
aroundPreStart
in interface Actor
void preRestart(java.lang.Throwable reason, scala.Option<java.lang.Object> message)
Actor
postStop()
.'''preRestart
in interface Actor
preRestart
in interface UnrestrictedStash
reason
- the Throwable that caused the restart to happenmessage
- optionally the current message the actor processed when failing, if applicable
Is called on a crashed Actor right BEFORE it is restarted to allow clean
up of resources before Actor is terminated.void postStop()
Actor
postStop
in interface Actor
postStop
in interface UnrestrictedStash
void onReplayError(java.lang.Throwable cause)
PersistentView
will not stop or throw exception due to this.
It will try again on next update.cause
- (undocumented)void changeState(PersistentView.State state)
java.lang.Object recoveryStarted(long replayMax)
java.lang.Object replayStarted(boolean await)
java.lang.Object ignoreRemainingReplay(java.lang.Throwable cause)