Package com.wavefront.agent.queueing
Class ConcurrentShardedQueueFile
- java.lang.Object
-
- com.wavefront.agent.queueing.ConcurrentShardedQueueFile
-
- All Implemented Interfaces:
QueueFile,Closeable,AutoCloseable,Iterable<byte[]>
public class ConcurrentShardedQueueFile extends Object implements QueueFile
A thread-safeQueueFileimplementation, that uses multiple smaller "shard" files instead of one large file. This also improves concurrency - when we have more than one file, we can add and remove tasks at the same time without mutually exclusive locking.- Author:
- [email protected]
-
-
Constructor Summary
Constructors Constructor Description ConcurrentShardedQueueFile(String fileNamePrefix, String fileNameSuffix, int shardSizeBytes, QueueFileFactory queueFileFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(byte[] data, int offset, int count)Adds an element to the end of the queue.longavailableBytes()Returns the number of bytes available for adding new tasks without growing the file.voidclear()Clears this queue.voidclose()Iterator<byte[]>iterator()byte[]peek()Reads the eldest element.voidremove()Removes the eldest element.intsize()Returns the number of elements in this queue.longstorageBytes()Returns the storage size (on-disk file size) in bytes.longusedBytes()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
-
ConcurrentShardedQueueFile
public ConcurrentShardedQueueFile(String fileNamePrefix, String fileNameSuffix, int shardSizeBytes, QueueFileFactory queueFileFactory) throws IOException
- Parameters:
fileNamePrefix- path + file name prefix for shard filesfileNameSuffix- file name suffix to identify shard filesshardSizeBytes- target shard size bytesqueueFileFactory- factory forQueueFileobjects- Throws:
IOException- if file(s) could not be created or accessed
-
-
Method Detail
-
peek
@Nullable public byte[] peek() throws IOException
Description copied from interface:QueueFileReads the eldest element. Returns null if the queue is empty.- Specified by:
peekin interfaceQueueFile- Returns:
- the eldest element.
- Throws:
IOException
-
add
public void add(byte[] data, int offset, int count) throws IOExceptionDescription copied from interface:QueueFileAdds an element to the end of the queue.- Specified by:
addin interfaceQueueFile- Parameters:
data- to copy bytes fromoffset- to start from in buffercount- number of bytes to copy- Throws:
IOException
-
remove
public void remove() throws IOExceptionDescription copied from interface:QueueFileRemoves the eldest element.- Specified by:
removein interfaceQueueFile- Throws:
IOException
-
size
public int size()
Description copied from interface:QueueFileReturns the number of elements in this queue.
-
storageBytes
public long storageBytes()
Description copied from interface:QueueFileReturns the storage size (on-disk file size) in bytes.- Specified by:
storageBytesin interfaceQueueFile- Returns:
- file size in bytes.
-
usedBytes
public long usedBytes()
Description copied from interface:QueueFileReturns the number of bytes used for data.
-
availableBytes
public long availableBytes()
Description copied from interface:QueueFileReturns the number of bytes available for adding new tasks without growing the file.- Specified by:
availableBytesin interfaceQueueFile- Returns:
- bytes available.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
clear
public void clear() throws IOExceptionDescription copied from interface:QueueFileClears this queue. Truncates the file to the initial size.- Specified by:
clearin interfaceQueueFile- Throws:
IOException
-
-