Atomically transition the state of the FSM.
Atomically transition the state of the FSM. After successfully transitioning to a new state, calls the onTransition method with the previous state and the new state exactly once. Note: all state transition side effects should be placed in the onTransition method
partial function that accepts the current state and returns the next state
partial function that invokes side effects after a successful state transition
the new state
java.lang.IllegalArgumentException
if the transition function is
undefined for some state
Atomically transition the state of the FSM and return the value associated with that new state.
Atomically transition the state of the FSM and return the value associated with that new state. After successfully transitioning to a new state, calls the onTransition method with the previous state and the new state exactly once. Note: all state transition side effects should be placed in the onTransition method
partial function that accepts the current state and returns the next state and the return value
partial function that invokes side effects after a successful state transition
the value associated with the new state
java.lang.IllegalArgumentException
if the transition function is
undefined for some state
A class for a finite state machine whose state may be transitioned atomically by any number of concurrent threads.
During the time it takes to compute a new state for the FSM, another thread may change the FSMs state, invalidating the newly computed state. To deal with this issue, AtomicFSM stores the state of the FSM using AtomicReference and after computing a new state, uses AtomicReference CAS to atomically compare the current state to the one originally used to compute the new state. If the current state does not match the original state used to compute the new state, then CAS update fails and the new state is discarded. The whole process is repeated using the updated current state. This will repeat until a new computed state successfully changes the current state. Because states may be discarded and transition functions invoked multiple times during this process, states and transition functions should never create side effects themselves. Instead all transition side effects should be placed in the onTransition function. When a state is successfully transitioned, onTransition is called with both the original and new state. This method can be used to safely create state transition side effects.
the type of state