Class AbstractFSM<S,D>
- java.lang.Object
-
- akka.actor.AbstractFSM<S,D>
-
- All Implemented Interfaces:
Actor,ActorLogging,FSM<S,D>,Listeners
- Direct Known Subclasses:
AbstractFSMWithStash,AbstractLoggingFSM
public abstract class AbstractFSM<S,D> extends java.lang.Object implements FSM<S,D>
Java API: compatible with lambda expressionsFinite State Machine actor abstract base class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$
-
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.FixedDelayMode$, FSM.FixedRateMode$, FSM.LogEntry<S,D>, FSM.LogEntry$, FSM.Normal$, FSM.NullFunction$, FSM.Reason, FSM.Shutdown$, FSM.SilentState<S,D>, FSM.SingleMode$, FSM.State<S,D>, FSM.State$, FSM.StateTimeout$, FSM.StopEvent<S,D>, FSM.StopEvent$, FSM.SubscribeTransitionCallBack, FSM.SubscribeTransitionCallBack$, FSM.Timer, FSM.Timer$, FSM.TimerMode, FSM.TransformHelper, FSM.Transition<S>, FSM.Transition$, FSM.UnsubscribeTransitionCallBack, FSM.UnsubscribeTransitionCallBack$
-
-
Constructor Summary
Constructors Constructor Description AbstractFSM()
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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.protected voidakka$actor$Actor$_setter_$context_$eq(ActorContext x$1)Scala API: Stores the context for this actor, including self, and sender.protected voidakka$actor$Actor$_setter_$self_$eq(ActorRef x$1)The 'self' field holds the ActorRef for this actor.protected voidakka$actor$FSM$_setter_$Event_$eq(FSM.Event$ x$1)protected voidakka$actor$FSM$_setter_$StateTimeout_$eq(FSM.StateTimeout$ x$1)This case object is received in case of a state timeout.protected voidakka$actor$FSM$_setter_$StopEvent_$eq(FSM.StopEvent$ x$1)protected voidakka$routing$Listeners$_setter_$listeners_$eq(java.util.Set<ActorRef> x$1)ActorContextcontext()Scala API: Stores the context for this actor, including self, and sender.FSM.Event$Event()AbstractActor.ActorContextgetContext()Returns this AbstractActor's ActorContext The ActorContext is not thread safe so do not expose it outside of the AbstractActor.ActorRefgetSelf()Returns the ActorRef for this actor.ActorRefgetSender()The reference sender Actor of the currently processed message.FSM.State<S,D>goTo(S nextStateName)Produce transition to other state.protected java.util.Set<ActorRef>listeners()FSMStateFunctionBuilder<S,D>matchAnyEvent(FI.Apply2<java.lang.Object,D,FSM.State<S,D>> apply)Create anFSMStateFunctionBuilderwith 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 aUnitPFBuilderwith the first case statement set.<DT extends D>
UnitPFBuilder<D>matchData(java.lang.Class<DT> dataType, FI.UnitApply<DT> apply)Create aUnitPFBuilderwith 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 anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith the first case statement set.<E> FSMStateFunctionBuilder<S,D>matchEventEquals(E event, FI.Apply2<E,D,FSM.State<S,D>> apply)Create anFSMStateFunctionBuilderwith 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 anFSMStateFunctionBuilderwith the first case statement set.FSMTransitionHandlerBuilder<S>matchState(S fromState, S toState, FI.UnitApply2<S,S> apply)Create anFSMTransitionHandlerBuilderwith the first case statement set.FSMTransitionHandlerBuilder<S>matchState(S fromState, S toState, FI.UnitApplyVoid apply)Create anFSMTransitionHandlerBuilderwith the first case statement set.FSMStopBuilder<S,D>matchStop(FSM.Reason reason, FI.UnitApply2<S,D> apply)Create anFSMStopBuilderwith 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 anFSMStopBuilderwith 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 anFSMStopBuilderwith the first case statement set.FSM.ReasonNormal()Default reason if callingstop().static <S,D>
scala.PartialFunction<S,D>NullFunction()A partial function value which does not match anything and can be used to “reset”whenUnhandledandonTerminationhandlers.voidonTermination(FSMStopBuilder<S,D> stopBuilder)Set handler which is called upon termination of this FSM actor.voidonTransition(FI.UnitApply2<S,S> transitionHandler)Add a handler which is called upon each state transition, i.e.voidonTransition(FSMTransitionHandlerBuilder<S> transitionHandlerBuilder)Add a handler which is called upon each state transition, i.e.ActorRefself()The 'self' field holds the ActorRef for this actor.voidsetTimer(java.lang.String name, java.lang.Object msg, java.time.Duration timeout)Deprecated.Use startSingleTimer instead.voidsetTimer(java.lang.String name, java.lang.Object msg, java.time.Duration timeout, boolean repeat)Deprecated.Use startSingleTimer, startTimerWithFixedDelay or startTimerAtFixedRate instead.voidsetTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout)Deprecated.Use startSingleTimer instead.FSM.ReasonShutdown()Reason given when someone was callingsystem.stop(fsm)from outside; also applies toStopsupervision directive.voidstartSingleTimer(java.lang.String name, java.lang.Object msg, java.time.Duration delay)Start a timer that will sendmsgonce to theselfactor after the givendelay.voidstartTimerAtFixedRate(java.lang.String name, java.lang.Object msg, java.time.Duration interval)Schedules a message to be sent repeatedly to theselfactor with a given frequency.voidstartTimerWithFixedDelay(java.lang.String name, java.lang.Object msg, java.time.Duration delay)Schedules a message to be sent repeatedly to theselfactor with a fixeddelaybetween messages.voidstartWith(S stateName, D stateData)Set initial state.voidstartWith(S stateName, D stateData, java.time.Duration timeout)Set initial state.voidstartWith(S stateName, D stateData, scala.concurrent.duration.FiniteDuration timeout)Set initial state.FSM.StateTimeout$StateTimeout()This case object is received in case of a state timeout.FSM.StopEvent$StopEvent()voidwhen(S stateName, FSMStateFunctionBuilder<S,D> stateFunctionBuilder)Insert a new StateFunction at the end of the processing chain for the given state.voidwhen(S stateName, java.time.Duration stateTimeout, FSMStateFunctionBuilder<S,D> stateFunctionBuilder)Insert a new StateFunction at the end of the processing chain for the given state.voidwhen(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.voidwhen(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.voidwhenUnhandled(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.Actor
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, postRestart, preRestart, preStart, sender, supervisorStrategy, unhandled
-
Methods inherited from interface akka.actor.ActorLogging
_log_$eq, log
-
Methods inherited from interface akka.actor.FSM
applyState, cancelTimer, currentState_$eq, debugEvent, generation_$eq, handleEvent_$eq, handleTransition, initialize, isStateTimerActive, isTimerActive, logTermination, makeTransition, nextState_$eq, nextStateData, onTermination, onTransition, postStop, processEvent, processMsg, receive, register, setStateTimeout, setTimer, setTimer$default$4, startSingleTimer, startTimer, startTimerAtFixedRate, startTimerWithFixedDelay, startWith, startWith$default$3, stateData, stateName, stay, stop, stop, stop, super$postStop, terminate, terminateEvent_$eq, timeoutFuture_$eq, total2pf, transform, transitionEvent_$eq, when, when$default$2, whenUnhandled
-
Methods inherited from interface akka.routing.Listeners
gossip, gossip$default$2, listenerManagement
-
-
-
-
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 “reset”whenUnhandledandonTerminationhandlers.onTermination(FSM.NullFunction())
-
Event
public FSM.Event$ Event()
-
StopEvent
public FSM.StopEvent$ StopEvent()
-
$minus$greater
public FSM.$minus$greater$ $minus$greater()
Description copied from interface:FSMThis extractor is just convenience for matching a (S, S) pair, including a reminder what the new state is.- Specified by:
$minus$greaterin interfaceFSM<S,D>
-
StateTimeout
public FSM.StateTimeout$ StateTimeout()
Description copied from interface:FSMThis case object is received in case of a state timeout.- Specified by:
StateTimeoutin interfaceFSM<S,D>
-
akka$actor$FSM$_setter_$Event_$eq
protected void akka$actor$FSM$_setter_$Event_$eq(FSM.Event$ x$1)
- Specified by:
akka$actor$FSM$_setter_$Event_$eqin interfaceFSM<S,D>
-
akka$actor$FSM$_setter_$StopEvent_$eq
protected void akka$actor$FSM$_setter_$StopEvent_$eq(FSM.StopEvent$ x$1)
- Specified by:
akka$actor$FSM$_setter_$StopEvent_$eqin interfaceFSM<S,D>
-
akka$actor$FSM$_setter_$StateTimeout_$eq
protected void akka$actor$FSM$_setter_$StateTimeout_$eq(FSM.StateTimeout$ x$1)
Description copied from interface:FSMThis case object is received in case of a state timeout.- Specified by:
akka$actor$FSM$_setter_$StateTimeout_$eqin interfaceFSM<S,D>
-
listeners
protected java.util.Set<ActorRef> listeners()
-
akka$routing$Listeners$_setter_$listeners_$eq
protected void akka$routing$Listeners$_setter_$listeners_$eq(java.util.Set<ActorRef> x$1)
- Specified by:
akka$routing$Listeners$_setter_$listeners_$eqin interfaceListeners
-
context
public ActorContext context()
Description copied from interface:ActorScala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such asforward.WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads!
ActorContextis the Scala API.getContextreturns aAbstractActor.ActorContext, which is the Java API of the actor context.
-
self
public final ActorRef self()
Description copied from interface:ActorThe 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message
-
akka$actor$Actor$_setter_$context_$eq
protected void akka$actor$Actor$_setter_$context_$eq(ActorContext x$1)
Description copied from interface:ActorScala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such asforward.WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads!
ActorContextis the Scala API.getContextreturns aAbstractActor.ActorContext, which is the Java API of the actor context.- Specified by:
akka$actor$Actor$_setter_$context_$eqin interfaceActor
-
akka$actor$Actor$_setter_$self_$eq
protected final void akka$actor$Actor$_setter_$self_$eq(ActorRef x$1)
Description copied from interface:ActorThe 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message
- Specified by:
akka$actor$Actor$_setter_$self_$eqin interfaceActor
-
getContext
public AbstractActor.ActorContext getContext()
Returns this AbstractActor's ActorContext The ActorContext is not thread safe so do not expose it outside of the AbstractActor.
-
getSelf
public ActorRef getSelf()
Returns the ActorRef for this actor.Same as
self().
-
getSender
public ActorRef getSender()
The reference sender Actor of the currently processed message. This is always a legal destination to send to, even if there is no logical recipient for the reply, in which case it will be sent to the dead letter mailbox.Same as
sender().WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads!
-
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 statestateFunction- 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 statestateFunctionBuilder- 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 statestateTimeout- default state timeout for this statestateFunctionBuilder- partial function builder describing response to input
-
when
public final void when(S stateName, java.time.Duration 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 statestateTimeout- default state timeout for this statestateFunctionBuilder- 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 theFSM.initialize()method. If different state is needed after a restart this method, followed byFSM.initialize(), can be used in the actor life cycle hooksActor.preStart()andActor.postRestart(java.lang.Throwable).- Parameters:
stateName- initial state designatorstateData- 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 theFSM.initialize()method. If different state is needed after a restart this method, followed byFSM.initialize(), 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
public final void startWith(S stateName, D stateData, java.time.Duration timeout)
Set initial state. Call this method from the constructor before theFSM.initialize()method. If different state is needed after a restart this method, followed byFSM.initialize(), 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
-
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.
-
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.
-
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.
-
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.
-
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 anFSMStateFunctionBuilderwith 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 ondataType- the data type to match onpredicate- a predicate to evaluate on the matched typesapply- 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 anFSMStateFunctionBuilderwith the first case statement set.A case statement that matches on an event and data type.
- Parameters:
eventType- the event type to match ondataType- the data type to match onapply- 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 anFSMStateFunctionBuilderwith the first case statement set.A case statement that matches if the event type and predicate matches.
- Parameters:
eventType- the event type to match onpredicate- a predicate that will be evaluated on the data and the eventapply- 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 anFSMStateFunctionBuilderwith the first case statement set.A case statement that matches if the event type matches.
- Parameters:
eventType- the event type to match onapply- 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 anFSMStateFunctionBuilderwith 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 eventapply- 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 anFSMStateFunctionBuilderwith 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 againstdataType- the data type to match onapply- 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 anFSMStateFunctionBuilderwith 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 againstapply- 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 anFSMStateFunctionBuilderwith 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 againstdataType- the data type to match onapply- 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 anFSMStateFunctionBuilderwith the first case statement set.A case statement that matches if the event compares equal.
- Parameters:
event- an event to compare equal againstapply- 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 anFSMStateFunctionBuilderwith 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 anFSMTransitionHandlerBuilderwith 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 ontoState- the to state to match onapply- 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 anFSMTransitionHandlerBuilderwith 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 ontoState- the to state to match onapply- 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 anFSMStopBuilderwith the first case statement set.A case statement that matches on an
FSM.Reason.- Parameters:
reason- the reason for the terminationapply- 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 anFSMStopBuilderwith the first case statement set.A case statement that matches on a reason type.
- Parameters:
reasonType- the reason type to match onapply- 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 anFSMStopBuilderwith the first case statement set.A case statement that matches on a reason type and a predicate.
- Parameters:
reasonType- the reason type to match onapply- an action to apply to the reason, event and state data if there is a matchpredicate- 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 aUnitPFBuilderwith the first case statement set.- Parameters:
dataType- a type to match the argument againstapply- 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 aUnitPFBuilderwith the first case statement set.- Parameters:
dataType- a type to match the argument againstpredicate- a predicate that will be evaluated on the argument if the type matchesapply- 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
-
startTimerWithFixedDelay
public void startTimerWithFixedDelay(java.lang.String name, java.lang.Object msg, java.time.Duration delay)Schedules a message to be sent repeatedly to theselfactor with a fixeddelaybetween 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
nameand if a new timer with samenameis 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.
-
startTimerAtFixedRate
public void startTimerAtFixedRate(java.lang.String name, java.lang.Object msg, java.time.Duration interval)Schedules a message to be sent repeatedly to theselfactor 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:
startTimerAtFixedRatecan result in bursts of scheduled messages after long garbage collection pauses, which may in worst case cause undesired load on the system. ThereforestartTimerWithFixedDelayis often preferred.Each timer has a
nameand if a new timer with samenameis 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.
-
startSingleTimer
public void startSingleTimer(java.lang.String name, java.lang.Object msg, java.time.Duration delay)Start a timer that will sendmsgonce to theselfactor after the givendelay.Each timer has a
nameand if a new timer with samenameis 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.
-
setTimer
public final void setTimer(java.lang.String name, java.lang.Object msg, scala.concurrent.duration.FiniteDuration timeout)Deprecated.Use startSingleTimer instead. 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 messages
-
setTimer
public final void setTimer(java.lang.String name, java.lang.Object msg, java.time.Duration timeout)Deprecated.Use startSingleTimer instead. 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 messages
-
setTimer
public final void setTimer(java.lang.String name, java.lang.Object msg, java.time.Duration 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
-
Normal
public FSM.Reason Normal()
Default reason if callingstop().
-
Shutdown
public FSM.Reason Shutdown()
Reason given when someone was callingsystem.stop(fsm)from outside; also applies toStopsupervision directive.
-
-