Module org.glassfish.grizzly
Package org.glassfish.grizzly.asyncqueue
Class TaskQueue<E extends AsyncQueueRecord>
java.lang.Object
org.glassfish.grizzly.asyncqueue.TaskQueue<E>
- Type Parameters:
E
-AsyncQueueRecord
type
Class represents common implementation of asynchronous processing queue.
- Author:
- Alexey Stashok
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TaskQueue
(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder) -
Method Summary
Modifier and TypeMethodDescriptionboolean
compareAndSetCurrentElement
(E expected, E newValue) static <E extends AsyncQueueRecord>
TaskQueue<E>createTaskQueue
(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder) void
doNotify()
Notifies processing the queue by write handlers.boolean
forgetWritePossible
(WriteHandler writeHandler) getQueue()
Get the queue of tasks, which will be processed asynchronouslyboolean
isEmpty()
void
notifyWritePossible
(WriteHandler writeHandler) void
notifyWritePossible
(WriteHandler writeHandler, int maxQueueSize) void
Add the new task into the task queue.void
onClose()
void
peek()
Get the current processing task, if the current in not set, take the task from the queue.poll()
Pools the current processing task.int
releaseSpace
(int amount) Releases memory space in the queue.int
releaseSpaceAndNotify
(int amount) Releases memory space in the queue and notifies registeredQueueMonitor
s about the update.boolean
Remove the task from queue.int
reserveSpace
(int amount) Reserves memory space in the queue.void
setCurrentElement
(E task) Set current task element.int
size()
Returns the number of queued bytes.int
Returns the number of queued bytes.
-
Field Details
-
writeHandlersQueue
-
-
Constructor Details
-
TaskQueue
-
-
Method Details
-
createTaskQueue
public static <E extends AsyncQueueRecord> TaskQueue<E> createTaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder) -
size
public int size()Returns the number of queued bytes.- Returns:
- the number of queued bytes.
-
poll
Pools the current processing task. Note: after this operation call, any element could be put at the head of the queue usingsetCurrentElement(org.glassfish.grizzly.asyncqueue.AsyncQueueRecord)
without overwriting any existing queue element.- Returns:
- the current processing task
-
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 topoll()
.- 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 registeredQueueMonitor
s 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
Get the queue of tasks, which will be processed asynchronously- Returns:
- the queue of tasks, which will be processed asynchronously
-
notifyWritePossible
-
notifyWritePossible
-
forgetWritePossible
-
doNotify
public void doNotify()Notifies processing the queue by write handlers. -
setCurrentElement
Set current task element.- Parameters:
task
- current element.
-
compareAndSetCurrentElement
-
remove
Remove the task from queue.- Parameters:
task
- the task to remove.- Returns:
- true if tasked was removed, or false otherwise.
-
offer
Add the new task into the task queue.- Parameters:
task
- new task.
-
isEmpty
public boolean isEmpty() -
onClose
public void onClose() -
onClose
-