akka.persistence
Interface PersistentView

All Superinterfaces:
Actor, Recovery, RequiresMessageQueue<DequeBasedMessageQueueSemantics>, Snapshotter, Stash, StashFactory, StashSupport, UnrestrictedStash
All Known Implementing Classes:
AbstractPersistentView, UntypedPersistentView

public interface PersistentView
extends Actor, Recovery

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

- autoUpdate for turning automated updates on or off - autoUpdateReplayMax for limiting the number of replayed messages per view update cycle


Nested Class Summary
 
Nested classes/interfaces inherited from interface akka.persistence.Recovery
Recovery.State
 
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$
 
Method Summary
 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.
 Recovery.State idle()
          When receiving an Update request, switches to replayStarted state and triggers an incremental message replay.
 boolean isPersistent()
          If true, the currently processed message was persisted (is sent from the Journal).
 void onReplayComplete(boolean await)
          Switches to idle state and schedules the next update if autoUpdate returns true.
 void onReplayFailure(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive, boolean await, java.lang.Throwable cause)
          INTERNAL API.
 void onReplaySuccess(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive, boolean await)
          INTERNAL API.
 void postStop()
          User overridable callback.
 void preRestart(java.lang.Throwable reason, scala.Option<java.lang.Object> message)
          User overridable callback: '''By default it disposes of all children and then calls postStop().'''
 void preStart()
          Triggers an initial recovery, starting form a snapshot, if any, and replaying at most autoUpdateReplayMax messages (following that snapshot).
 java.lang.Object replayStarted(boolean await)
          INTERNAL API.
 void runReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive, Persistent msg)
          INTERNAL API WARNING: This implementation UNWRAPS PERSISTENT() before delivering to the receive block.
 scala.Option<Cancellable> schedule()
           
 java.lang.String snapshotterId()
          Returns viewId.
 java.lang.String viewId()
          View id is used as identifier for snapshots performed by this PersistentView.
 akka.persistence.PersistenceSettings.view$ viewSettings()
           
 
Methods inherited from interface akka.persistence.Recovery
_currentPersistent, _currentState, _lastSequenceNr, _recoveryFailureCause, _recoveryFailureMessage, aroundReceive, currentPersistentMessage, extension, getCurrentPersistentMessage, journal, lastSequenceNr, persistenceId, prepareRestart, processorId, receiverStash, recoveryPending, recoveryStarted, replayFailed, snapshotSequenceNr, updateLastSequenceNr, updateLastSequenceNr, withCurrentPersistent
 
Methods inherited from interface akka.persistence.Snapshotter
deleteSnapshot, deleteSnapshots, loadSnapshot, saveSnapshot, snapshotStore
 
Methods inherited from interface akka.actor.Actor
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, context, postRestart, receive, self, sender, supervisorStrategy, unhandled
 
Methods inherited from interface akka.actor.StashSupport
actorCell, capacity, clearStash, context, enqueueFirst, mailbox, prepend, self, stash, theStash, unstash, unstashAll, unstashAll
 
Methods inherited from interface akka.actor.StashFactory
createStash
 

Method Detail

replayStarted

java.lang.Object replayStarted(boolean await)
INTERNAL API.

Extends the replayStarted state of Recovery with logic to handle Update requests sent by users.

Specified by:
replayStarted in interface Recovery
Parameters:
await - (undocumented)
Returns:
(undocumented)

idle

Recovery.State idle()
When receiving an Update request, switches to replayStarted state and triggers an incremental message replay. Invokes the actor's current behavior for any other received message.

Returns:
(undocumented)

onReplaySuccess

void onReplaySuccess(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive,
                     boolean await)
INTERNAL API.

Specified by:
onReplaySuccess in interface Recovery
Parameters:
receive - (undocumented)
await - (undocumented)

onReplayFailure

void onReplayFailure(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive,
                     boolean await,
                     java.lang.Throwable cause)
INTERNAL API.

Specified by:
onReplayFailure in interface Recovery
Parameters:
receive - (undocumented)
await - (undocumented)
cause - (undocumented)

onReplayComplete

void onReplayComplete(boolean await)
Switches to idle state and schedules the next update if autoUpdate returns true.

Parameters:
await - (undocumented)

runReceive

void runReceive(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive,
                Persistent msg)
INTERNAL API WARNING: This implementation UNWRAPS PERSISTENT() before delivering to the receive block.

Specified by:
runReceive in interface Recovery
Parameters:
receive - (undocumented)
msg - (undocumented)

viewSettings

akka.persistence.PersistenceSettings.view$ viewSettings()

schedule

scala.Option<Cancellable> schedule()

viewId

java.lang.String viewId()
View id is 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* 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

      // ...
    }
 

Returns:
(undocumented)

snapshotterId

java.lang.String snapshotterId()
Returns viewId.

Specified by:
snapshotterId in interface Snapshotter
Returns:
(undocumented)

isPersistent

boolean isPersistent()
If 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").

Returns:
(undocumented)

autoUpdate

boolean autoUpdate()
If 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.

Returns:
(undocumented)

autoUpdateInterval

scala.concurrent.duration.FiniteDuration autoUpdateInterval()
The interval for automated updates. The default value can be configured with the akka.persistence.view.auto-update-interval configuration key. This method can be overridden by implementation classes to return non-default values.

Returns:
(undocumented)

autoUpdateReplayMax

long autoUpdateReplayMax()
The maximum number of messages to replay per update. The default value can be configured with the akka.persistence.view.auto-update-replay-max configuration key. This method can be overridden by implementation classes to return non-default values.

Returns:
(undocumented)

preStart

void preStart()
Triggers an initial recovery, starting form a snapshot, if any, and replaying at most autoUpdateReplayMax messages (following that snapshot).

Specified by:
preStart in interface Actor

preRestart

void preRestart(java.lang.Throwable reason,
                scala.Option<java.lang.Object> message)
Description copied from interface: Actor
User overridable callback: '''By default it disposes of all children and then calls postStop().'''

Specified by:
preRestart in interface Actor
Specified by:
preRestart in interface UnrestrictedStash
Parameters:
reason - the Throwable that caused the restart to happen
message - 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.

postStop

void postStop()
Description copied from interface: Actor
User overridable callback.

Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation.

Specified by:
postStop in interface Actor
Specified by:
postStop in interface UnrestrictedStash