org.glassfish.grizzly.asyncqueue
Class TaskQueue<E>

java.lang.Object
  extended by org.glassfish.grizzly.asyncqueue.TaskQueue<E>

public final class TaskQueue<E>
extends java.lang.Object

Class represents common implementation of asynchronous processing queue.

Author:
Alexey Stashok

Nested Class Summary
static class TaskQueue.QueueMonitor
          Notification mechanism which will be invoked when releaseSpace(int) or releaseSpaceAndNotify(int) is called.
 
Field Summary
protected  java.util.Queue<TaskQueue.QueueMonitor> monitorQueue
           
 
Constructor Summary
protected TaskQueue()
           
 
Method Summary
 boolean addQueueMonitor(TaskQueue.QueueMonitor monitor)
          Get the queue of tasks, which will be processed asynchronously
static
<E> TaskQueue<E>
createTaskQueue()
           
protected  void doNotify()
           
 boolean isEmpty()
           
 E obtainCurrentElement()
          Get the current processing task, if the current in not set, take the task from the queue.
 E obtainCurrentElementAndReserve()
          Gets the current processing task and reserves its place.
 void offer(E task)
          Add the new task into the task queue.
 int releaseSpace(int amount)
          Releases memory space in the queue.
 int releaseSpaceAndNotify(int amount)
          Releases memory space in the queue and notifies registered TaskQueue.QueueMonitors about the update.
 boolean remove(E task)
          Remove the task from queue.
 void removeQueueMonitor(TaskQueue.QueueMonitor monitor)
           
 int reserveSpace(int amount)
          Reserves memory space in the queue.
 void setCurrentElement(E task)
          Set current task element.
 int spaceInBytes()
          Returns the number of queued bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

monitorQueue

protected final java.util.Queue<TaskQueue.QueueMonitor> monitorQueue
Constructor Detail

TaskQueue

protected TaskQueue()
Method Detail

createTaskQueue

public static <E> TaskQueue<E> createTaskQueue()

reserveSpace

public int reserveSpace(int amount)
Reserves memory space in the queue.

Returns:
the new memory (in bytes) consumed by the queue.

releaseSpace

public int releaseSpace(int amount)
Releases memory space in the queue.

Returns:
the new memory (in bytes) consumed by the queue.

releaseSpaceAndNotify

public int releaseSpaceAndNotify(int amount)
                          throws java.io.IOException
Releases memory space in the queue and notifies registered TaskQueue.QueueMonitors about the update.

Returns:
the new memory (in bytes) consumed by the queue.
Throws:
java.io.IOException

spaceInBytes

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

Returns:
the number of queued bytes.

obtainCurrentElement

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

Returns:
the current processing task

obtainCurrentElementAndReserve

public E obtainCurrentElementAndReserve()
Gets the current processing task and reserves its place.

Returns:
the current processing task

addQueueMonitor

public boolean addQueueMonitor(TaskQueue.QueueMonitor monitor)
                        throws java.io.IOException
Get the queue of tasks, which will be processed asynchronously

Returns:
the queue of tasks, which will be processed asynchronously
Throws:
java.io.IOException

removeQueueMonitor

public void removeQueueMonitor(TaskQueue.QueueMonitor monitor)

doNotify

protected void doNotify()
                 throws java.io.IOException
Throws:
java.io.IOException

setCurrentElement

public void setCurrentElement(E task)
Set current task element.

Parameters:
task - current element.

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()


Copyright © 2011 Oracle Corpration. All Rights Reserved.