Package com.wavefront.agent.queueing
Class TapeQueueFile
- java.lang.Object
-
- com.wavefront.agent.queueing.TapeQueueFile
-
- All Implemented Interfaces:
QueueFile
,Closeable
,AutoCloseable
,Iterable<byte[]>
public class TapeQueueFile extends Object implements QueueFile
AQueueFile
toQueueFile
adapter.- Author:
- [email protected]
-
-
Constructor Summary
Constructors Constructor Description TapeQueueFile(com.squareup.tape2.QueueFile delegate)
TapeQueueFile(com.squareup.tape2.QueueFile delegate, BiConsumer<Integer,Long> writeStatsConsumer)
TapeQueueFile(com.squareup.tape2.QueueFile delegate, BiConsumer<Integer,Long> writeStatsConsumer, com.wavefront.common.TimeProvider clock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(byte[] data, int offset, int count)
Adds an element to the end of the queue.long
availableBytes()
Returns the number of bytes available for adding new tasks without growing the file.void
clear()
Clears this queue.void
close()
boolean
isEmpty()
Checks whether this queue is empty.Iterator<byte[]>
iterator()
byte[]
peek()
Reads the eldest element.void
remove()
Removes the eldest element.int
size()
Returns the number of elements in this queue.long
storageBytes()
Returns the storage size (on-disk file size) in bytes.long
usedBytes()
Returns the number of bytes used for data.-
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
-
TapeQueueFile
public TapeQueueFile(com.squareup.tape2.QueueFile delegate)
- Parameters:
delegate
- tape queue file
-
TapeQueueFile
public TapeQueueFile(com.squareup.tape2.QueueFile delegate, @Nullable BiConsumer<Integer,Long> writeStatsConsumer)
- Parameters:
delegate
- tape queue filewriteStatsConsumer
- consumer for statistics on writes (bytes written and millis taken)
-
TapeQueueFile
public TapeQueueFile(com.squareup.tape2.QueueFile delegate, @Nullable BiConsumer<Integer,Long> writeStatsConsumer, @Nullable com.wavefront.common.TimeProvider clock)
- Parameters:
delegate
- tape queue filewriteStatsConsumer
- consumer for statistics on writes (bytes written and millis taken)clock
- time provider (in millis)
-
-
Method Detail
-
add
public void add(byte[] data, int offset, int count) throws IOException
Description copied from interface:QueueFile
Adds an element to the end of the queue.- Specified by:
add
in interfaceQueueFile
- Parameters:
data
- to copy bytes fromoffset
- to start from in buffercount
- number of bytes to copy- Throws:
IOException
-
isEmpty
public boolean isEmpty()
Description copied from interface:QueueFile
Checks whether this queue is empty.
-
peek
@Nullable public byte[] peek() throws IOException
Description copied from interface:QueueFile
Reads the eldest element. Returns null if the queue is empty.- Specified by:
peek
in interfaceQueueFile
- Returns:
- the eldest element.
- Throws:
IOException
-
size
public int size()
Description copied from interface:QueueFile
Returns the number of elements in this queue.
-
storageBytes
public long storageBytes()
Description copied from interface:QueueFile
Returns the storage size (on-disk file size) in bytes.- Specified by:
storageBytes
in interfaceQueueFile
- Returns:
- file size in bytes.
-
usedBytes
public long usedBytes()
Description copied from interface:QueueFile
Returns the number of bytes used for data.
-
availableBytes
public long availableBytes()
Description copied from interface:QueueFile
Returns the number of bytes available for adding new tasks without growing the file.- Specified by:
availableBytes
in interfaceQueueFile
- Returns:
- bytes available.
-
remove
public void remove() throws IOException
Description copied from interface:QueueFile
Removes the eldest element.- Specified by:
remove
in interfaceQueueFile
- Throws:
IOException
-
clear
public void clear() throws IOException
Description copied from interface:QueueFile
Clears this queue. Truncates the file to the initial size.- Specified by:
clear
in interfaceQueueFile
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-