Interface FSM<S,D>
-
- All Superinterfaces:
Actor
,ActorLogging
,Listeners
- All Known Subinterfaces:
LoggingFSM<S,D>
- All Known Implementing Classes:
AbstractFSM
,AbstractFSMWithStash
,AbstractLoggingFSM
,BarrierCoordinator
,ClientFSM
,ClusterSingletonManager
,ProtocolStateActor
,ServerFSM
,ThrottledAssociation
public interface FSM<S,D> extends Actor, Listeners, ActorLogging
This extractor is just convenience for matching a (S, S) pair, including a reminder what the new state is.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
FSM.$minus$greater$
static class
FSM.CurrentState<S>
static class
FSM.CurrentState$
static class
FSM.Event<D>
static class
FSM.Event$
static class
FSM.Failure
static class
FSM.Failure$
static class
FSM.FixedDelayMode$
static class
FSM.FixedRateMode$
static class
FSM.LogEntry<S,D>
Log Entry of theLoggingFSM
, can be obtained by callinggetLog
.static class
FSM.LogEntry$
static class
FSM.Normal$
static class
FSM.NullFunction$
static interface
FSM.Reason
static class
FSM.Shutdown$
static class
FSM.SilentState<S,D>
INTERNAL APIstatic class
FSM.SingleMode$
static class
FSM.State<S,D>
static class
FSM.State$
static class
FSM.StateTimeout$
static class
FSM.StopEvent<S,D>
static class
FSM.StopEvent$
static class
FSM.SubscribeTransitionCallBack
static class
FSM.SubscribeTransitionCallBack$
static class
FSM.Timer
static class
FSM.Timer$
static interface
FSM.TimerMode
static class
FSM.TransformHelper
static class
FSM.Transition<S>
static class
FSM.Transition$
static class
FSM.UnsubscribeTransitionCallBack
static class
FSM.UnsubscribeTransitionCallBack$
-
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description FSM.$minus$greater$
$minus$greater()
This extractor is just convenience for matching a (S, S) pair, including a reminder what the new state is.void
akka$actor$FSM$_setter_$Event_$eq(FSM.Event$ x$1)
void
akka$actor$FSM$_setter_$StateTimeout_$eq(FSM.StateTimeout$ x$1)
This case object is received in case of a state timeout.void
akka$actor$FSM$_setter_$StopEvent_$eq(FSM.StopEvent$ x$1)
void
applyState(FSM.State<S,D> nextState)
void
cancelTimer(java.lang.String name)
Cancel named timer, ensuring that the message is not subsequently delivered (no race).void
currentState_$eq(FSM.State<S,D> x$1)
boolean
debugEvent()
FSM.Event$
Event()
void
generation_$eq(long x$1)
void
handleEvent_$eq(scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> x$1)
void
handleTransition(S prev, S next)
void
initialize()
Verify existence of initial state and setup timers.boolean
isStateTimerActive()
INTERNAL API, used for testing.boolean
isTimerActive(java.lang.String name)
Inquire whether the named timer is still active.void
logTermination(FSM.Reason reason)
By defaultFSM.Failure
is logged at error level and other reason types are not logged.void
makeTransition(FSM.State<S,D> nextState)
void
nextState_$eq(FSM.State<S,D> x$1)
D
nextStateData()
Return next state data (available in onTransition handlers)void
onTermination(scala.PartialFunction<FSM.StopEvent<S,D>,scala.runtime.BoxedUnit> terminationHandler)
Set handler which is called upon termination of this FSM actor.void
onTransition(scala.PartialFunction<scala.Tuple2<S,S>,scala.runtime.BoxedUnit> transitionHandler)
Set handler which is called upon each state transition, i.e.void
postStop()
CallonTermination
hook; if you want to retain this behavior when overriding make sure to callsuper.postStop()
.void
processEvent(FSM.Event<D> event, java.lang.Object source)
void
processMsg(java.lang.Object value, java.lang.Object source)
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>
receive()
Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.void
register(S name, scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> function, scala.Option<scala.concurrent.duration.FiniteDuration> timeout)
void
setStateTimeout(S state, scala.Option<scala.concurrent.duration.FiniteDuration> timeout)
Set state timeout explicitly.void
setTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout, boolean repeat)
Deprecated.Use startSingleTimer, startTimerWithFixedDelay or startTimerAtFixedRate instead.boolean
setTimer$default$4()
void
startSingleTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration delay)
Start a timer that will sendmsg
once to theself
actor after the givendelay
.void
startTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout, FSM.TimerMode mode)
void
startTimerAtFixedRate(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration interval)
Schedules a message to be sent repeatedly to theself
actor with a given frequency.void
startTimerWithFixedDelay(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration delay)
Schedules a message to be sent repeatedly to theself
actor with a fixeddelay
between messages.void
startWith(S stateName, D stateData, scala.Option<scala.concurrent.duration.FiniteDuration> timeout)
Set initial state.scala.Option<scala.concurrent.duration.FiniteDuration>
startWith$default$3()
D
stateData()
Return current state data (i.e.S
stateName()
Return current state name (i.e.FSM.StateTimeout$
StateTimeout()
This case object is received in case of a state timeout.FSM.State<S,D>
stay()
Produce "empty" transition descriptor.FSM.State<S,D>
stop()
Produce change descriptor to stop this FSM actor with reason "Normal".FSM.State<S,D>
stop(FSM.Reason reason)
Produce change descriptor to stop this FSM actor including specified reason.FSM.State<S,D>
stop(FSM.Reason reason, D stateData)
Produce change descriptor to stop this FSM actor including specified reason.FSM.StopEvent$
StopEvent()
void
super$postStop()
CallonTermination
hook; if you want to retain this behavior when overriding make sure to callsuper.postStop()
.void
terminate(FSM.State<S,D> nextState)
void
terminateEvent_$eq(scala.PartialFunction<FSM.StopEvent<S,D>,scala.runtime.BoxedUnit> x$1)
void
timeoutFuture_$eq(scala.Option<Cancellable> x$1)
scala.PartialFunction<scala.Tuple2<S,S>,scala.runtime.BoxedUnit>
total2pf(scala.Function2<S,S,scala.runtime.BoxedUnit> transitionHandler)
Convenience wrapper for using a total function instead of a partial function literal.FSM.TransformHelper
transform(scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> func)
void
transitionEvent_$eq(scala.collection.immutable.List<scala.PartialFunction<scala.Tuple2<S,S>,scala.runtime.BoxedUnit>> x$1)
void
when(S stateName, scala.concurrent.duration.FiniteDuration stateTimeout, 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.scala.concurrent.duration.FiniteDuration
when$default$2()
void
whenUnhandled(scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> stateFunction)
Set handler which is called upon reception of unhandled messages.-
Methods inherited from interface akka.actor.Actor
akka$actor$Actor$_setter_$context_$eq, akka$actor$Actor$_setter_$self_$eq, aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, postRestart, preRestart, preStart, self, sender, supervisorStrategy, unhandled
-
Methods inherited from interface akka.actor.ActorLogging
_log_$eq, log
-
Methods inherited from interface akka.routing.Listeners
akka$routing$Listeners$_setter_$listeners_$eq, gossip, gossip$default$2, listenerManagement, listeners
-
-
-
-
Method Detail
-
akka$actor$FSM$_setter_$Event_$eq
void akka$actor$FSM$_setter_$Event_$eq(FSM.Event$ x$1)
-
akka$actor$FSM$_setter_$StopEvent_$eq
void akka$actor$FSM$_setter_$StopEvent_$eq(FSM.StopEvent$ x$1)
-
akka$actor$FSM$_setter_$StateTimeout_$eq
void akka$actor$FSM$_setter_$StateTimeout_$eq(FSM.StateTimeout$ x$1)
This case object is received in case of a state timeout.- Parameters:
x$1
- (undocumented)
-
super$postStop
void super$postStop()
CallonTermination
hook; if you want to retain this behavior when overriding make sure to callsuper.postStop()
.Please note that this method is called by default from
preRestart()
, so override that one ifonTermination
shall not be called during restart.
-
Event
FSM.Event$ Event()
-
StopEvent
FSM.StopEvent$ StopEvent()
-
$minus$greater
FSM.$minus$greater$ $minus$greater()
This extractor is just convenience for matching a (S, S) pair, including a reminder what the new state is.- Returns:
- (undocumented)
-
StateTimeout
FSM.StateTimeout$ StateTimeout()
This case object is received in case of a state timeout.- Returns:
- (undocumented)
-
when
void when(S stateName, scala.concurrent.duration.FiniteDuration stateTimeout, 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. 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 statestateTimeout
- default state timeout for this statestateFunction
- partial function describing response to input
-
when$default$2
scala.concurrent.duration.FiniteDuration when$default$2()
-
startWith
void startWith(S stateName, D stateData, scala.Option<scala.concurrent.duration.FiniteDuration> timeout)
Set initial state. Call this method from the constructor before theinitialize()
method. If different state is needed after a restart this method, followed byinitialize()
, can be used in the actor life cycle hooksActor.preStart()
andActor.postRestart(java.lang.Throwable)
.- Parameters:
stateName
- initial state designatorstateData
- initial state datatimeout
- state timeout for the initial state, overriding the default timeout for that state
-
startWith$default$3
scala.Option<scala.concurrent.duration.FiniteDuration> startWith$default$3()
-
stay
FSM.State<S,D> stay()
Produce "empty" transition descriptor. Return this from a state function when no state change is to be effected.No transition event will be triggered by
stay()
. If you want to trigger an event likeS -> S
foronTransition
to handle usegoto
instead.- Returns:
- descriptor for staying in current state
-
stop
FSM.State<S,D> stop()
Produce change descriptor to stop this FSM actor with reason "Normal".- Returns:
- (undocumented)
-
stop
FSM.State<S,D> stop(FSM.Reason reason)
Produce change descriptor to stop this FSM actor including specified reason.- Parameters:
reason
- (undocumented)- Returns:
- (undocumented)
-
stop
FSM.State<S,D> stop(FSM.Reason reason, D stateData)
Produce change descriptor to stop this FSM actor including specified reason.- Parameters:
reason
- (undocumented)stateData
- (undocumented)- Returns:
- (undocumented)
-
startTimerWithFixedDelay
void startTimerWithFixedDelay(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration delay)
Schedules a message to be sent repeatedly to theself
actor with a fixeddelay
between messages.It will not compensate the delay between messages if scheduling is delayed longer than specified for some reason. The delay between sending of subsequent messages will always be (at least) the given
delay
.In the long run, the frequency of messages will generally be slightly lower than the reciprocal of the specified
delay
.Each timer has a
name
and if a new timer with samename
is started the previous is cancelled. It is guaranteed that a message from the previous timer is not received, even if it was already enqueued in the mailbox when the new timer was started.- Parameters:
name
- (undocumented)msg
- (undocumented)delay
- (undocumented)
-
startTimerAtFixedRate
void startTimerAtFixedRate(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration interval)
Schedules a message to be sent repeatedly to theself
actor with a given frequency.It will compensate the delay for a subsequent message if the sending of previous message was delayed more than specified. In such cases, the actual message interval will differ from the interval passed to the method.
If the execution is delayed longer than the
interval
, the subsequent message will be sent immediately after the prior one. This also has the consequence that after long garbage collection pauses or other reasons when the JVM was suspended all "missed" messages will be sent when the process wakes up again.In the long run, the frequency of messages will be exactly the reciprocal of the specified
interval
.Warning:
startTimerAtFixedRate
can result in bursts of scheduled messages after long garbage collection pauses, which may in worst case cause undesired load on the system. ThereforestartTimerWithFixedDelay
is often preferred.Each timer has a
name
and if a new timer with samename
is started the previous is cancelled. It is guaranteed that a message from the previous timer is not received, even if it was already enqueued in the mailbox when the new timer was started.- Parameters:
name
- (undocumented)msg
- (undocumented)interval
- (undocumented)
-
startSingleTimer
void startSingleTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration delay)
Start a timer that will sendmsg
once to theself
actor after the givendelay
.Each timer has a
name
and if a new timer with samename
is started the previous is cancelled. It is guaranteed that a message from the previous timer is not received, even if it was already enqueued in the mailbox when the new timer was started.- Parameters:
name
- (undocumented)msg
- (undocumented)delay
- (undocumented)
-
setTimer
void setTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout, boolean repeat)
Deprecated.Use startSingleTimer, startTimerWithFixedDelay or startTimerAtFixedRate instead. This has the same semantics as startTimerAtFixedRate, but startTimerWithFixedDelay is often preferred. Since 2.6.0.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 deliveredtimeout
- delay of first message delivery and between subsequent messagesrepeat
- send once if false, scheduleAtFixedRate if true
-
setTimer$default$4
boolean setTimer$default$4()
-
startTimer
void startTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout, FSM.TimerMode mode)
-
cancelTimer
void cancelTimer(java.lang.String name)
Cancel named timer, ensuring that the message is not subsequently delivered (no race).- Parameters:
name
- of the timer to cancel
-
isTimerActive
boolean isTimerActive(java.lang.String name)
Inquire whether the named timer is still active. Returns true unless the timer does not exist, has previously been canceled or if it was a single-shot timer whose message was already received.- Parameters:
name
- (undocumented)- Returns:
- (undocumented)
-
setStateTimeout
void setStateTimeout(S state, scala.Option<scala.concurrent.duration.FiniteDuration> timeout)
Set state timeout explicitly. This method can safely be used from within a state handler.- Parameters:
state
- (undocumented)timeout
- (undocumented)
-
isStateTimerActive
boolean isStateTimerActive()
INTERNAL API, used for testing.- Returns:
- (undocumented)
-
onTransition
void onTransition(scala.PartialFunction<scala.Tuple2<S,S>,scala.runtime.BoxedUnit> transitionHandler)
Set handler which is called upon each state transition, i.e. not when staying in the same state. This may use the pair extractor defined in the FSM companion object like so:onTransition { case Old -> New => doSomething }
It is also possible to supply a 2-ary function object:
onTransition(handler _) private def handler(from: S, to: S) { ... }
The underscore is unfortunately necessary to enable the nicer syntax shown above (it uses the implicit conversion total2pf under the hood).
Multiple handlers may be installed, and every one of them will be called, not only the first one matching.
- Parameters:
transitionHandler
- (undocumented)
-
total2pf
scala.PartialFunction<scala.Tuple2<S,S>,scala.runtime.BoxedUnit> total2pf(scala.Function2<S,S,scala.runtime.BoxedUnit> transitionHandler)
Convenience wrapper for using a total function instead of a partial function literal. To be used with onTransition.- Parameters:
transitionHandler
- (undocumented)- Returns:
- (undocumented)
-
onTermination
void onTermination(scala.PartialFunction<FSM.StopEvent<S,D>,scala.runtime.BoxedUnit> terminationHandler)
Set handler which is called upon termination of this FSM actor. Calling this method again will overwrite the previous contents.- Parameters:
terminationHandler
- (undocumented)
-
whenUnhandled
void whenUnhandled(scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> stateFunction)
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:
stateFunction
- (undocumented)
-
initialize
void initialize()
Verify existence of initial state and setup timers. This should be the last call within the constructor, orActor.preStart()
andActor.postRestart(java.lang.Throwable)
An initial
currentState -> currentState
notification will be triggered by calling this method.
-
stateName
S stateName()
Return current state name (i.e. object of type S)- Returns:
- (undocumented)
-
stateData
D stateData()
Return current state data (i.e. object of type D)- Returns:
- (undocumented)
-
nextStateData
D nextStateData()
Return next state data (available in onTransition handlers)- Returns:
- (undocumented)
-
debugEvent
boolean debugEvent()
-
timeoutFuture_$eq
void timeoutFuture_$eq(scala.Option<Cancellable> x$1)
-
generation_$eq
void generation_$eq(long x$1)
-
register
void register(S name, scala.PartialFunction<FSM.Event<D>,FSM.State<S,D>> function, scala.Option<scala.concurrent.duration.FiniteDuration> timeout)
-
terminateEvent_$eq
void terminateEvent_$eq(scala.PartialFunction<FSM.StopEvent<S,D>,scala.runtime.BoxedUnit> x$1)
-
transitionEvent_$eq
void transitionEvent_$eq(scala.collection.immutable.List<scala.PartialFunction<scala.Tuple2<S,S>,scala.runtime.BoxedUnit>> x$1)
-
receive
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
Description copied from interface:Actor
Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.
-
processMsg
void processMsg(java.lang.Object value, java.lang.Object source)
-
postStop
void postStop()
CallonTermination
hook; if you want to retain this behavior when overriding make sure to callsuper.postStop()
.Please note that this method is called by default from
preRestart()
, so override that one ifonTermination
shall not be called during restart.
-
logTermination
void logTermination(FSM.Reason reason)
By defaultFSM.Failure
is logged at error level and other reason types are not logged. It is possible to override this behavior.- Parameters:
reason
- (undocumented)
-
-