akka.persistence
Interface View

All Superinterfaces:
Actor, Recovery, RequiresMessageQueue<DequeBasedMessageQueueSemantics>, Snapshotter, Stash, UnrestrictedStash
All Known Implementing Classes:
AbstractView, UntypedView

public interface View
extends Actor, Recovery

A view replicates the persistent message stream of a processor. Implementation classes receive the message stream as Persistent messages. These messages can be processed to update internal state in order to maintain an (eventual consistent) view of the state of the corresponding processor. A view can also run on a different node, provided that a replicated journal is used. Implementation classes reference a processor by implementing processorId.

Views can also store snapshots of internal state by calling Snapshotter.saveSnapshot(java.lang.Object). The snapshots of a view are independent of those of the referenced processor. 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

Views can also use channels to communicate with destinations in the same way as processors can do.


Nested Class Summary
 
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$
 
Method Summary
 java.lang.String _viewId()
           
 akka.actor.ActorCell actorCell()
           
 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.
 int capacity()
           
 scala.collection.immutable.Vector<Envelope> clearStash()
          INTERNAL API.
 ActorContext context()
          INTERNAL API.
 void enqueueFirst(Envelope envelope)
          Enqueues envelope at the first position in the mailbox.
 Recovery.State idle()
          When receiving an Update request, switches to replayStarted state and triggers an incremental message replay.
 DequeBasedMessageQueueSemantics mailbox()
          INTERNAL API.
 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 prepend(scala.collection.immutable.Seq<Envelope> others)
          Prepends others to this stash.
 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.
 scala.Option<Cancellable> schedule()
           
 ActorRef self()
          INTERNAL API.
 java.lang.String snapshotterId()
          Returns viewId.
 void stash()
          Adds the current message (the message that the actor received last) to the actor's stash.
 scala.collection.immutable.Vector<Envelope> theStash()
           
 void unstash()
          Prepends the oldest message in the stash to the mailbox, and then removes that message from the stash.
 void unstashAll()
          Prepends all messages in the stash to the mailbox, and then clears the stash.
 void unstashAll(scala.Function1<java.lang.Object,java.lang.Object> filterPredicate)
          INTERNAL API.
 java.lang.String viewId()
          View id.
 akka.persistence.PersistenceSettings.view$ viewSettings()
           
 
Methods inherited from interface akka.persistence.Recovery
_currentPersistent, _currentState, _lastSequenceNr, _recoveryFailureCause, _recoveryFailureMessage, aroundReceive, currentPersistentMessage, extension, getCurrentPersistentMessage, journal, lastSequenceNr, prepareRestart, processorId, receiverStash, recoveryPending, recoveryStarted, replayFailed, snapshotSequenceNr
 
Methods inherited from interface akka.persistence.Snapshotter
deleteSnapshot, deleteSnapshots, loadSnapshot, saveSnapshot, snapshotStore
 
Methods inherited from interface akka.actor.Actor
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, context, noSender, postRestart, receive, self, sender, supervisorStrategy, unhandled
 

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 - if true processing of further messages will be delayed until replay completes, otherwise, the actor's behavior is invoked immediately with these messages.

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.


onReplaySuccess

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

Specified by:
onReplaySuccess in interface Recovery
Parameters:
receive - the actor's current behavior.
await - awaitReplay value of the calling replayStarted state.

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 - the actor's current behavior.
await - awaitReplay value of the calling replayStarted state.
cause - failure cause.

onReplayComplete

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


_viewId

java.lang.String _viewId()

viewSettings

akka.persistence.PersistenceSettings.view$ viewSettings()

schedule

scala.Option<Cancellable> schedule()

viewId

java.lang.String viewId()
View id. Defaults to this view's path and can be overridden.


snapshotterId

java.lang.String snapshotterId()
Returns viewId.

Specified by:
snapshotterId in interface Snapshotter

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.


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.


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.


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

context

ActorContext context()
INTERNAL API.

Context of the actor that uses this stash.


self

ActorRef self()
INTERNAL API.

Self reference of the actor that uses this stash.


theStash

scala.collection.immutable.Vector<Envelope> theStash()

actorCell

akka.actor.ActorCell actorCell()

capacity

int capacity()

mailbox

DequeBasedMessageQueueSemantics mailbox()
INTERNAL API.

The actor's deque-based message queue. mailbox.queue is the underlying Deque.


stash

void stash()
Adds the current message (the message that the actor received last) to the actor's stash.

Throws:
StashOverflowException - in case of a stash capacity violation
java.lang.IllegalStateException - if the same message is stashed more than once

prepend

void prepend(scala.collection.immutable.Seq<Envelope> others)
Prepends others to this stash. This method is optimized for a large stash and small others.


unstash

void unstash()
Prepends the oldest message in the stash to the mailbox, and then removes that message from the stash.

Messages from the stash are enqueued to the mailbox until the capacity of the mailbox (if any) has been reached. In case a bounded mailbox overflows, a MessageQueueAppendFailedException is thrown.

The unstashed message is guaranteed to be removed from the stash regardless if the unstash() call successfully returns or throws an exception.


unstashAll

void unstashAll()
Prepends all messages in the stash to the mailbox, and then clears the stash.

Messages from the stash are enqueued to the mailbox until the capacity of the mailbox (if any) has been reached. In case a bounded mailbox overflows, a MessageQueueAppendFailedException is thrown.

The stash is guaranteed to be empty after calling unstashAll().


unstashAll

void unstashAll(scala.Function1<java.lang.Object,java.lang.Object> filterPredicate)
INTERNAL API.

Prepends selected messages in the stash, applying filterPredicate, to the mailbox, and then clears the stash.

Messages from the stash are enqueued to the mailbox until the capacity of the mailbox (if any) has been reached. In case a bounded mailbox overflows, a MessageQueueAppendFailedException is thrown.

The stash is guaranteed to be empty after calling unstashAll(Any => Boolean).

Parameters:
filterPredicate - only stashed messages selected by this predicate are prepended to the mailbox.

clearStash

scala.collection.immutable.Vector<Envelope> clearStash()
INTERNAL API.

Clears the stash and and returns all envelopes that have not been unstashed.


enqueueFirst

void enqueueFirst(Envelope envelope)
Enqueues envelope at the first position in the mailbox. If the message contained in the envelope is a Terminated message, it will be ensured that it can be re-received by the actor.