akka.actor
Class AbstractFSM<S,D>

java.lang.Object
  extended by akka.actor.AbstractFSM<S,D>
All Implemented Interfaces:
Actor, ActorLogging, FSM<S,D>, Listeners
Direct Known Subclasses:
AbstractLoggingFSM

public abstract class AbstractFSM<S,D>
extends java.lang.Object
implements FSM<S,D>

Java API: compatible with lambda expressions

Finite State Machine actor abstract base class.

This is an EXPERIMENTAL feature and is subject to change until it has received more real world testing.


Nested Class Summary
 
Nested classes/interfaces inherited from interface akka.actor.FSM
FSM.$minus$greater$, FSM.CurrentState<S>, FSM.CurrentState$, FSM.Event<D>, FSM.Event$, FSM.Failure, FSM.Failure$, FSM.LogEntry<S,D>, FSM.LogEntry$, FSM.Normal$, FSM.NullFunction$, FSM.Reason, FSM.Shutdown$, FSM.State<S,D>, FSM.State$, FSM.StateTimeout$, FSM.StopEvent<S,D>, FSM.StopEvent$, FSM.SubscribeTransitionCallBack, FSM.SubscribeTransitionCallBack$, FSM.TimeoutMarker, FSM.TimeoutMarker$, FSM.Timer, FSM.Timer$, FSM.TransformHelper, FSM.Transition<S>, FSM.Transition$, FSM.UnsubscribeTransitionCallBack, FSM.UnsubscribeTransitionCallBack$
 
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$
 
Constructor Summary
AbstractFSM()
           
 
Method Summary
 FSM.State<S,D> goTo(S nextStateName)
          Produce transition to other state.
 FSMStateFunctionBuilder<S,D> matchAnyEvent(FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<DT extends D>
UnitPFBuilder<D>
matchData(java.lang.Class<DT> dataType, FI.TypedPredicate<DT> predicate, FI.UnitApply<DT> apply)
          Create a UnitPFBuilder with the first case statement set.
<DT extends D>
UnitPFBuilder<D>
matchData(java.lang.Class<DT> dataType, FI.UnitApply<DT> apply)
          Create a UnitPFBuilder with the first case statement set.
<ET,DT extends D>
FSMStateFunctionBuilder<S,D>
matchEvent(java.lang.Class<ET> eventType, java.lang.Class<DT> dataType, FI.Apply2<ET,DT,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<ET,DT extends D>
FSMStateFunctionBuilder<S,D>
matchEvent(java.lang.Class<ET> eventType, java.lang.Class<DT> dataType, FI.TypedPredicate2<ET,DT> predicate, FI.Apply2<ET,DT,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<ET> FSMStateFunctionBuilder<S,D>
matchEvent(java.lang.Class<ET> eventType, FI.Apply2<ET,D,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<ET> FSMStateFunctionBuilder<S,D>
matchEvent(java.lang.Class<ET> eventType, FI.TypedPredicate2<ET,D> predicate, FI.Apply2<ET,D,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
 FSMStateFunctionBuilder<S,D> matchEvent(FI.TypedPredicate2<java.lang.Object,D> predicate, FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<DT extends D>
FSMStateFunctionBuilder<S,D>
matchEvent(java.util.List<java.lang.Object> eventMatches, java.lang.Class<DT> dataType, FI.Apply2<java.lang.Object,DT,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
 FSMStateFunctionBuilder<S,D> matchEvent(java.util.List<java.lang.Object> eventMatches, FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<E,DT extends D>
FSMStateFunctionBuilder<S,D>
matchEventEquals(E event, java.lang.Class<DT> dataType, FI.Apply2<E,DT,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
<E> FSMStateFunctionBuilder<S,D>
matchEventEquals(E event, FI.Apply2<E,D,FSM.State<S,D>> apply)
          Create an FSMStateFunctionBuilder with the first case statement set.
 FSMTransitionHandlerBuilder<S> matchState(S fromState, S toState, FI.UnitApply2<S,S> apply)
          Create an FSMTransitionHandlerBuilder with the first case statement set.
 FSMTransitionHandlerBuilder<S> matchState(S fromState, S toState, FI.UnitApplyVoid apply)
          Create an FSMTransitionHandlerBuilder with the first case statement set.
<RT extends FSM.Reason>
FSMStopBuilder<S,D>
matchStop(java.lang.Class<RT> reasonType, FI.TypedPredicate<RT> predicate, FI.UnitApply3<RT,S,D> apply)
          Create an FSMStopBuilder with the first case statement set.
<RT extends FSM.Reason>
FSMStopBuilder<S,D>
matchStop(java.lang.Class<RT> reasonType, FI.UnitApply3<RT,S,D> apply)
          Create an FSMStopBuilder with the first case statement set.
 FSMStopBuilder<S,D> matchStop(FSM.Reason reason, FI.UnitApply2<S,D> apply)
          Create an FSMStopBuilder with the first case statement set.
 FSM.Reason Normal()
          Default reason if calling stop().
static
<S,D> scala.PartialFunction<S,D>
NullFunction()
          A partial function value which does not match anything and can be used to &ldquo;reset&rdquo; whenUnhandled and onTermination handlers.
 void onTermination(FSMStopBuilder<S,D> stopBuilder)
          Set handler which is called upon termination of this FSM actor.
 void onTransition(FI.UnitApply2<S,S> transitionHandler)
          Add a handler which is called upon each state transition, i.e.
 void onTransition(FSMTransitionHandlerBuilder<S> transitionHandlerBuilder)
          Add a handler which is called upon each state transition, i.e.
 void setTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout)
          Schedule named timer to deliver message after given delay, possibly repeating.
 FSM.Reason Shutdown()
          Reason given when someone was calling system.stop(fsm) from outside; also applies to Stop supervision directive.
 void startWith(S stateName, D stateData)
          Set initial state.
 void startWith(S stateName, D stateData, scala.concurrent.duration.FiniteDuration timeout)
          Set initial state.
 void when(S stateName, scala.concurrent.duration.FiniteDuration stateTimeout, FSMStateFunctionBuilder<S,D> stateFunctionBuilder)
          Insert a new StateFunction at the end of the processing chain for the given state.
 void when(S stateName, FSMStateFunctionBuilder<S,D> stateFunctionBuilder)
          Insert a new StateFunction at the end of the processing chain for the given state.
 void when(S stateName, scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> stateFunction)
          Insert a new StateFunction at the end of the processing chain for the given state.
 void whenUnhandled(FSMStateFunctionBuilder<S,D> stateFunctionBuilder)
          Set handler which is called upon reception of unhandled messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface akka.actor.FSM
applyState, cancelTimer, currentState, debugEvent, Event, generation, handleEvent, handleEventDefault, handleTransition, initialize, isStateTimerActive, isTimerActive, logTermination, makeTransition, nextState, nextStateData, onTermination, onTransition, postStop, processEvent, processMsg, receive, register, setStateTimeout, setTimer, startWith, stateData, stateFunctions, stateName, StateTimeout, stateTimeouts, stay, stop, stop, stop, StopEvent, terminate, terminateEvent, timeoutFuture, timerGen, timers, total2pf, transform, transitionEvent, when, whenUnhandled
 
Methods inherited from interface akka.actor.Actor
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, postRestart, preRestart, preStart, self, sender, supervisorStrategy, unhandled
 
Methods inherited from interface akka.routing.Listeners
gossip, listenerManagement, listeners
 
Methods inherited from interface akka.actor.ActorLogging
_log, log
 

Constructor Detail

AbstractFSM

public AbstractFSM()
Method Detail

NullFunction

public static <S,D> scala.PartialFunction<S,D> NullFunction()
A partial function value which does not match anything and can be used to &ldquo;reset&rdquo; whenUnhandled and onTermination handlers.


 onTermination(FSM.NullFunction())
 

Returns:
(undocumented)

when

public final void when(S stateName,
                       scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> stateFunction)
Insert a new StateFunction at the end of the processing chain for the given state.

Parameters:
stateName - designator for the state
stateFunction - partial function describing response to input

when

public final void when(S stateName,
                       FSMStateFunctionBuilder<S,D> stateFunctionBuilder)
Insert a new StateFunction at the end of the processing chain for the given state.

Parameters:
stateName - designator for the state
stateFunctionBuilder - partial function builder describing response to input

when

public final void when(S stateName,
                       scala.concurrent.duration.FiniteDuration stateTimeout,
                       FSMStateFunctionBuilder<S,D> stateFunctionBuilder)
Insert a new StateFunction at the end of the processing chain for the given state. If the stateTimeout parameter is set, entering this state without a differing explicit timeout setting will trigger a StateTimeout event; the same is true when using #stay.

Parameters:
stateName - designator for the state
stateTimeout - default state timeout for this state
stateFunctionBuilder - partial function builder describing response to input

startWith

public final void startWith(S stateName,
                            D stateData)
Set initial state. Call this method from the constructor before the FSM.initialize() method. If different state is needed after a restart this method, followed by FSM.initialize(), can be used in the actor life cycle hooks Actor.preStart() and Actor.postRestart(java.lang.Throwable).

Parameters:
stateName - initial state designator
stateData - initial state data

startWith

public final void startWith(S stateName,
                            D stateData,
                            scala.concurrent.duration.FiniteDuration timeout)
Set initial state. Call this method from the constructor before the FSM.initialize() method. If different state is needed after a restart this method, followed by FSM.initialize(), can be used in the actor life cycle hooks Actor.preStart() and Actor.postRestart(java.lang.Throwable).

Parameters:
stateName - initial state designator
stateData - initial state data
timeout - state timeout for the initial state, overriding the default timeout for that state

onTransition

public final void onTransition(FSMTransitionHandlerBuilder<S> transitionHandlerBuilder)
Add a handler which is called upon each state transition, i.e. not when staying in the same state.

Multiple handlers may be installed, and every one of them will be called, not only the first one matching.

Parameters:
transitionHandlerBuilder - (undocumented)

onTransition

public final void onTransition(FI.UnitApply2<S,S> transitionHandler)
Add a handler which is called upon each state transition, i.e. not when staying in the same state.

Multiple handlers may be installed, and every one of them will be called, not only the first one matching.

Parameters:
transitionHandler - (undocumented)

whenUnhandled

public final void whenUnhandled(FSMStateFunctionBuilder<S,D> stateFunctionBuilder)
Set handler which is called upon reception of unhandled messages. Calling this method again will overwrite the previous contents.

The current state may be queried using stateName.

Parameters:
stateFunctionBuilder - (undocumented)

onTermination

public final void onTermination(FSMStopBuilder<S,D> stopBuilder)
Set handler which is called upon termination of this FSM actor. Calling this method again will overwrite the previous contents.

Parameters:
stopBuilder - (undocumented)

matchEvent

public final <ET,DT extends D> FSMStateFunctionBuilder<S,D> matchEvent(java.lang.Class<ET> eventType,
                                                                       java.lang.Class<DT> dataType,
                                                                       FI.TypedPredicate2<ET,DT> predicate,
                                                                       FI.Apply2<ET,DT,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches on an event and data type and a predicate.

Parameters:
eventType - the event type to match on
dataType - the data type to match on
predicate - a predicate to evaluate on the matched types
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEvent

public final <ET,DT extends D> FSMStateFunctionBuilder<S,D> matchEvent(java.lang.Class<ET> eventType,
                                                                       java.lang.Class<DT> dataType,
                                                                       FI.Apply2<ET,DT,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches on an event and data type.

Parameters:
eventType - the event type to match on
dataType - the data type to match on
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEvent

public final <ET> FSMStateFunctionBuilder<S,D> matchEvent(java.lang.Class<ET> eventType,
                                                          FI.TypedPredicate2<ET,D> predicate,
                                                          FI.Apply2<ET,D,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches if the event type and predicate matches.

Parameters:
eventType - the event type to match on
predicate - a predicate that will be evaluated on the data and the event
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEvent

public final <ET> FSMStateFunctionBuilder<S,D> matchEvent(java.lang.Class<ET> eventType,
                                                          FI.Apply2<ET,D,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches if the event type matches.

Parameters:
eventType - the event type to match on
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEvent

public final FSMStateFunctionBuilder<S,D> matchEvent(FI.TypedPredicate2<java.lang.Object,D> predicate,
                                                     FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches if the predicate matches.

Parameters:
predicate - a predicate that will be evaluated on the data and the event
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEvent

public final <DT extends D> FSMStateFunctionBuilder<S,D> matchEvent(java.util.List<java.lang.Object> eventMatches,
                                                                    java.lang.Class<DT> dataType,
                                                                    FI.Apply2<java.lang.Object,DT,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches on the data type and if any of the event types in the list match or any of the event instances in the list compares equal.

Parameters:
eventMatches - a list of types or instances to match against
dataType - the data type to match on
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEvent

public final FSMStateFunctionBuilder<S,D> matchEvent(java.util.List<java.lang.Object> eventMatches,
                                                     FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches if any of the event types in the list match or any of the event instances in the list compares equal.

Parameters:
eventMatches - a list of types or instances to match against
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEventEquals

public final <E,DT extends D> FSMStateFunctionBuilder<S,D> matchEventEquals(E event,
                                                                            java.lang.Class<DT> dataType,
                                                                            FI.Apply2<E,DT,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches on the data type and if the event compares equal.

Parameters:
event - an event to compare equal against
dataType - the data type to match on
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchEventEquals

public final <E> FSMStateFunctionBuilder<S,D> matchEventEquals(E event,
                                                               FI.Apply2<E,D,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches if the event compares equal.

Parameters:
event - an event to compare equal against
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchAnyEvent

public final FSMStateFunctionBuilder<S,D> matchAnyEvent(FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)
Create an FSMStateFunctionBuilder with the first case statement set.

A case statement that matches on any type of event.

Parameters:
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchState

public final FSMTransitionHandlerBuilder<S> matchState(S fromState,
                                                       S toState,
                                                       FI.UnitApplyVoid apply)
Create an FSMTransitionHandlerBuilder with the first case statement set.

A case statement that matches on a from state and a to state.

Parameters:
fromState - the from state to match on
toState - the to state to match on
apply - an action to apply when the states match
Returns:
the builder with the case statement added

matchState

public final FSMTransitionHandlerBuilder<S> matchState(S fromState,
                                                       S toState,
                                                       FI.UnitApply2<S,S> apply)
Create an FSMTransitionHandlerBuilder with the first case statement set.

A case statement that matches on a from state and a to state.

Parameters:
fromState - the from state to match on
toState - the to state to match on
apply - an action to apply when the states match
Returns:
the builder with the case statement added

matchStop

public final FSMStopBuilder<S,D> matchStop(FSM.Reason reason,
                                           FI.UnitApply2<S,D> apply)
Create an FSMStopBuilder with the first case statement set.

A case statement that matches on an FSM.Reason.

Parameters:
reason - the reason for the termination
apply - an action to apply to the event and state data if there is a match
Returns:
the builder with the case statement added

matchStop

public final <RT extends FSM.Reason> FSMStopBuilder<S,D> matchStop(java.lang.Class<RT> reasonType,
                                                                   FI.UnitApply3<RT,S,D> apply)
Create an FSMStopBuilder with the first case statement set.

A case statement that matches on a reason type.

Parameters:
reasonType - the reason type to match on
apply - an action to apply to the reason, event and state data if there is a match
Returns:
the builder with the case statement added

matchStop

public final <RT extends FSM.Reason> FSMStopBuilder<S,D> matchStop(java.lang.Class<RT> reasonType,
                                                                   FI.TypedPredicate<RT> predicate,
                                                                   FI.UnitApply3<RT,S,D> apply)
Create an FSMStopBuilder with the first case statement set.

A case statement that matches on a reason type and a predicate.

Parameters:
reasonType - the reason type to match on
apply - an action to apply to the reason, event and state data if there is a match
predicate - a predicate that will be evaluated on the reason if the type matches
Returns:
the builder with the case statement added

matchData

public final <DT extends D> UnitPFBuilder<D> matchData(java.lang.Class<DT> dataType,
                                                       FI.UnitApply<DT> apply)
Create a UnitPFBuilder with the first case statement set.

Parameters:
dataType - a type to match the argument against
apply - an action to apply to the argument if the type matches
Returns:
a builder with the case statement added

matchData

public final <DT extends D> UnitPFBuilder<D> matchData(java.lang.Class<DT> dataType,
                                                       FI.TypedPredicate<DT> predicate,
                                                       FI.UnitApply<DT> apply)
Create a UnitPFBuilder with the first case statement set.

Parameters:
dataType - a type to match the argument against
predicate - a predicate that will be evaluated on the argument if the type matches
apply - an action to apply to the argument if the type and predicate matches
Returns:
a builder with the case statement added

goTo

public final FSM.State<S,D> goTo(S nextStateName)
Produce transition to other state. Return this from a state function in order to effect the transition.

Parameters:
nextStateName - state designator for the next state
Returns:
state transition descriptor

setTimer

public final void setTimer(java.lang.String name,
                           java.lang.Object msg,
                           scala.concurrent.duration.FiniteDuration timeout)
Schedule named timer to deliver message after given delay, possibly repeating. Any existing timer with the same name will automatically be canceled before adding the new timer.

Parameters:
name - identifier to be used with cancelTimer()
msg - message to be delivered
timeout - delay of first message delivery and between subsequent messages

Normal

public FSM.Reason Normal()
Default reason if calling stop().

Returns:
(undocumented)

Shutdown

public FSM.Reason Shutdown()
Reason given when someone was calling system.stop(fsm) from outside; also applies to Stop supervision directive.

Returns:
(undocumented)