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.CoalescedEventis aLifecycleAwareEventthat coalesces other (wrapped)Events with the same discriminator so that only oneEventactually executes. | 
| static class  | NonBlockingFiniteStateMachine.DefaultTaskDependenciesImplementation of Dependencies for Task | 
| static class  | NonBlockingFiniteStateMachine.DelayedTransitionTo<S extends Enum<S>>A  NonBlockingFiniteStateMachine.DelayedTransitionTois a specializedInstructionforNonBlockingFiniteStateMachines that enables aStateEntryActionto request a delayed transition to another state, unlike aInstruction.TransitionToInstructionwhich occurs immediately. | 
| static class  | NonBlockingFiniteStateMachine.ProcessEventLater<S extends Enum<S>>A specialized  InstructionforNonBlockingFiniteStateMachines that enables aStateEntryActionto request anEventto be processed at some point in the future. | 
| static class  | NonBlockingFiniteStateMachine.SubsequentEvent<S extends Enum<S>>A  NonBlockingFiniteStateMachine.SubsequentEventis anEventthat ensures that another (wrapped)Eventto occur if an only if theFiniteStateMachineis at a certain transition count. | 
| protected class  | NonBlockingFiniteStateMachine.TaskA PriorityTask implementation to process a requested event. | 
| static interface  | NonBlockingFiniteStateMachine.TaskDependenciesDependencies 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  NonBlockingFiniteStateMachinegiven aModel. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addListener(FiniteStateMachineListener<S> listener)Add a  FiniteStateMachineListenerto theFiniteStateMachine. | 
| 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 theFiniteStateMachineto process. | 
| void | process(Event<S> event)Request the  FiniteStateMachineto process the specifiedEvent. | 
| void | processLater(Event<S> event)Request the  FiniteStateMachineto process the specifiedEventas soon as possible. | 
| void | processLater(Event<S> event, long duration, TimeUnit timeUnit)Request the  FiniteStateMachineto process the specifiedEventat some point in the future (represented as a duration to wait from the moment the method is called). | 
| boolean | quiesceThenStop()Requests the  FiniteStateMachineto stop accepting newEvents to process, wait for any existing queuedEvents to be processed and then stop. | 
| void | removeListener(FiniteStateMachineListener<S> listener)Remove a  FiniteStateMachineListenerfrom theFiniteStateMachine. | 
| boolean | start()Start the  FiniteStateMachineand enter the initial state. | 
| boolean | stop()Stops the  FiniteStateMachineas 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.