Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.asyncqueue

public final Class TaskQueue<E extends AsyncQueueRecord<R>>

extends Object
Class Inheritance
Type Parameters
<E>
AsyncQueueRecord type
Imports
java.io.IOException, java.util.Queue, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, .AtomicReferenceFieldUpdater, org.glassfish.grizzly.WriteHandler

Class represents common implementation of asynchronous processing queue.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private volatile E
private static final AtomicReferenceFieldUpdater<TaskQueue<E extends AsyncQueueRecord<R>>, AsyncQueueRecord<R>>
private volatile boolean
private final TaskQueue.MutableMaxQueueSize
private final Queue<E>
queue

The queue of tasks, which will be processed asynchronously

private volatile int
private static final AtomicIntegerFieldUpdater<TaskQueue<E extends AsyncQueueRecord<R>>>
private volatile int
private static final AtomicIntegerFieldUpdater<TaskQueue<E extends AsyncQueueRecord<R>>>
protected final Queue<WriteHandler>

Constructor Summary

AccessConstructor and Description
protected
TaskQueue(final TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)

Method Summary

Modifier and TypeMethod and Description
private void
public boolean
compareAndSetCurrentElement(final E expected, final E newValue)

public static <E extends AsyncQueueRecord<R>> TaskQueue<E>
createTaskQueue(final TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)

public void
doNotify()

Notifies processing the queue by write handlers.

public boolean
forgetWritePossible(final WriteHandler writeHandler)

public Queue<E>

Returns:

the queue of tasks, which will be processed asynchronously
getQueue
()

Get the queue of tasks, which will be processed asynchronously

public boolean
public void
notifyWritePossible(final WriteHandler writeHandler)

public void
notifyWritePossible(final WriteHandler writeHandler, final int maxQueueSize)

public void
offer(final E
new task.
task
)

Add the new task into the task queue.

private void
offerWriteHandler(final WriteHandler writeHandler)

public void
public void
onClose(final Throwable cause)

public E

Returns:

the current processing task
peek
()

Get the current processing task, if the current in not set, take the task from the queue.

public E

Returns:

the current processing task
poll
()

Pools the current processing task.

private WriteHandler
public int

Returns:

the new memory (in bytes) consumed by the queue.
releaseSpace
(final int amount)

Releases memory space in the queue.

public int

Returns:

the new memory (in bytes) consumed by the queue.
releaseSpaceAndNotify
(final int amount)

Releases memory space in the queue and notifies registered QueueMonitors about the update.

public boolean

Returns:

true if tasked was removed, or false otherwise.
remove
(final E
the task to remove.
task
)

Remove the task from queue.

private boolean
removeWriteHandler(final WriteHandler writeHandler)

public int

Returns:

the new memory (in bytes) consumed by the queue.
reserveSpace
(final int amount)

Reserves memory space in the queue.

public void
setCurrentElement(final E
current element.
task
)

Set current task element.

public int

Returns:

the number of queued bytes.
size
()

Returns the number of queued bytes.

public int

Returns:

the number of queued bytes.
spaceInBytes
()

Returns the number of queued bytes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentElementback to summary
private volatile E currentElement
currentElementUpdaterback to summary
private static final AtomicReferenceFieldUpdater<TaskQueue<E extends AsyncQueueRecord<R>>, AsyncQueueRecord<R>> currentElementUpdater
isClosedback to summary
private volatile boolean isClosed
maxQueueSizeHolderback to summary
private final TaskQueue.MutableMaxQueueSize maxQueueSizeHolder
queueback to summary
private final Queue<E> queue

The queue of tasks, which will be processed asynchronously

spaceInBytesback to summary
private volatile int spaceInBytes
spaceInBytesUpdaterback to summary
private static final AtomicIntegerFieldUpdater<TaskQueue<E extends AsyncQueueRecord<R>>> spaceInBytesUpdater
writeHandlersCounterback to summary
private volatile int writeHandlersCounter
writeHandlersCounterUpdaterback to summary
private static final AtomicIntegerFieldUpdater<TaskQueue<E extends AsyncQueueRecord<R>>> writeHandlersCounterUpdater
writeHandlersQueueback to summary
protected final Queue<WriteHandler> writeHandlersQueue

Constructor Detail

TaskQueueback to summary
protected TaskQueue(final TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)

Method Detail

checkWriteHandlerOnCloseback to summary
private void checkWriteHandlerOnClose(final WriteHandler writeHandler)
compareAndSetCurrentElementback to summary
public boolean compareAndSetCurrentElement(final E expected, final E newValue)
createTaskQueueback to summary
public static <E extends AsyncQueueRecord<R>> TaskQueue<E> createTaskQueue(final TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
doNotifyback to summary
public void doNotify()

Notifies processing the queue by write handlers.

forgetWritePossibleback to summary
public boolean forgetWritePossible(final WriteHandler writeHandler)
getQueueback to summary
public Queue<E> getQueue()

Get the queue of tasks, which will be processed asynchronously

Returns:Queue<E>

the queue of tasks, which will be processed asynchronously

isEmptyback to summary
public boolean isEmpty()
notifyWritePossibleback to summary
public void notifyWritePossible(final WriteHandler writeHandler)
notifyWritePossibleback to summary
public void notifyWritePossible(final WriteHandler writeHandler, final int maxQueueSize)
offerback to summary
public void offer(final E task)

Add the new task into the task queue.

Parameters
task:E

new task.

offerWriteHandlerback to summary
private void offerWriteHandler(final WriteHandler writeHandler)
onCloseback to summary
public void onClose()
onCloseback to summary
public void onClose(final Throwable cause)
peekback to summary
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:E

the current processing task

pollback to summary
public E poll()

Pools the current processing task.

Note

after this operation call, any element could be put at the head of the queue using setCurrentElement(org.glassfish.grizzly.asyncqueue.AsyncQueueRecord) without overwriting any existing queue element.

Returns:E

the current processing task

Annotations
@SuppressWarnings:unchecked
pollWriteHandlerback to summary
private WriteHandler pollWriteHandler()
releaseSpaceback to summary
public int releaseSpace(final int amount)

Releases memory space in the queue.

Returns:int

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

releaseSpaceAndNotifyback to summary
public int releaseSpaceAndNotify(final int amount)

Releases memory space in the queue and notifies registered QueueMonitors about the update.

Returns:int

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

removeback to summary
public boolean remove(final E task)

Remove the task from queue.

Parameters
task:E

the task to remove.

Returns:boolean

true if tasked was removed, or false otherwise.

removeWriteHandlerback to summary
private boolean removeWriteHandler(final WriteHandler writeHandler)
reserveSpaceback to summary
public int reserveSpace(final int amount)

Reserves memory space in the queue.

Returns:int

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

setCurrentElementback to summary
public void setCurrentElement(final E task)

Set current task element.

Parameters
task:E

current element.

sizeback to summary
public int size()

Returns the number of queued bytes.

Returns:int

the number of queued bytes.

spaceInBytesback to summary
public int spaceInBytes()

Returns the number of queued bytes.

Returns:int

the number of queued bytes.

org.glassfish.grizzly.asyncqueue back to summary

public Interface TaskQueue.MutableMaxQueueSize


Method Summary

Modifier and TypeMethod and Description
public int

Method Detail

getMaxQueueSizeback to summary
public int getMaxQueueSize()