public class DeterministicStateMachine extends ProcessorAdapter implements StateMachine
SynchronizedStateMachine| Modifier and Type | Field and Description |
|---|---|
private State |
currentState
The current state.
|
private java.util.List<Preprocessor> |
preprocessors
The preprocessors of events.
|
private java.util.List<StateListener> |
stateListeners
The listeners.
|
private java.util.Map<State,TransitionMap> |
stateTransitions
The transitions.
|
private java.util.List<TransitionListener> |
transitionListeners
The listeners.
|
loggerINITIAL_STATE_NAME| Constructor and Description |
|---|
DeterministicStateMachine(java.lang.String name)
Create the object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(StateListener listener)
Add a new listener.
|
void |
addListener(TransitionListener listener)
Add a new listener.
|
void |
addPreprocessor(Preprocessor preprocessor)
Add a new preprocessor.
|
void |
addState(State state)
Add a new state.
|
private void |
addStateInternal(State state)
Add a new state to the state machine.
|
void |
addTransition(Transition transition)
Add a new transition.
|
void |
close()
Finish processing of the events and free all allocated resources.
|
boolean |
easterEgg()
Each software product should contain at least one easter egg.
|
State |
getActiveState()
Get the currently active state.
|
java.util.Set<State> |
getActiveStates()
Get the currently active states.
|
java.util.Set<State> |
getStates()
Get all defined states.
|
protected Transition |
getTransition(State state,
Event event)
Get transition of a specified event type defined for a state.
|
java.util.Set<Transition> |
getTransitions()
Get all defined transitions.
|
boolean |
isInFinalState()
Is the active state a final state?
|
(package private) void |
notifyEnter(State previous,
Event event,
State current)
Process all state enter callbacks.
|
(package private) void |
notifyExit(State current,
Event event,
State next)
Process all state exit callbacks.
|
(package private) void |
notifyTransition(Transition transition,
State source,
Event event,
State destination)
Process all transition callbacks.
|
private Event |
preprocessEvent(Event event)
Preprocess event using all registered preprocessors (recursive).
|
Event |
process(Event event)
Process the event.
|
private void |
processCheck(Event event)
Check the input event and the internal state before processing the event.
|
private Event |
processInternal(Transition transition,
Event eventToProcess,
Event matchedEvent)
Real processing of the event.
|
void |
setStartState(State state)
Set the start state.
|
void |
start()
Building of the processor is finished, prepare it to the events
processing.
|
java.lang.String |
toString() |
getNameprivate final java.util.Map<State,TransitionMap> stateTransitions
private State currentState
private final java.util.List<StateListener> stateListeners
private final java.util.List<TransitionListener> transitionListeners
private final java.util.List<Preprocessor> preprocessors
public DeterministicStateMachine(java.lang.String name)
name - the name of the state machinepublic void setStartState(State state) throws FsmException
StateMachinesetStartState in interface StateMachinestate - the stateFsmExceptionStateMachine.start(),
Processor.process(Event)public void start()
throws FsmException
Processorstart in interface Processorstart in interface StateMachinestart in class ProcessorAdapterFsmException - if something failsProcessor.close()public void close()
ProcessorProcessor.close() should be
avoided. The behavior is not defined and may cause unpredictable
behavior, e.g. NullPointerException.close in interface java.lang.AutoCloseableclose in interface Processorclose in interface StateMachineclose in class ProcessorAdapterProcessor.start()public void addState(State state) throws FsmException
StateMachineaddState in interface StateMachinestate - the stateFsmException - if something failsprivate void addStateInternal(State state)
state - the statepublic void addTransition(Transition transition) throws FsmException
StateMachineaddTransition in interface StateMachinetransition - the transitionFsmException - if something failspublic void addPreprocessor(Preprocessor preprocessor)
StateMachineaddPreprocessor in interface StateMachinepreprocessor - the preprocessorProcessor.process(Event),
StateMachine.start(),
StateMachine.close()public void addListener(StateListener listener)
StateMachineaddListener in interface StateMachinelistener - the listenerpublic void addListener(TransitionListener listener)
StateMachineaddListener in interface StateMachinelistener - the listenervoid notifyEnter(State previous, Event event, State current) throws FsmException
previous - the previous stateevent - the eventcurrent - the current stateFsmException - if something failsvoid notifyExit(State current, Event event, State next) throws FsmException
current - the current stateevent - the eventnext - the next stateFsmException - if something failsvoid notifyTransition(Transition transition, State source, Event event, State destination) throws FsmException
transition - the transitionsource - the source stateevent - the eventdestination - the destination stateFsmException - if something failspublic State getActiveState()
StateMachinegetActiveState in interface StateMachineStateMachine.getActiveStates()public java.util.Set<State> getActiveStates()
StateMachinegetActiveStates in interface StateMachineStateMachine.getActiveState()public Event process(Event event) throws FsmException
Processorprocess in interface Processorevent - the input eventFsmException - if something failsprivate Event preprocessEvent(Event event) throws FsmException
event - the eventFsmException - if something failsprivate void processCheck(Event event) throws FsmException
event - the input eventFsmException - if the event can't be processed for any reasonprivate Event processInternal(Transition transition, Event eventToProcess, Event matchedEvent) throws FsmException
transition - the transition that should be processedeventToProcess - the event that should be processedmatchedEvent - the event that matched, for logging purposesFsmException - if something failspublic java.util.Set<State> getStates()
StateMachinegetStates in interface StateMachinepublic java.util.Set<Transition> getTransitions()
StateMachinegetTransitions in interface StateMachineprotected Transition getTransition(State state, Event event)
state - the state, it must be defined in the state machineevent - the eventpublic boolean isInFinalState()
StateMachineisInFinalState in interface StateMachinepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean easterEgg()
Copyright 2013 Michal Turek, AnotherFSM.