Class DisruptorQueue<ID,​DATA>

  • All Implemented Interfaces:
    IQueue<ID,​DATA>, AutoCloseable
    Direct Known Subclasses:
    BaseUniversalDisruptorQueue

    public class DisruptorQueue<ID,​DATA>
    extends AbstractInmemEphemeralQueue<ID,​DATA>
    In-Memory implementation of IQueue using LMAX Disruptor library.

    Implementation:

    • A Disruptor's RingBuffer to be the queue storage.
    • A ConcurrentMap as ephemeral storage.

    Features:

    • Queue-size support: yes
    • Ephemeral storage support: yes
    • Ephemeral-size support: yes
    Since:
    0.4.0
    Author:
    Thanh Ba Nguyen
    See Also:
    LMAXDisruptor
    • Constructor Detail

      • DisruptorQueue

        public DisruptorQueue()
      • DisruptorQueue

        public DisruptorQueue​(int ringSize)
    • Method Detail

      • getRingSize

        protected int getRingSize()
        Size of the ring buffer, should be power of 2.
        Returns:
      • setRingSize

        public DisruptorQueue<ID,​DATA> setRingSize​(int ringSize)
        Size of the ring buffer, should be power of 2.
        Parameters:
        ringSize -
        Returns:
      • finish

        public void finish​(IQueueMessage<ID,​DATA> msg)
        Called when finish processing the message to cleanup ephemeral storage.

        Implementation flow:

        • Remove message from ephemeral storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

      • takeFromRingBuffer

        protected IQueueMessage<ID,​DATA> takeFromRingBuffer()
        Take a message from the ring buffer.
        Returns:
        the available message or null if the ring buffer is empty
      • take

        public IQueueMessage<ID,​DATA> take()
                                          throws QueueException.EphemeralIsFull
        Take a message out of queue.

        Implementation flow:

        • Read message from head of queue storage.
        • Write message to ephemeral storage.
        • Remove message from queue storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

        Returns:
        Throws:
        QueueException.EphemeralIsFull - if the ephemeral storage is full
      • queueSize

        public int queueSize()
        Get number of items currently in queue storage.
        Returns:
        negative number if queue size can not be queried