public interface IFanOutQueue extends Closeable
| Modifier and Type | Field and Description |
|---|---|
static long |
EARLIEST
Constant represents earliest timestamp
|
static long |
LATEST
Constant represents latest timestamp
|
| Modifier and Type | Method and Description |
|---|---|
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 sizeLmit)
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
|
static final long EARLIEST
static final long LATEST
boolean isEmpty(String fanoutId, boolean useLatest) throws IOException
fanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception thrown if IO error occursboolean isEmpty(String fanoutId) throws IOException
fanoutId - the fanout identifierIOException - exception thrown if IO error occursboolean isEmpty()
long enqueue(byte[] data)
throws IOException
data - to be enqueued dataIOException - exception throws if there is any IO error during enqueue operation.byte[] dequeue(String fanoutId) throws IOException
fanoutId - the fanout identifierIOException - exception throws if there is any IO error during dequeue operation.byte[] dequeue(String fanoutId, boolean useLatest) throws IOException
fanoutId - 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.byte[] peek(String fanoutId) throws IOException
fanoutId - the fanout identifierIOException - exception throws if there is any IO error during peek operation.byte[] peek(String fanoutId, boolean useLatest) throws IOException
fanoutId - 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.int peekLength(String fanoutId) throws IOException
fanoutId - the fanout identifierIOException - exception throws if there is any IO error during peek operation.int peekLength(String fanoutId, boolean useLatest) throws IOException
fanoutId - 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.long peekTimestamp(String fanoutId) throws IOException
fanoutId - the fanout identifierIOException - exception throws if there is any IO error during peek operation.long peekTimestamp(String fanoutId, boolean useLatest) throws IOException
fanoutId - 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.byte[] get(long index)
throws IOException
index - data item indexIOException - exception throws if there is any IO error during fetch operation.int getLength(long index)
throws IOException
index - data item indexIOException - exception throws if there is any IO error during fetch operation.long getTimestamp(long index)
throws IOException
index - data item indexIOException - exception throws if there is any IO error during fetch operation.long size(String fanoutId) throws IOException
fanoutId - the fanout identifierIOException - exception thrown if IO error occurslong size(String fanoutId, boolean useLatest) throws IOException
fanoutId - the fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception thrown if IO error occurslong size()
void flush()
void removeBefore(long timestamp)
throws IOException
timestamp - a timestampIOException - exception thrown if there was any IO error during the removal operationvoid limitBackFileSize(long sizeLmit)
throws IOException
sizeLmit - size limitIOException - exception thrown if there was any IO error during the operationlong getBackFileSize()
throws IOException
IOException - exception thrown if there was any IO error during the operationlong findClosestIndex(long timestamp)
throws IOException
LATEST as timestamp.
to find earliest index, use EARLIEST as timestamp.timestamp - when the corresponding item was appendedIOException - exception thrown during the operationvoid resetQueueFrontIndex(String fanoutId, long index) throws IOException
fanoutId - fanout identifierindex - target indexIOException - exception thrown during the operationvoid removeAll()
throws IOException
IOException - exception throws if there is any IO error during dequeue operation.long getFrontIndex()
long getFrontIndex(String fanoutId) throws IOException
fanoutId - fanout identifierIOException - exception thrown if IO error occurslong getFrontIndex(String fanoutId, boolean useLatest) throws IOException
fanoutId - fanout identifieruseLatest - if no offset has been recorded the head of the queue is usedIOException - exception thrown if IO error occurslong getRearIndex()
Copyright © 2020. All rights reserved.