T - public class FiniteStateMachine<T> extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
FiniteStateMachine.AbandonedTransitionException
Thrown when a transition was initiated by a thread that no longer exists, likely implying that the transition can
never be closed.
|
static class |
FiniteStateMachine.Builder<T>
Used to build a
FiniteStateMachine instance. |
static class |
FiniteStateMachine.FailedCallback |
static class |
FiniteStateMachine.FailedTransitionCallbackException
Thrown when the callbacks when closing a transition fail.
|
static class |
FiniteStateMachine.ReentrantStableStateWait
Thrown when a thread that has started a transition is waiting for a non-transitioning state, which is a deadlock situation.
|
class |
FiniteStateMachine.Transition
A handle used for controlling the transition of the
FiniteStateMachine. |
static class |
FiniteStateMachine.UnallowedTransitionException
If a transition is not allowed to happen.
|
| Modifier | Constructor and Description |
|---|---|
protected |
FiniteStateMachine(com.google.common.collect.SetMultimap<T,T> allowedTransitions,
Set<T> universalEnds,
T errorState,
T initialState) |
| Modifier and Type | Method and Description |
|---|---|
FiniteStateMachine<T> |
cloneAtCurrentState() |
FiniteStateMachine<T> |
cloneAtInitialState() |
T |
getCurrentState()
Get the current state.
|
protected boolean |
isAllowedTransition(T startState,
T endState) |
FiniteStateMachine.Transition |
startTransition(T endState)
Start a transition to the end state specified.
|
boolean |
transitionIfAllowed(T endState)
Transition immediately to the given end state if the transition is allowed.
|
void |
transitionImmediately(T endState)
Transition immediately to the given end state.
|
public FiniteStateMachine.Transition startTransition(T endState) throws FiniteStateMachine.UnallowedTransitionException, InterruptedException
FiniteStateMachine.Transition object is a closeable that will finalize
the transition when it is closed. While the transition is open, no other transition can start.
It is recommended to call this method only within a try-with-resource block to ensure the transition is closed.FiniteStateMachine.UnallowedTransitionException - If the transition is not allowed.InterruptedException - if the thread got interrupted while waiting for a non-transitioning state.public void transitionImmediately(T endState) throws FiniteStateMachine.UnallowedTransitionException, InterruptedException, FiniteStateMachine.FailedTransitionCallbackException
startTransition(Object) immediately
followed by FiniteStateMachine.Transition.close().FiniteStateMachine.UnallowedTransitionException - if the transition is not allowed.InterruptedException - if the thread got interrupted while waiting for a non-transitioning state.FiniteStateMachine.FailedTransitionCallbackExceptionpublic boolean transitionIfAllowed(T endState) throws InterruptedException, FiniteStateMachine.FailedTransitionCallbackException
InterruptedException - if the thread got interrupted while waiting for a non-transitioning state.FiniteStateMachine.FailedTransitionCallbackExceptionpublic T getCurrentState() throws InterruptedException
InterruptedException - if the thread got interrupted while waiting for a non-transitioning state.public FiniteStateMachine<T> cloneAtInitialState()
public FiniteStateMachine<T> cloneAtCurrentState() throws InterruptedException
InterruptedException