Class AbstractStateMachine<STATE extends State<STATE>,CONTEXT extends AbstractContext<?>>

java.lang.Object
io.openems.edge.common.statemachine.AbstractStateMachine<STATE,CONTEXT>
Type Parameters:
STATE - the State type, e.g. typically an enum
CONTEXT - the context type, i.e. a class wrapping a State-Machine context
Direct Known Subclasses:
AbstractForceChargeDischarge, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine, StateMachine

public abstract class AbstractStateMachine<STATE extends State<STATE>,CONTEXT extends AbstractContext<?>> extends Object
Manages the States of the StateMachine.
  • Constructor Details

    • AbstractStateMachine

      public AbstractStateMachine(STATE initialState)
      Initialize the State-Machine and set an initial State.

      TODO Note that for the initialState the StateHandler.onEntry(Object) method is not called in the beginning.

      Parameters:
      initialState - the initial State
  • Method Details

    • debugLog

      public String debugLog()
      Gets a message that is suitable for a continuous Debug log. Returns the name of the current state in Camel-Case by default.
      Returns:
      the debug log output
    • getStateHandler

      public abstract StateHandler<STATE,CONTEXT> getStateHandler(STATE state)
      Gets the StateHandler for each State.

      This method is called once for every available State during construction of the StateMachine in order to initialize an internal list of StateHandlers.

      Parameters:
      state - the State
      Returns:
      the StateHandler for the given State
    • getPreviousState

      public STATE getPreviousState()
      Gets the previously activate State.
      Returns:
      the State
    • getCurrentState

      public STATE getCurrentState()
      Gets the currently activate State.
      Returns:
      the State
    • forceNextState

      public void forceNextState(STATE state)
      Forcibly change the next State from outside. Use with care!

      Note that transition events will get called.

      Parameters:
      state - the next State
    • run

      public void run(CONTEXT context) throws OpenemsError.OpenemsNamedException
      Execute the StateMachine.
      Parameters:
      context - the Context object
      Throws:
      OpenemsError.OpenemsNamedException - on error