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

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

public final class TaskQueue<E>
extends Object

Class represents common implementation of asynchronous processing queue.

Author:
Alexey Stashok

Nested Class Summary
static interface TaskQueue.MutableMaxQueueSize
           
 
Field Summary
protected  Queue<org.glassfish.grizzly.asyncqueue.TaskQueue.WriteHandlerQueueRecord> writeHandlersQueue
           
 
Constructor Summary
protected TaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
           
 
Method Summary
static
<E> TaskQueue<E>
createTaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
           
 void doNotify()
           
 boolean forgetWritePossible(WriteHandler writeHandler)
           
 Queue<E> getQueue()
          Get the queue of tasks, which will be processed asynchronously
 AtomicInteger getRefusedBytes()
          Get refused bytes counter.
 boolean isEmpty()
           
 void notifyWritePossible(WriteHandler writeHandler, int size)
           
 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.
 void onClose()
           
 int releaseSpace(int amount)
          Releases memory space in the queue.
 int releaseSpaceAndNotify(int amount)
          Releases memory space in the queue and notifies registered QueueMonitors about the update.
 boolean remove(E task)
          Remove the task from queue.
 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

writeHandlersQueue

protected final Queue<org.glassfish.grizzly.asyncqueue.TaskQueue.WriteHandlerQueueRecord> writeHandlersQueue
Constructor Detail

TaskQueue

protected TaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
Method Detail

createTaskQueue

public static <E> TaskQueue<E> createTaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)

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)
Releases memory space in the queue and notifies registered QueueMonitors about the update.

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.

getRefusedBytes

public AtomicInteger getRefusedBytes()
Get refused bytes counter.


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

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,
                                int size)

forgetWritePossible

public final boolean forgetWritePossible(WriteHandler writeHandler)

doNotify

public void doNotify()

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

onClose

public void onClose()


Copyright © 2013 Oracle Corporation. All Rights Reserved.