Package com.wavefront.agent.queueing
Class FileBasedTaskQueue<T extends DataSubmissionTask<T>>
- java.lang.Object
-
- com.wavefront.agent.queueing.FileBasedTaskQueue<T>
-
- Type Parameters:
T- type of objects stored.
public class FileBasedTaskQueue<T extends DataSubmissionTask<T>> extends Object implements TaskQueue<T>
- Author:
- [email protected]
-
-
Constructor Summary
Constructors Constructor Description FileBasedTaskQueue(QueueFile queueFile, TaskConverter<T> taskConverter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T entry)Add a task to the end of the queuevoidclear()Empty and re-initialize the queue.voidclose()Close the queue.LonggetAvailableBytes()Returns the total number of pre-allocated but unused bytes in the backing file.Iterator<T>iterator()Tpeek()Retrieve a task that is currently at the head of the queue.voidremove()Remove a task from the head of the queue.intsize()Returns a number of tasks currently in the queue.Longweight()Returns the total weight of the queue (sum of weights of all tasks).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
FileBasedTaskQueue
public FileBasedTaskQueue(QueueFile queueFile, TaskConverter<T> taskConverter)
- Parameters:
queueFile- file backing the queuetaskConverter- task converter
-
-
Method Detail
-
peek
public T peek()
Description copied from interface:TaskQueueRetrieve a task that is currently at the head of the queue.- Specified by:
peekin interfaceTaskQueue<T extends DataSubmissionTask<T>>- Returns:
- task object
-
add
public void add(@Nonnull T entry) throws IOException
Description copied from interface:TaskQueueAdd a task to the end of the queue- Specified by:
addin interfaceTaskQueue<T extends DataSubmissionTask<T>>- Parameters:
entry- task- Throws:
IOException- IO exceptions caught by the storage engine
-
clear
public void clear() throws IOExceptionDescription copied from interface:TaskQueueEmpty and re-initialize the queue.- Specified by:
clearin interfaceTaskQueue<T extends DataSubmissionTask<T>>- Throws:
IOException
-
remove
public void remove() throws IOExceptionDescription copied from interface:TaskQueueRemove a task from the head of the queue. Requires peek() to be called first, otherwise anIllegalStateExceptionis thrown.- Specified by:
removein interfaceTaskQueue<T extends DataSubmissionTask<T>>- Throws:
IOException- IO exceptions caught by the storage engine
-
size
public int size()
Description copied from interface:TaskQueueReturns a number of tasks currently in the queue.- Specified by:
sizein interfaceTaskQueue<T extends DataSubmissionTask<T>>- Returns:
- number of tasks
-
close
public void close() throws IOExceptionDescription copied from interface:TaskQueueClose the queue. Should be invoked before a graceful shutdown.- Specified by:
closein interfaceTaskQueue<T extends DataSubmissionTask<T>>- Throws:
IOException
-
weight
@Nullable public Long weight()
Description copied from interface:TaskQueueReturns the total weight of the queue (sum of weights of all tasks).- Specified by:
weightin interfaceTaskQueue<T extends DataSubmissionTask<T>>- Returns:
- weight of the queue (null if unknown)
-
getAvailableBytes
@Nullable public Long getAvailableBytes()
Description copied from interface:TaskQueueReturns the total number of pre-allocated but unused bytes in the backing file. May return null if not applicable.- Specified by:
getAvailableBytesin interfaceTaskQueue<T extends DataSubmissionTask<T>>- Returns:
- total number of available bytes in the file or null
-
-