akka.persistence
Class AbstractPersistentActor

java.lang.Object
  extended by akka.actor.AbstractActor
      extended by akka.persistence.AbstractPersistentActor
All Implemented Interfaces:
Actor, Stash, StashFactory, StashSupport, UnrestrictedStash, RequiresMessageQueue<DequeBasedMessageQueueSemantics>, Eventsourced, PersistentActor, ProcessorImpl, Recovery, Snapshotter
Direct Known Subclasses:
AbstractEventsourcedProcessor, AbstractPersistentActorWithAtLeastOnceDelivery

public abstract class AbstractPersistentActor
extends AbstractActor
implements PersistentActor, Eventsourced

Java API: an persistent actor - can be used to implement command or event sourcing.


Nested Class Summary
 
Nested classes/interfaces inherited from interface akka.persistence.Eventsourced
Eventsourced.PendingHandlerInvocation
 
Nested classes/interfaces inherited from interface akka.persistence.Recovery
Recovery.State
 
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$
 
Constructor Summary
AbstractPersistentActor()
           
 
Method Summary
<A> void
defer(A event, Procedure<A> handler)
          Defer the handler execution until all pending handlers have been executed.
<A> void
defer(java.lang.Iterable<A> events, Procedure<A> handler)
          Defer the handler execution until all pending handlers have been executed.
<A> void
persist(A event, Procedure<A> handler)
          Java API: asynchronously persists event.
<A> void
persist(java.lang.Iterable<A> events, Procedure<A> handler)
          Java API: asynchronously persists events in specified order.
<A> void
persistAsync(A event, Procedure<A> handler)
          Java API: asynchronously persists event.
<A> void
persistAsync(java.lang.Iterable<A> events, Procedure<A> handler)
          Java API: asynchronously persists events in specified order.
 scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
          This defines the initial actor behavior, it must return a partial function with the actor logic.
 
Methods inherited from class akka.actor.AbstractActor
emptyBehavior, getContext, receive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface akka.persistence.Eventsourced
aroundPreRestart, aroundReceive, currentState, defer, defer, flushBatch, initialBehavior, pendingInvocations, pendingStashingPersistInvocations, persist, persist, persistAsync, persistAsync, persistingEvents, postStop, preRestart, processingCommands, processorStash, receiveCommand, receiveRecover, recovering, recoveryBehavior, resequenceableEventBatch, unstashAll, useProcessorBatching
 
Methods inherited from interface akka.persistence.ProcessorImpl
_persistenceId, aroundPostStop, aroundPreStart, deleteMessage, deleteMessage, deleteMessages, deleteMessages, flushJournalBatch, initializing, instanceId, nextSequenceNr, onRecoveryCompleted, onRecoveryFailure, onReplayFailure, onReplaySuccess, preRestartDefault, preStart, processing, processorBatch, processorId, recoveryFinished, recoveryRunning, sequenceNr, snapshotterId, unhandled, unstashFilterPredicate
 
Methods inherited from interface akka.persistence.Recovery
_currentPersistent, _currentState, _lastSequenceNr, _recoveryFailureCause, _recoveryFailureMessage, currentPersistentMessage, extension, getCurrentPersistentMessage, journal, lastSequenceNr, persistenceId, prepareRestart, receiverStash, recoveryPending, recoveryStarted, replayFailed, replayStarted, runReceive, snapshotSequenceNr, updateLastSequenceNr, updateLastSequenceNr, withCurrentPersistent
 
Methods inherited from interface akka.persistence.Snapshotter
deleteSnapshot, deleteSnapshots, loadSnapshot, saveSnapshot, snapshotStore
 
Methods inherited from interface akka.actor.Actor
aroundPostRestart, context, postRestart, self, sender, supervisorStrategy
 
Methods inherited from interface akka.actor.StashSupport
actorCell, capacity, clearStash, context, enqueueFirst, mailbox, prepend, self, stash, theStash, unstash, unstashAll
 
Methods inherited from interface akka.actor.StashFactory
createStash
 

Constructor Detail

AbstractPersistentActor

public AbstractPersistentActor()
Method Detail

persist

public final <A> void persist(A event,
                              Procedure<A> handler)
Java API: asynchronously persists event. On successful persistence, handler is called with the persisted event. It is guaranteed that no new commands will be received by a persistent actor between a call to persist and the execution of its handler. This also holds for multiple persist calls per received command. Internally, this is achieved by stashing new commands and unstashing them when the event has been persisted and handled. The stash used for that is an internal stash which doesn't interfere with the inherited user stash.

An event handler may close over persistent actor state and modify it. The getSender() of a persisted event is the sender of the corresponding command. This means that one can reply to a command sender within an event handler.

Within an event handler, applications usually update persistent actor state using persisted event data, notify listeners and reply to command senders.

If persistence of an event fails, the persistent actor will be stopped. This can be customized by handling PersistenceFailure in receiveCommand.

Parameters:
event - event to be persisted.
handler - handler for each persisted event

persist

public final <A> void persist(java.lang.Iterable<A> events,
                              Procedure<A> handler)
Java API: asynchronously persists events in specified order. This is equivalent to calling persist[A](event: A, handler: Procedure[A]) multiple times with the same handler, except that events are persisted atomically with this method.

Parameters:
events - events to be persisted.
handler - handler for each persisted events

persistAsync

public final <A> void persistAsync(A event,
                                   Procedure<A> handler)
Java API: asynchronously persists event. On successful persistence, handler is called with the persisted event.

Unlike persist the persistent actor will continue to receive incomming commands between the call to persistAsync and executing it's handler. This asynchronous, non-stashing, version of of persist should be used when you favor throughput over the strict ordering guarantees that persist guarantees.

If persistence of an event fails, the persistent actor will be stopped. This can be customized by handling PersistenceFailure in receiveCommand.

Parameters:
event - event to be persisted
handler - handler for each persisted event

defer

public final <A> void defer(A event,
                            Procedure<A> handler)
Defer the handler execution until all pending handlers have been executed. Allows to define logic within the actor, which will respect the invocation-order-guarantee in respect to persistAsync calls. That is, if persistAsync was invoked before defer, the corresponding handlers will be invoked in the same order as they were registered in.

This call will NOT result in event being persisted, please use persist or persistAsync, if the given event should possible to replay.

If there are no pending persist handler calls, the handler will be called immediatly.

In the event of persistence failures (indicated by PersistenceFailure messages being sent to the PersistentActor, you can handle these messages, which in turn will enable the deferred handlers to run afterwards. If persistence failure messages are left unhandled, the default behavior is to stop the Actor, thus the handlers will not be run.

Parameters:
event - event to be handled in the future, when preceeding persist operations have been processes
handler - handler for the given event

defer

public final <A> void defer(java.lang.Iterable<A> events,
                            Procedure<A> handler)
Defer the handler execution until all pending handlers have been executed. Allows to define logic within the actor, which will respect the invocation-order-guarantee in respect to persistAsync calls. That is, if persistAsync was invoked before defer, the corresponding handlers will be invoked in the same order as they were registered in.

This call will NOT result in event being persisted, please use persist or persistAsync, if the given event should possible to replay.

If there are no pending persist handler calls, the handler will be called immediatly.

In the event of persistence failures (indicated by PersistenceFailure messages being sent to the PersistentActor, you can handle these messages, which in turn will enable the deferred handlers to run afterwards. If persistence failure messages are left unhandled, the default behavior is to stop the Actor, thus the handlers will not be run.

Parameters:
events - event to be handled in the future, when preceeding persist operations have been processes
handler - handler for each event

persistAsync

public final <A> void persistAsync(java.lang.Iterable<A> events,
                                   Procedure<A> handler)
Java API: asynchronously persists events in specified order. This is equivalent to calling persistAsync[A](event: A)(handler: A => Unit) multiple times with the same handler, except that events are persisted atomically with this method.

Parameters:
events - events to be persisted
handler - handler for each persisted events

receive

public scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
Description copied from interface: Actor
This defines the initial actor behavior, it must return a partial function with the actor logic.

Specified by:
receive in interface Actor
Specified by:
receive in interface PersistentActor
Overrides:
receive in class AbstractActor
Returns:
(undocumented)