Class

s_mach.concurrent.util

AtomicFSM

Related Doc: package util

Permalink

class AtomicFSM[S] extends AtomicReference[S]

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.

S

the type of state

Linear Supertypes
AtomicReference[S], Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AtomicFSM
  2. AtomicReference
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AtomicFSM(s0: S)

    Permalink

    s0

    the initial state

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def accumulateAndGet(arg0: S, arg1: BinaryOperator[S]): S

    Permalink
    Definition Classes
    AtomicReference
  5. def apply(transition: PartialFunction[S, S], onTransition: PartialFunction[(S, S), Unit] = PartialFunction.empty): S

    Permalink

    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

    transition

    partial function that accepts the current state and returns the next state

    onTransition

    partial function that invokes side effects after a successful state transition

    returns

    the new state

    Exceptions thrown

    java.lang.IllegalArgumentException if the transition function is undefined for some state

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def compareAndSet(arg0: S, arg1: S): Boolean

    Permalink
    Definition Classes
    AtomicReference
  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def fold[X](transition: PartialFunction[S, (S, X)], onTransition: PartialFunction[(S, S), Unit] = PartialFunction.empty): X

    Permalink

    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

    transition

    partial function that accepts the current state and returns the next state and the return value

    onTransition

    partial function that invokes side effects after a successful state transition

    returns

    the value associated with the new state

    Exceptions thrown

    java.lang.IllegalArgumentException if the transition function is undefined for some state

  13. final def get(): S

    Permalink
    Definition Classes
    AtomicReference
  14. final def getAndAccumulate(arg0: S, arg1: BinaryOperator[S]): S

    Permalink
    Definition Classes
    AtomicReference
  15. final def getAndSet(arg0: S): S

    Permalink
    Definition Classes
    AtomicReference
  16. final def getAndUpdate(arg0: UnaryOperator[S]): S

    Permalink
    Definition Classes
    AtomicReference
  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  20. final def lazySet(arg0: S): Unit

    Permalink
    Definition Classes
    AtomicReference
  21. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. final def set(arg0: S): Unit

    Permalink
    Definition Classes
    AtomicReference
  25. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  26. def toString(): String

    Permalink
    Definition Classes
    AtomicReference → AnyRef → Any
  27. final def updateAndGet(arg0: UnaryOperator[S]): S

    Permalink
    Definition Classes
    AtomicReference
  28. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def weakCompareAndSet(arg0: S, arg1: S): Boolean

    Permalink
    Definition Classes
    AtomicReference

Inherited from AtomicReference[S]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped