akka.persistence
Class UntypedPersistentActor

java.lang.Object
  extended by akka.actor.UntypedActor
      extended by akka.persistence.UntypedPersistentActor
All Implemented Interfaces:
Actor, Stash, StashFactory, StashSupport, UnrestrictedStash, RequiresMessageQueue<DequeBasedMessageQueueSemantics>, Eventsourced, ProcessorImpl, Recovery, Snapshotter
Direct Known Subclasses:
UntypedEventsourcedProcessor, UntypedPersistentActorWithAtLeastOnceDelivery

public abstract class UntypedPersistentActor
extends UntypedActor
implements ProcessorImpl, 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
UntypedPersistentActor()
           
 
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.
 void onReceive(java.lang.Object message)
          To be implemented by concrete UntypedActor, this defines the behavior of the UntypedActor.
abstract  void onReceiveCommand(java.lang.Object msg)
          Java API: command handler.
abstract  void onReceiveRecover(java.lang.Object msg)
          Java API: recovery handler that receives persisted events during recovery.
<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, scala.Function1<A,scala.runtime.BoxedUnit> handler)
          JAVA API: asynchronously persists events in specified order.
 scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receiveCommand()
           
 scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receiveRecover()
           
 
Methods inherited from class akka.actor.UntypedActor
getContext, getSelf, getSender, postRestart, postStop, preRestart, preStart, receive, supervisorStrategy, unhandled
 
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, 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, receive, 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

UntypedPersistentActor

public UntypedPersistentActor()
Method Detail

onReceive

public final void onReceive(java.lang.Object message)
Description copied from class: UntypedActor
To be implemented by concrete UntypedActor, this defines the behavior of the UntypedActor.

Specified by:
onReceive in class UntypedActor
Parameters:
message - (undocumented)

receiveRecover

public final scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receiveRecover()
Specified by:
receiveRecover in interface Eventsourced

receiveCommand

public final scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receiveCommand()
Specified by:
receiveCommand in interface Eventsourced

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 onReceiveCommand.

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 persist and executing it's handler. This asynchronous, non-stashing, version of of persist should be used when you favor throughput over the "command-2 only processed after command-1 effects' have been applied" guarantee, which is provided by the plain persist method.

An event handler may close over persistent actor state and modify it. The sender 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.

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

persistAsync

public final <A> void persistAsync(java.lang.Iterable<A> events,
                                   scala.Function1<A,scala.runtime.BoxedUnit> 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

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

onReceiveRecover

public abstract void onReceiveRecover(java.lang.Object msg)
Java API: recovery handler that receives persisted events during recovery. If a state snapshot has been captured and saved, this handler will receive a SnapshotOffer message followed by events that are younger than the offered snapshot.

This handler must not have side-effects other than changing persistent actor state i.e. it should not perform actions that may fail, such as interacting with external services, for example.

If recovery fails, the actor will be stopped. This can be customized by handling RecoveryFailure.

Parameters:
msg - (undocumented)
See Also:
Recover

onReceiveCommand

public abstract void onReceiveCommand(java.lang.Object msg)
Java API: command handler. Typically validates commands against current state (and/or by communication with other actors). On successful validation, one or more events are derived from a command and these events are then persisted by calling persist. Commands sent to event sourced persistent actors must not be Persistent or PersistentBatch messages. In this case an UnsupportedOperationException is thrown by the persistent actor.

Parameters:
msg - (undocumented)