Class TaskQueue<E extends AsyncQueueRecord>

  • Type Parameters:
    E - AsyncQueueRecord type

    public final class TaskQueue<E extends AsyncQueueRecord>
    extends Object
    Class represents common implementation of asynchronous processing queue.
    Author:
    Alexey Stashok
    • Method Detail

      • size

        public int size()
        Returns the number of queued bytes.
        Returns:
        the number of queued bytes.
      • peek

        public E peek()
        Get the current processing task, if the current in not set, take the task from the queue.

        Note: after this operation call, the current element could be removed from the queue using setCurrentElement(org.glassfish.grizzly.asyncqueue.AsyncQueueRecord) and passing null as a parameter, this is a little bit more optimal alternative to poll().

        Returns:
        the current processing task
      • reserveSpace

        public int reserveSpace​(int amount)
        Reserves memory space in the queue.
        Parameters:
        amount -
        Returns:
        the new memory (in bytes) consumed by the queue.
      • releaseSpace

        public int releaseSpace​(int amount)
        Releases memory space in the queue.
        Parameters:
        amount -
        Returns:
        the new memory (in bytes) consumed by the queue.
      • releaseSpaceAndNotify

        public int releaseSpaceAndNotify​(int amount)
        Releases memory space in the queue and notifies registered QueueMonitors about the update.
        Parameters:
        amount -
        Returns:
        the new memory (in bytes) consumed by the queue.
      • spaceInBytes

        public int spaceInBytes()
        Returns the number of queued bytes.
        Returns:
        the number of queued bytes.
      • getQueue

        public Queue<E> getQueue()
        Get the queue of tasks, which will be processed asynchronously
        Returns:
        the queue of tasks, which will be processed asynchronously
      • notifyWritePossible

        public void notifyWritePossible​(WriteHandler writeHandler)
      • notifyWritePossible

        public void notifyWritePossible​(WriteHandler writeHandler,
                                        int maxQueueSize)
      • forgetWritePossible

        public boolean forgetWritePossible​(WriteHandler writeHandler)
      • doNotify

        public void doNotify()
        Notifies processing the queue by write handlers.
      • setCurrentElement

        public void setCurrentElement​(E task)
        Set current task element.
        Parameters:
        task - current element.
      • compareAndSetCurrentElement

        public boolean compareAndSetCurrentElement​(E expected,
                                                   E newValue)
      • remove

        public boolean remove​(E task)
        Remove the task from queue.
        Parameters:
        task - the task to remove.
        Returns:
        true if tasked was removed, or false otherwise.
      • offer

        public void offer​(E task)
        Add the new task into the task queue.
        Parameters:
        task - new task.
      • isEmpty

        public boolean isEmpty()
      • onClose

        public void onClose()
      • onClose

        public void onClose​(Throwable cause)