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 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()
      Specified by:
      isStarted in interface FSM<S extends Enum<S>,C extends Context,D extends Data>
    • isTerminated

      public final boolean isTerminated()
      Description copied from interface: FSM
      The FSM is in its terminated state if it has reached the final state.
      Specified by:
      isTerminated in interface FSM<S extends Enum<S>,C extends Context,D extends Data>
      Returns:
    • start

      public final void start()
      Description copied from interface: FSM
      You must call FSM.start() on the FSM before 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.
      Specified by:
      start in interface FSM<S extends Enum<S>,C extends Context,D extends Data>
    • reStartAndEnter

      public void reStartAndEnter(S state) throws IllegalArgumentException
      Description copied from interface: FSM
      Re-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:
      reStartAndEnter in interface FSM<S extends Enum<S>,C extends Context,D extends Data>
      Throws:
      IllegalArgumentException - in case the state is null
    • onEvent

      public final void onEvent(Object event)
      Description copied from interface: FSM
      Deliver an event to this FSM.
      Specified by:
      onEvent in interface FSM<S extends Enum<S>,C extends Context,D extends Data>
    • getState

      public final S getState()
      Description copied from interface: FSM
      The state in which this FSM currently is.
      Specified by:
      getState in interface FSM<S extends Enum<S>,C extends Context,D extends Data>
    • getLogger

      public org.slf4j.Logger getLogger()
      Specified by:
      getLogger in interface io.snice.logging.Logging