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 void
add(T entry)
Add a task to the end of the queuevoid
clear()
Empty and re-initialize the queue.void
close()
Close the queue.Long
getAvailableBytes()
Returns the total number of pre-allocated but unused bytes in the backing file.Iterator<T>
iterator()
T
peek()
Retrieve a task that is currently at the head of the queue.void
remove()
Remove a task from the head of the queue.int
size()
Returns a number of tasks currently in the queue.Long
weight()
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:TaskQueue
Retrieve a task that is currently at the head of the queue.- Specified by:
peek
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Returns:
- task object
-
add
public void add(@Nonnull T entry) throws IOException
Description copied from interface:TaskQueue
Add a task to the end of the queue- Specified by:
add
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Parameters:
entry
- task- Throws:
IOException
- IO exceptions caught by the storage engine
-
clear
public void clear() throws IOException
Description copied from interface:TaskQueue
Empty and re-initialize the queue.- Specified by:
clear
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Throws:
IOException
-
remove
public void remove() throws IOException
Description copied from interface:TaskQueue
Remove a task from the head of the queue. Requires peek() to be called first, otherwise anIllegalStateException
is thrown.- Specified by:
remove
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Throws:
IOException
- IO exceptions caught by the storage engine
-
size
public int size()
Description copied from interface:TaskQueue
Returns a number of tasks currently in the queue.- Specified by:
size
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Returns:
- number of tasks
-
close
public void close() throws IOException
Description copied from interface:TaskQueue
Close the queue. Should be invoked before a graceful shutdown.- Specified by:
close
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Throws:
IOException
-
weight
@Nullable public Long weight()
Description copied from interface:TaskQueue
Returns the total weight of the queue (sum of weights of all tasks).- Specified by:
weight
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Returns:
- weight of the queue (null if unknown)
-
getAvailableBytes
@Nullable public Long getAvailableBytes()
Description copied from interface:TaskQueue
Returns the total number of pre-allocated but unused bytes in the backing file. May return null if not applicable.- Specified by:
getAvailableBytes
in interfaceTaskQueue<T extends DataSubmissionTask<T>>
- Returns:
- total number of available bytes in the file or null
-
-