Package akka.dispatch

Class AbstractNodeQueue<T>

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    NodeMessageQueue

    public abstract class AbstractNodeQueue<T>
    extends java.util.concurrent.atomic.AtomicReference<AbstractNodeQueue.Node<T>>
    Lock-free MPSC linked queue implementation based on Dmitriy Vyukov's non-intrusive MPSC queue: http://www.1024cores.net/home/lock-free-algorithms/queues/non-intrusive-mpsc-node-based-queue This queue could be wait-free (i.e. without the spinning loops in peekNode and pollNode) if it were permitted to return null while the queue is not quite empty anymore but the enqueued element is not yet visible. This would break actor scheduling, though.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractNodeQueue()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(T value)
      Add an element to the head of the queue.
      void addNode​(AbstractNodeQueue.Node<T> n)
      Add an element to the head of the queue, providing the queue node to be used.
      int count()
      This method returns an upper bound on the queue size at the time it starts executing.
      boolean isEmpty()
      Query the queue whether it is empty right now.
      T peek()
      Query the queue tail for the next element without dequeuing it.
      protected AbstractNodeQueue.Node<T> peekNode()
      Query the queue tail for the next element without dequeuing it.
      T poll()
      Pull one item from the queue’s tail if there is one.
      AbstractNodeQueue.Node<T> pollNode()
      Pull one item from the queue, returning it within a queue node.
      • Methods inherited from class java.util.concurrent.atomic.AtomicReference

        accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AbstractNodeQueue

        protected AbstractNodeQueue()
    • Method Detail

      • peekNode

        protected final AbstractNodeQueue.Node<T> peekNode()
        Query the queue tail for the next element without dequeuing it. Use this method only from the consumer thread! !!! There is a copy of this code in pollNode() !!!
        Returns:
        queue node with element inside if there was one, or null if there was none
      • peek

        public final T peek()
        Query the queue tail for the next element without dequeuing it. Use this method only from the consumer thread!
        Returns:
        element if there was one, or null if there was none
      • add

        public final void add​(T value)
        Add an element to the head of the queue. This method can be used from any thread.
        Parameters:
        value - the element to be added; must not be null
      • addNode

        public final void addNode​(AbstractNodeQueue.Node<T> n)
        Add an element to the head of the queue, providing the queue node to be used. This method can be used from any thread.
        Parameters:
        n - the node containing the element to be added; both must not be null
      • isEmpty

        public final boolean isEmpty()
        Query the queue whether it is empty right now. This method can be used from any thread.
        Returns:
        true if queue was empty at some point in the past
      • count

        public final int count()
        This method returns an upper bound on the queue size at the time it starts executing. It may spuriously return smaller values (including zero) if the consumer pulls items out concurrently. This method can be used from any thread.
        Returns:
        an upper bound on queue length at some time in the past
      • poll

        public final T poll()
        Pull one item from the queue’s tail if there is one. Use this method only from the consumer thread!
        Returns:
        element if there was one, or null if there was none
      • pollNode

        public final AbstractNodeQueue.Node<T> pollNode()
        Pull one item from the queue, returning it within a queue node. Use this method only from the consumer thread!
        Returns:
        queue node with element inside if there was one, or null if there was none