public interface PersistentView extends akka.actor.Actor, Snapshotter, akka.actor.Stash, akka.actor.StashFactory, PersistenceIdentity, PersistenceRecovery, akka.actor.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 |
static class |
PersistentView.ScheduledUpdate$ |
static interface |
PersistentView.State |
Modifier and Type | Method and Description |
---|---|
long |
_lastSequenceNr() |
void |
aroundPreStart()
INTERNAL API.
|
void |
aroundReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive,
java.lang.Object message)
INTERNAL API.
|
boolean |
autoUpdate()
If
true , this view automatically updates itself with an interval specified by autoUpdateInterval . |
scala.concurrent.duration.FiniteDuration |
autoUpdateInterval()
The interval for automated updates.
|
long |
autoUpdateReplayMax()
The maximum number of messages to replay per update.
|
void |
changeState(PersistentView.State state) |
PersistentView.State |
currentState() |
Persistence |
extension() |
PersistentView.State |
idle()
When receiving an
Update request, switches to replayStarted state and triggers
an incremental message replay. |
java.lang.Object |
ignoreRemainingReplay(java.lang.Throwable cause)
Consumes remaining replayed messages and then throw the exception.
|
akka.actor.StashSupport |
internalStash() |
boolean |
isPersistent()
If
true , the currently processed message was persisted (is sent from the Journal). |
akka.actor.ActorRef |
journal() |
long |
lastSequenceNr()
Highest received sequence number so far or
0L if this actor hasn't replayed
any persistent events yet. |
void |
onReplayError(java.lang.Throwable cause)
Called whenever a message replay fails.
|
void |
postStop() |
void |
preRestart(java.lang.Throwable reason,
scala.Option<java.lang.Object> message) |
void |
preStart()
Triggers an initial recovery, starting form a snapshot, if any, and replaying at most
autoUpdateReplayMax
messages (following that snapshot). |
Recovery |
recovery()
Called when the persistent actor is started for the first time.
|
java.lang.Object |
recoveryStarted(long replayMax) |
java.lang.Object |
replayStarted(boolean await)
Processes replayed messages, if any.
|
scala.Option<akka.actor.Cancellable> |
schedule() |
void |
setLastSequenceNr(long value) |
long |
snapshotSequenceNr()
Returns
lastSequenceNr . |
akka.actor.ActorRef |
snapshotStore()
Snapshot store plugin actor.
|
java.lang.String |
snapshotterId()
Returns
viewId . |
void |
startRecovery(Recovery recovery) |
void |
updateLastSequenceNr(PersistentRepr persistent) |
java.lang.String |
viewId()
View id is used as identifier for snapshots performed by this
PersistentView . |
akka.persistence.PersistenceSettings.view$ |
viewSettings() |
deleteSnapshot, deleteSnapshots, loadSnapshot, saveSnapshot
akka$actor$Actor$_setter_$context_$eq, akka$actor$Actor$_setter_$self_$eq, aroundPostRestart, aroundPostStop, aroundPreRestart, context, postRestart, receive, self, sender, supervisorStrategy, unhandled
akka$actor$StashSupport$_setter_$akka$actor$StashSupport$$capacity_$eq, akka$actor$StashSupport$_setter_$mailbox_$eq, akka$actor$StashSupport$$capacity, akka$actor$StashSupport$$theStash_$eq, akka$actor$StashSupport$$theStash, clearStash, context, mailbox, prepend, self, stash, unstash, unstashAll, unstashAll
journalPluginId, persistenceId, snapshotPluginId
Persistence extension()
akka.persistence.PersistenceSettings.view$ viewSettings()
akka.actor.ActorRef journal()
akka.actor.ActorRef snapshotStore()
Snapshotter
snapshotStore
in interface Snapshotter
scala.Option<akka.actor.Cancellable> schedule()
long _lastSequenceNr()
akka.actor.StashSupport internalStash()
PersistentView.State currentState()
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).preStart
in interface akka.actor.Actor
void startRecovery(Recovery recovery)
void aroundReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive, java.lang.Object message)
aroundReceive
in interface akka.actor.Actor
void aroundPreStart()
aroundPreStart
in interface akka.actor.Actor
void preRestart(java.lang.Throwable reason, scala.Option<java.lang.Object> message)
preRestart
in interface akka.actor.Actor
preRestart
in interface akka.actor.UnrestrictedStash
void postStop()
postStop
in interface akka.actor.Actor
postStop
in interface akka.actor.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)
receive
is invoked with the replayed
events.
If replay succeeds it switches to initializing
state and requests the highest stored sequence
number from the journal.
If replay succeeds the onReplaySuccess
callback method is called, otherwise onReplayError
is called and
remaining replay events are consumed (ignored).
If processing of a replayed event fails, the exception is caught and
stored for later and state is changed to recoveryFailed
.
All incoming messages are stashed when await
is true.
await
- (undocumented)java.lang.Object ignoreRemainingReplay(java.lang.Throwable cause)
cause
- (undocumented)PersistentView.State idle()
Update
request, switches to replayStarted
state and triggers
an incremental message replay. Invokes the actor's current behavior for any other
received message.