Class AbstractStateMachine<STATE extends State<STATE>,CONTEXT extends AbstractContext<?>>
- java.lang.Object
-
- io.openems.edge.common.statemachine.AbstractStateMachine<STATE,CONTEXT>
-
- Type Parameters:
STATE
- theState
type, e.g. typically an enumCONTEXT
- 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
public abstract class AbstractStateMachine<STATE extends State<STATE>,CONTEXT extends AbstractContext<?>> extends java.lang.Object
Manages the States of the StateMachine.
-
-
Constructor Summary
Constructors Constructor Description AbstractStateMachine(STATE initialState)
Initialize the State-Machine and set an initial State.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
forceNextState(STATE state)
Forcibly change the next State from outside.STATE
getCurrentState()
Gets the currently activate State.STATE
getPreviousState()
Gets the previously activate State.abstract StateHandler<STATE,CONTEXT>
getStateHandler(STATE state)
Gets theStateHandler
for each State.void
run(CONTEXT context)
Execute the StateMachine.
-
-
-
Constructor Detail
-
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 Detail
-
getStateHandler
public abstract StateHandler<STATE,CONTEXT> getStateHandler(STATE state)
Gets theStateHandler
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
-
-