Class NonBlockingFiniteStateMachine<S extends Enum<S>>
- java.lang.Object
 - 
- com.tangosol.util.fsm.NonBlockingFiniteStateMachine<S>
 
 
- 
- All Implemented Interfaces:
 ExecutionContext,FiniteStateMachine<S>
public class NonBlockingFiniteStateMachine<S extends Enum<S>> extends Object implements FiniteStateMachine<S>, ExecutionContext
AnNonBlockingFiniteStateMachineis a specializedFiniteStateMachineimplementation 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.- Since:
 - Coherence 12.2.1
 - Author:
 - Brian Oliver
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNonBlockingFiniteStateMachine.CoalescedEvent<S extends Enum<S>>ANonBlockingFiniteStateMachine.CoalescedEventis aLifecycleAwareEventthat coalesces other (wrapped)Events with the same discriminator so that only oneEventactually executes.static classNonBlockingFiniteStateMachine.DefaultTaskDependenciesImplementation of Dependencies for Taskstatic classNonBlockingFiniteStateMachine.DelayedTransitionTo<S extends Enum<S>>ANonBlockingFiniteStateMachine.DelayedTransitionTois a specializedInstructionforNonBlockingFiniteStateMachines that enables aStateEntryActionto request a delayed transition to another state, unlike aInstruction.TransitionToInstructionwhich occurs immediately.static classNonBlockingFiniteStateMachine.ProcessEventLater<S extends Enum<S>>A specializedInstructionforNonBlockingFiniteStateMachines that enables aStateEntryActionto request anEventto be processed at some point in the future.static classNonBlockingFiniteStateMachine.SubsequentEvent<S extends Enum<S>>ANonBlockingFiniteStateMachine.SubsequentEventis anEventthat ensures that another (wrapped)Eventto occur if an only if theFiniteStateMachineis at a certain transition count.protected classNonBlockingFiniteStateMachine.TaskA PriorityTask implementation to process a requested event.static interfaceNonBlockingFiniteStateMachine.TaskDependenciesDependencies for Task. 
- 
Constructor Summary
Constructors Constructor Description NonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps)Construct anNonBlockingFiniteStateMachinegiven aModel. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(FiniteStateMachineListener<S> listener)Add aFiniteStateMachineListenerto theFiniteStateMachine.StringgetName()Obtains the name of theFiniteStateMachine.SgetState()Obtains the current state of theFiniteStateMachine.longgetTransitionCount()Obtains the number of transitions that have occurred in theFiniteStateMachine.booleanhasPendingEvents()Determines if there are any pendingEvents for theFiniteStateMachineto process.voidprocess(Event<S> event)Request theFiniteStateMachineto process the specifiedEvent.voidprocessLater(Event<S> event)Request theFiniteStateMachineto process the specifiedEventas soon as possible.voidprocessLater(Event<S> event, long duration, TimeUnit timeUnit)Request theFiniteStateMachineto process the specifiedEventat some point in the future (represented as a duration to wait from the moment the method is called).booleanquiesceThenStop()Requests theFiniteStateMachineto stop accepting newEvents to process, wait for any existing queuedEvents to be processed and then stop.voidremoveListener(FiniteStateMachineListener<S> listener)Remove aFiniteStateMachineListenerfrom theFiniteStateMachine.booleanstart()Start theFiniteStateMachineand enter the initial state.booleanstop()Stops theFiniteStateMachineas soon as possible.StringtoString() 
 - 
 
- 
- 
Constructor Detail
- 
NonBlockingFiniteStateMachine
public NonBlockingFiniteStateMachine(String sName, Model<S> model, S stateInitial, com.tangosol.internal.util.DaemonPoolDependencies daemonPoolDeps, boolean fIgnoreExceptions, NonBlockingFiniteStateMachine.TaskDependencies deps)
Construct anNonBlockingFiniteStateMachinegiven aModel.- Parameters:
 sName- the name of theNonBlockingFiniteStateMachinemodel- theModelof theNonBlockingFiniteStateMachinestateInitial- the initial statedaemonPoolDeps- OptionalDaemonPoolDependenciesfor Daemon Pool that will be used for schedulingTransitionsfIgnoreExceptions- whentrueRuntimeExceptions will be ignored, whenfalseRuntimeExceptions will immediately stop theNonBlockingFiniteStateMachinedeps- theNonBlockingFiniteStateMachine.TaskDependenciesspecifies the event processing configs.
 
 - 
 
- 
Method Detail
- 
addListener
public void addListener(FiniteStateMachineListener<S> listener)
Add aFiniteStateMachineListenerto theFiniteStateMachine.Note that unique instances of FiniteStateMachineListener are identified via their
equalsandhashCodeimplementations.- Specified by:
 addListenerin interfaceFiniteStateMachine<S extends Enum<S>>- Parameters:
 listener- the listener to be added
 
- 
removeListener
public void removeListener(FiniteStateMachineListener<S> listener)
Remove aFiniteStateMachineListenerfrom theFiniteStateMachine.Note that unique instances of FiniteStateMachineListener are identified via their
equalsandhashCodeimplementations.- Specified by:
 removeListenerin interfaceFiniteStateMachine<S extends Enum<S>>- Parameters:
 listener- the listener to be removed
 
- 
getName
public String getName()
Obtains the name of theFiniteStateMachine. This is primarily used for display/logging/monitoring purposes.- Specified by:
 getNamein interfaceExecutionContext- Specified by:
 getNamein interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
 - the name of the 
FiniteStateMachine 
 
- 
getState
public S getState()
Obtains the current state of theFiniteStateMachine.Note: After returning the current state there's no guarantee that the state will be the same because a
Transitionmay be executing asynchronously in the background on another thread.- Specified by:
 getStatein interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
 - the current state of the 
FiniteStateMachine 
 
- 
getTransitionCount
public long getTransitionCount()
Obtains the number of transitions that have occurred in theFiniteStateMachine.Note: After returning the count there's no guarantee that the count will be the same on the next request because a
Transitionmay be executing asynchronously in the background on another thread.- Specified by:
 getTransitionCountin interfaceExecutionContext- Specified by:
 getTransitionCountin interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
 - the number of transitions that have occurred in the 
FiniteStateMachine 
 
- 
start
public boolean start()
Start theFiniteStateMachineand enter the initial state.Note: Once stopped a
FiniteStateMachinecan't be restarted; instead a newFiniteStateMachineshould be created.- Specified by:
 startin interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
 trueif the start was successful or the FiniteStateMachine is already stated,falseif it has been stopped
 
- 
stop
public boolean stop()
Stops theFiniteStateMachineas soon as possible.Note: Once stopped a
FiniteStateMachinecan't be restarted; instead a newFiniteStateMachineshould be created.- Specified by:
 stopin interfaceFiniteStateMachine<S extends Enum<S>>- Returns:
 trueif the stop was successful,falseif it's already stopped
 
- 
quiesceThenStop
public boolean quiesceThenStop()
Requests theFiniteStateMachineto stop accepting newEvents to process, wait for any existing queuedEvents to be processed and then stop.Note: Once stopped a
FiniteStateMachinecan't be restarted. Instead a newFiniteStateMachineshould be created.- Returns:
 trueif theFiniteStateMachinewas stopped orfalseif it was already stopped- Throws:
 IllegalStateException- if the FiniteStateMachine was never started
 
- 
process
public void process(Event<S> event)
Request theFiniteStateMachineto process the specifiedEvent.Note: There's no guarantee that the
Eventwill be processed because:- the 
Transitionto be performed for theEventis invalid as theFiniteStateMachineis not in the required starting state. - the 
FiniteStateMachinemay have been stopped. 
- Specified by:
 processin interfaceFiniteStateMachine<S extends Enum<S>>- Parameters:
 event- theEventfor theFiniteStateMachineto process
 - the 
 
- 
processLater
public void processLater(Event<S> event)
Request theFiniteStateMachineto process the specifiedEventas soon as possible.Note: This method is semantically equivalent to
process(Event).- Parameters:
 event- theEventfor theFiniteStateMachineto process
 
- 
processLater
public void processLater(Event<S> event, long duration, TimeUnit timeUnit)
Request theFiniteStateMachineto process the specifiedEventat 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
Eventwill processed because:- the 
Transitionto be performed for theEventis invalid as theFiniteStateMachineis not in the required starting state. - the 
FiniteStateMachinemay have been stopped. 
- Parameters:
 event- theEventfor theFiniteStateMachineto processduration- the amount of theTimeUnitto wait before theEventis processedtimeUnit- theTimeUnit
 - the 
 
- 
hasPendingEvents
public boolean hasPendingEvents()
Determines if there are any pendingEvents for theFiniteStateMachineto process.Note: If the
FiniteStateMachinecan no longer processEvents false will be returned. 
 - 
 
 -