public class FanOutQueueImpl extends Object implements IFanOutQueue
EARLIEST, LATEST| Constructor and Description |
|---|
FanOutQueueImpl(String queueDir,
String queueName)
A big, fast and persistent queue implementation with fanout support,
use default back data page size, see
BigArrayImpl.DEFAULT_DATA_PAGE_SIZE |
FanOutQueueImpl(String queueDir,
String queueName,
int pageSize)
A big, fast and persistent queue implementation with fandout support.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
byte[] |
dequeue(String fanoutId)
Retrieves and removes the front of a fan out queue
|
byte[] |
dequeue(String fanoutId,
boolean useLatest)
Retrieves and removes the front of a fan out queue
|
long |
enqueue(byte[] data)
Adds an item at the back of the queue
|
long |
findClosestIndex(long timestamp)
Find an index closest to the specific timestamp when the corresponding item was enqueued.
|
void |
flush()
Force to persist current state of the queue,
normally, you don't need to flush explicitly since:
1.) FanOutQueue will automatically flush a cached page when it is replaced out,
2.) FanOutQueue uses memory mapped file technology internally, and the OS will flush the changes even your process crashes,
call this periodically only if you need transactional reliability and you are aware of the cost to performance.
|
byte[] |
get(long index)
Retrieves data item at the specific index of the queue
|
long |
getBackFileSize()
Current total size of the back files of this queue
|
long |
getFrontIndex()
Get the queue front index, this is the earliest appended index
|
long |
getFrontIndex(String fanoutId)
Get front index of specific fanout queue
|
long |
getFrontIndex(String fanoutId,
boolean useLatest)
Get front index of specific fanout queue
|
int |
getLength(long index)
Get length of data item at specific index of the queue
|
long |
getRearIndex()
Get the queue rear index, this is the next to be appended index
|
long |
getTimestamp(long index)
Get timestamp of data item at specific index of the queue, this is the timestamp when corresponding item was appended into the queue.
|
boolean |
isEmpty()
Determines whether the queue is empty
|
boolean |
isEmpty(String fanoutId)
Determines whether a fan out queue is empty
|
boolean |
isEmpty(String fanoutId,
boolean useLatest)
Determines whether a fan out queue is empty
|
void |
limitBackFileSize(long sizeLimit)
Limit the back file size of this queue, truncate back files and advance the queue front if necessary.
|
byte[] |
peek(String fanoutId)
Peek the item at the front of a fanout queue, without removing it from the queue
|
byte[] |
peek(String fanoutId,
boolean useLatest)
Peek the item at the front of a fanout queue, without removing it from the queue
|
int |
peekLength(String fanoutId)
Peek the length of the item at the front of a fan out queue
|
int |
peekLength(String fanoutId,
boolean useLatest)
Peek the length of the item at the front of a fan out queue
|
long |
peekTimestamp(String fanoutId)
Peek the timestamp of the item at the front of a fan out queue
|
long |
peekTimestamp(String fanoutId,
boolean useLatest)
Peek the timestamp of the item at the front of a fan out queue
|
void |
removeAll()
Removes all items of a queue, this will empty the queue and delete all back data files.
|
void |
removeBefore(long timestamp)
Remove all data before specific timestamp, truncate back files and advance the queue front if necessary.
|
void |
resetQueueFrontIndex(String fanoutId,
long index)
Reset the front index of a fanout queue.
|
long |
size()
Total number of items remaining in the queue.
|
long |
size(String fanoutId)
Total number of items remaining in the fan out queue
|
long |
size(String fanoutId,
boolean useLatest)
Total number of items remaining in the fan out queue
|
public FanOutQueueImpl(String queueDir, String queueName, int pageSize) throws IOException
queueDir - the directory to store queue dataqueueName - the name of the queue, will be appended as last part of the queue directorypageSize - the back data file size per page in bytes, see minimum allowed BigArrayImpl.MINIMUM_DATA_PAGE_SIZEIOException - exception throws if there is any IO error during queue initializationpublic FanOutQueueImpl(String queueDir, String queueName) throws IOException
BigArrayImpl.DEFAULT_DATA_PAGE_SIZEqueueDir - the directory to store queue dataqueueName - the name of the queue, will be appended as last part of the queue directoryIOException - exception throws if there is any IO error during queue initializationpublic boolean isEmpty(String fanoutId, boolean useLatest) throws IOException
IFanOutQueueisEmpty in interface IFanOutQueuefanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception thrown if IO error occurspublic boolean isEmpty(String fanoutId) throws IOException
IFanOutQueueisEmpty in interface IFanOutQueuefanoutId - the fanout identifierIOException - exception thrown if IO error occurspublic boolean isEmpty()
IFanOutQueueisEmpty in interface IFanOutQueuepublic long enqueue(byte[] data)
throws IOException
IFanOutQueueenqueue in interface IFanOutQueuedata - to be enqueued dataIOException - exception throws if there is any IO error during enqueue operation.public byte[] dequeue(String fanoutId) throws IOException
IFanOutQueuedequeue in interface IFanOutQueuefanoutId - the fanout identifierIOException - exception throws if there is any IO error during dequeue operation.public byte[] dequeue(String fanoutId, boolean useLatest) throws IOException
IFanOutQueuedequeue in interface IFanOutQueuefanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception throws if there is any IO error during dequeue operation.public byte[] peek(String fanoutId) throws IOException
IFanOutQueuepeek in interface IFanOutQueuefanoutId - the fanout identifierIOException - exception throws if there is any IO error during peek operation.public byte[] peek(String fanoutId, boolean useLatest) throws IOException
IFanOutQueuepeek in interface IFanOutQueuefanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception throws if there is any IO error during peek operation.public int peekLength(String fanoutId) throws IOException
IFanOutQueuepeekLength in interface IFanOutQueuefanoutId - the fanout identifierIOException - exception throws if there is any IO error during peek operation.public int peekLength(String fanoutId, boolean useLatest) throws IOException
IFanOutQueuepeekLength in interface IFanOutQueuefanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception throws if there is any IO error during peek operation.public long peekTimestamp(String fanoutId) throws IOException
IFanOutQueuepeekTimestamp in interface IFanOutQueuefanoutId - the fanout identifierIOException - exception throws if there is any IO error during peek operation.public long peekTimestamp(String fanoutId, boolean useLatest) throws IOException
IFanOutQueuepeekTimestamp in interface IFanOutQueuefanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception throws if there is any IO error during peek operation.public byte[] get(long index)
throws IOException
IFanOutQueueget in interface IFanOutQueueindex - data item indexIOException - exception throws if there is any IO error during fetch operation.public int getLength(long index)
throws IOException
IFanOutQueuegetLength in interface IFanOutQueueindex - data item indexIOException - exception throws if there is any IO error during fetch operation.public long getTimestamp(long index)
throws IOException
IFanOutQueuegetTimestamp in interface IFanOutQueueindex - data item indexIOException - exception throws if there is any IO error during fetch operation.public long size(String fanoutId) throws IOException
IFanOutQueuesize in interface IFanOutQueuefanoutId - the fanout identifierIOException - exception thrown if IO error occurspublic void removeBefore(long timestamp)
throws IOException
IFanOutQueueremoveBefore in interface IFanOutQueuetimestamp - a timestampIOException - exception thrown if there was any IO error during the removal operationpublic void limitBackFileSize(long sizeLimit)
throws IOException
IFanOutQueuelimitBackFileSize in interface IFanOutQueuesizeLimit - size limitIOException - exception thrown if there was any IO error during the operationpublic long getBackFileSize()
throws IOException
IFanOutQueuegetBackFileSize in interface IFanOutQueueIOException - exception thrown if there was any IO error during the operationpublic long findClosestIndex(long timestamp)
throws IOException
IFanOutQueueIFanOutQueue.LATEST as timestamp.
to find earliest index, use IFanOutQueue.EARLIEST as timestamp.findClosestIndex in interface IFanOutQueuetimestamp - when the corresponding item was appendedIOException - exception thrown during the operationpublic void resetQueueFrontIndex(String fanoutId, long index) throws IOException
IFanOutQueueresetQueueFrontIndex in interface IFanOutQueuefanoutId - fanout identifierindex - target indexIOException - exception thrown during the operationpublic long size(String fanoutId, boolean useLatest) throws IOException
IFanOutQueuesize in interface IFanOutQueuefanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception thrown if IO error occurspublic long size()
IFanOutQueuesize in interface IFanOutQueuepublic void flush()
IFanOutQueueflush in interface IFanOutQueuepublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void removeAll()
throws IOException
IFanOutQueueremoveAll in interface IFanOutQueueIOException - exception throws if there is any IO error during dequeue operation.public long getFrontIndex()
IFanOutQueuegetFrontIndex in interface IFanOutQueuepublic long getFrontIndex(String fanoutId) throws IOException
IFanOutQueuegetFrontIndex in interface IFanOutQueuefanoutId - fanout identifierIOException - exception thrown if IO error occurspublic long getRearIndex()
IFanOutQueuegetRearIndex in interface IFanOutQueuepublic long getFrontIndex(String fanoutId, boolean useLatest) throws IOException
IFanOutQueuegetFrontIndex in interface IFanOutQueuefanoutId - fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception thrown if IO error occursCopyright © 2022. All rights reserved.