Package io.hektor.fsm.impl
Class FsmImpl<S extends Enum<S>,C extends Context,D extends Data>
java.lang.Object
io.hektor.fsm.impl.FsmImpl<S,C,D>
- All Implemented Interfaces:
FSM<S,,C, D> io.snice.logging.Logging
public class FsmImpl<S extends Enum<S>,C extends Context,D extends Data>
extends Object
implements FSM<S,C,D>, io.snice.logging.Logging
- Author:
- jonas@jonasborjesson.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.slf4j.Loggerfinal SgetState()The state in which this FSM currently is.final booleanfinal booleanThe FSM is in its terminated state if it has reached the final state.final voidDeliver an event to thisFSM.voidreStartAndEnter(S state) Re-start the FSM and enter the specified state.final voidstart()You must callFSM.start()on theFSMbefore it can be used.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.snice.logging.Logging
log, logDebug, logError, logError, logInfo, logInfo, logInfo, logInfo, logWarn, logWarn
-
Constructor Details
-
FsmImpl
public FsmImpl(Object uuid, String friendlyName, State[] states, S initialState, C ctx, D data, BiConsumer<S, Object> unhandledEventHandler, TransitionListener<S> transitionListener) - Parameters:
uuid- unique id to use as a correlator by external users. Not used by the FSM itself, other than in logging etc.friendlyName- only used for logging.states-initialState-ctx-data-unhandledEventHandler-transitionListener-
-
-
Method Details
-
isStarted
public final boolean isStarted() -
isTerminated
public final boolean isTerminated()Description copied from interface:FSMThe FSM is in its terminated state if it has reached the final state. -
start
public final void start()Description copied from interface:FSMYou must callFSM.start()on theFSMbefore it can be used. This will cause the FSM to "transition" from a null state to its initial state. Any enter actions associated with the initial state will naturally now be called. Note: calling this method when the FSM is already started will silently be ignored. -
reStartAndEnter
Description copied from interface:FSMRe-start the FSM and enter the specified state. The entry actions associated with this state will be executed. This is useful if your FSM throw an exception and you want to control how to deal with that (and potentially let the FSM start over) or if you have suspended/resumed the FSM (e.g. my serializing it to another JVM) and you want to continue were you left off.- Specified by:
reStartAndEnterin interfaceFSM<S extends Enum<S>,C extends Context, D extends Data> - Throws:
IllegalArgumentException- in case the state is null
-
onEvent
Description copied from interface:FSMDeliver an event to thisFSM. -
getState
Description copied from interface:FSMThe state in which this FSM currently is. -
getLogger
public org.slf4j.Logger getLogger()- Specified by:
getLoggerin interfaceio.snice.logging.Logging
-