Package com.digitalpetri.strictmachine
Interface FsmContext<S,E>
-
- All Known Subinterfaces:
ActionContext<S,E>
public interface FsmContext<S,E>
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classFsmContext.Key<T>
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ScurrentState()Get the current state of the FSM.voidfireEvent(E event)Fire an event to be evaluated against the current state of theFsm.java.lang.Objectget(FsmContext.Key<?> key)Get the value identified bykeyfrom the context, ornullif it does not exist.longgetInstanceId()Get the id assigned to this FSM instance.voidprocessShelvedEvents()Drain the event shelf of any queued events and fire them for evaluation.java.lang.Objectremove(FsmContext.Key<?> key)Get and remove the value identified bykeyfrom the context, ornullif it does not exist.voidset(FsmContext.Key<?> key, java.lang.Object value)Set a value identified bykeyon the context.voidshelveEvent(E event)Shelve an event to to be evaluated at some later time.
-
-
-
Method Detail
-
currentState
S currentState()
Get the current state of the FSM.- Returns:
- the current state of the FSM.
-
fireEvent
void fireEvent(E event)
Fire an event to be evaluated against the current state of theFsm.- Parameters:
event- the event to be evaluated.
-
shelveEvent
void shelveEvent(E event)
Shelve an event to to be evaluated at some later time.This is useful e.g. when an event can't be handled in the current state but shouldn't be discarded or ignored with an action-less internal transition.
- Parameters:
event- the event to be queued.- See Also:
processShelvedEvents()
-
processShelvedEvents
void processShelvedEvents()
Drain the event shelf of any queued events and fire them for evaluation.
-
get
java.lang.Object get(FsmContext.Key<?> key)
Get the value identified bykeyfrom the context, ornullif it does not exist.- Parameters:
key- theFsmContext.Key.- Returns:
- the value identified by
key, ornullif it does not exist.
-
remove
java.lang.Object remove(FsmContext.Key<?> key)
Get and remove the value identified bykeyfrom the context, ornullif it does not exist.- Parameters:
key- theFsmContext.Key.- Returns:
- the value identified by
key, ornullif it did not exist.
-
set
void set(FsmContext.Key<?> key, java.lang.Object value)
Set a value identified bykeyon the context.- Parameters:
key- theFsmContext.Key.value- the value.
-
getInstanceId
long getInstanceId()
Get the id assigned to this FSM instance.The id is a monotonically increasing value assigned to each new instance to aid in determining which log messages belong to which instance.
- Returns:
- the id assigned to this FSM instance.
-
-