Package org.glassfish.grizzly.asyncqueue
Class TaskQueue<E extends AsyncQueueRecord>
- java.lang.Object
-
- org.glassfish.grizzly.asyncqueue.TaskQueue<E>
-
- Type Parameters:
E-AsyncQueueRecordtype
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 interfaceTaskQueue.MutableMaxQueueSize
-
Field Summary
Fields Modifier and Type Field Description protected Queue<WriteHandler>writeHandlersQueue
-
Constructor Summary
Constructors Modifier Constructor Description protectedTaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancompareAndSetCurrentElement(E expected, E newValue)static <E extends AsyncQueueRecord>
TaskQueue<E>createTaskQueue(TaskQueue.MutableMaxQueueSize maxQueueSizeHolder)voiddoNotify()Notifies processing the queue by write handlers.booleanforgetWritePossible(WriteHandler writeHandler)Queue<E>getQueue()Get the queue of tasks, which will be processed asynchronouslybooleanisEmpty()voidnotifyWritePossible(WriteHandler writeHandler)voidnotifyWritePossible(WriteHandler writeHandler, int maxQueueSize)voidoffer(E task)Add the new task into the task queue.voidonClose()voidonClose(Throwable cause)Epeek()Get the current processing task, if the current in not set, take the task from the queue.Epoll()Pools the current processing task.intreleaseSpace(int amount)Releases memory space in the queue.intreleaseSpaceAndNotify(int amount)Releases memory space in the queue and notifies registeredQueueMonitors about the update.booleanremove(E task)Remove the task from queue.intreserveSpace(int amount)Reserves memory space in the queue.voidsetCurrentElement(E task)Set current task element.intsize()Returns the number of queued bytes.intspaceInBytes()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 registeredQueueMonitors 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)
-
-