Package org.glassfish.grizzly.asyncqueue
Class TaskQueue<E extends AsyncQueueRecord>
- java.lang.Object
-
- org.glassfish.grizzly.asyncqueue.TaskQueue<E>
-
- 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TaskQueue.MutableMaxQueueSize
-
Field Summary
Fields Modifier and Type Field Description protected Queue<WriteHandler>
writeHandlersQueue
-
Constructor Summary
Constructors Modifier Constructor Description protected
TaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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)
Queue<E>
getQueue()
Get the queue of tasks, which will be processed asynchronouslyboolean
isEmpty()
void
notifyWritePossible(WriteHandler writeHandler)
void
notifyWritePossible(WriteHandler writeHandler, int maxQueueSize)
void
offer(E task)
Add the new task into the task queue.void
onClose()
void
onClose(Throwable cause)
E
peek()
Get the current processing task, if the current in not set, take the task from the queue.E
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(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
size()
Returns the number of queued bytes.int
spaceInBytes()
Returns the number of queued bytes.
-
-
-
Field Detail
-
writeHandlersQueue
protected final Queue<WriteHandler> writeHandlersQueue
-
-
Constructor Detail
-
TaskQueue
protected TaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
-
-
Method Detail
-
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
public E 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
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 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
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.
-
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)
-
-