public class NonBlockingFiniteStateMachine<S extends Enum<S>> extends Object implements FiniteStateMachine<S>, ExecutionContext
NonBlockingFiniteStateMachine is a specialized FiniteStateMachine implementation that performs transitions asynchronously to the threads that request state changes. That is, threads that request state transitions are never blocked. Instead their requests are queued for a single thread to later perform the appropriate transition to the requested state.| Modifier and Type | Class and Description |
|---|---|
static class |
NonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>>
A
NonBlockingFiniteStateMachine.CoalescedEvent is a LifecycleAwareEvent that coalesces other (wrapped) Events with the same discriminator so that only one Event actually executes. |
static class |
NonBlockingFiniteStateMachine.DefaultTaskDependencies
Implementation of Dependencies for Task
|
static class |
NonBlockingFiniteStateMachine.DelayedTransitionTo<S extends Enum<S>>
A
NonBlockingFiniteStateMachine.DelayedTransitionTo is a specialized Instruction for NonBlockingFiniteStateMachines that enables a StateEntryAction to request a delayed transition to another state, unlike a Instruction.TransitionTo Instruction which occurs immediately. |
static class |
NonBlockingFiniteStateMachine.ProcessEventLater<S extends Enum<S>>
A specialized
Instruction for NonBlockingFiniteStateMachines that enables a StateEntryAction to request an Event to be processed at some point in the future. |
static class |
NonBlockingFiniteStateMachine.SubsequentEvent<S extends Enum<S>>
A
NonBlockingFiniteStateMachine.SubsequentEvent is an Event that ensures that another (wrapped) Event to occur if an only if the FiniteStateMachine is at a certain transition count. |
protected class |
NonBlockingFiniteStateMachine.Task
A PriorityTask implementation to process a requested event.
|
static interface |
NonBlockingFiniteStateMachine.TaskDependencies
Dependencies for Task.
|
| Constructor and Description |
|---|
NonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps)
Construct an
NonBlockingFiniteStateMachine given a Model. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(FiniteStateMachineListener<S> listener)
Add a
FiniteStateMachineListener to the FiniteStateMachine. |
String |
getName()
Obtains the name of the
FiniteStateMachine. |
S |
getState()
Obtains the current state of the
FiniteStateMachine. |
long |
getTransitionCount()
Obtains the number of transitions that have occurred in the
FiniteStateMachine. |
boolean |
hasPendingEvents()
Determines if there are any pending
Events for the FiniteStateMachine to process. |
void |
process(Event<S> event)
Request the
FiniteStateMachine to process the specified Event. |
void |
processLater(Event<S> event)
Request the
FiniteStateMachine to process the specified Event as soon as possible. |
void |
processLater(Event<S> event, long duration, TimeUnit timeUnit)
Request the
FiniteStateMachine to process the specified Event at some point in the future (represented as a duration to wait from the moment the method is called). |
boolean |
quiesceThenStop()
Requests the
FiniteStateMachine to stop accepting new Events to process, wait for any existing queued Events to be processed and then stop. |
void |
removeListener(FiniteStateMachineListener<S> listener)
Remove a
FiniteStateMachineListener from the FiniteStateMachine. |
boolean |
start()
Start the
FiniteStateMachine and enter the initial state. |
boolean |
stop()
Stops the
FiniteStateMachine as soon as possible. |
String |
toString() |
public NonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps)
NonBlockingFiniteStateMachine given a Model.sName - the name of the NonBlockingFiniteStateMachinemodel - the Model of the NonBlockingFiniteStateMachinestateInitial - the initial statedaemonPoolDeps - Optional DaemonPoolDependencies for Daemon Pool that will be used for scheduling TransitionsfIgnoreExceptions - when true RuntimeExceptions will be ignored, when false RuntimeExceptions will immediately stop the NonBlockingFiniteStateMachinedeps - the NonBlockingFiniteStateMachine.TaskDependencies specifies the event processing configs.public void addListener(FiniteStateMachineListener<S> listener)
FiniteStateMachineListener to the FiniteStateMachine.
Note that unique instances of FiniteStateMachineListener are identified via their #equals and #hashCode implementations.
addListener in interface FiniteStateMachine<S extends Enum<S>>listener - the listener to be addedpublic void removeListener(FiniteStateMachineListener<S> listener)
FiniteStateMachineListener from the FiniteStateMachine.
Note that unique instances of FiniteStateMachineListener are identified via their #equals and #hashCode implementations.
removeListener in interface FiniteStateMachine<S extends Enum<S>>listener - the listener to be removedpublic String getName()
FiniteStateMachine. This is primarily used for display/logging/monitoring purposes.getName in interface ExecutionContextgetName in interface FiniteStateMachine<S extends Enum<S>>FiniteStateMachinepublic S getState()
FiniteStateMachine.
Note: After returning the current state there's no guarantee that the state will be the same because a Transition may be executing asynchronously in the background on another thread.
getState in interface FiniteStateMachine<S extends Enum<S>>FiniteStateMachinepublic long getTransitionCount()
FiniteStateMachine.
Note: After returning the count there's no guarantee that the count will be the same on the next request because a Transition may be executing asynchronously in the background on another thread.
getTransitionCount in interface ExecutionContextgetTransitionCount in interface FiniteStateMachine<S extends Enum<S>>FiniteStateMachinepublic boolean start()
FiniteStateMachine and enter the initial state.
Note: Once stopped a FiniteStateMachine can't be restarted; instead a new FiniteStateMachine should be created.
start in interface FiniteStateMachine<S extends Enum<S>>true if the start was successful or the FiniteStateMachine is already stated, false if it has been stoppedpublic boolean stop()
FiniteStateMachine as soon as possible.
Note: Once stopped a FiniteStateMachine can't be restarted; instead a new FiniteStateMachine should be created.
stop in interface FiniteStateMachine<S extends Enum<S>>true if the stop was successful, false if it's already stoppedpublic boolean quiesceThenStop()
FiniteStateMachine to stop accepting new Events to process, wait for any existing queued Events to be processed and then stop.
Note: Once stopped a FiniteStateMachine can't be restarted. Instead a new FiniteStateMachine should be created.
true if the FiniteStateMachine was stopped or false if it was already stoppedIllegalStateException - if the FiniteStateMachine was never startedpublic void process(Event<S> event)
FiniteStateMachine to process the specified Event.
Note: There's no guarantee that the Event will be processed because:
Transition to be performed for the Event is invalid as the FiniteStateMachine is not in the required starting state.FiniteStateMachine may have been stopped.process in interface FiniteStateMachine<S extends Enum<S>>event - the Event for the FiniteStateMachine to processpublic void processLater(Event<S> event)
FiniteStateMachine to process the specified Event as soon as possible.
Note: This method is semantically equivalent to process(Event).
event - the Event for the FiniteStateMachine to processpublic void processLater(Event<S> event, long duration, TimeUnit timeUnit)
FiniteStateMachine to process the specified Event at some point in the future (represented as a duration to wait from the moment the method is called).
Note: There's no guarantee that the Event will processed because:
Transition to be performed for the Event is invalid as the FiniteStateMachine is not in the required starting state.FiniteStateMachine may have been stopped.event - the Event for the FiniteStateMachine to processduration - the amount of the TimeUnit to wait before the Event is processedtimeUnit - the TimeUnitpublic boolean hasPendingEvents()
Events for the FiniteStateMachine to process.
Note: If the FiniteStateMachine can no longer process Events false will be returned.