Package org.kairosdb.bigqueue
Interface IFanOutQueue
-
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
FanOutQueueImpl
public interface IFanOutQueue extends Closeable
FanOut queue ADT- Author:
- bulldog
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]dequeue(String fanoutId)Retrieves and removes the front of a fan out queuebyte[]dequeue(String fanoutId, boolean useLatest)Retrieves and removes the front of a fan out queuelongenqueue(byte[] data)Adds an item at the back of the queuelongfindClosestIndex(long timestamp)Find an index closest to the specific timestamp when the corresponding item was enqueued.voidflush()Force to persist current state of the queue, normally, you don't need to flush explicitly since: 1.)byte[]get(long index)Retrieves data item at the specific index of the queuelonggetBackFileSize()Current total size of the back files of this queuelonggetFrontIndex()Get the queue front index, this is the earliest appended indexlonggetFrontIndex(String fanoutId)Get front index of specific fanout queuelonggetFrontIndex(String fanoutId, boolean useLatest)Get front index of specific fanout queueintgetLength(long index)Get length of data item at specific index of the queuelonggetRearIndex()Get the queue rear index, this is the next to be appended indexlonggetTimestamp(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.booleanisEmpty()Determines whether the queue is emptybooleanisEmpty(String fanoutId)Determines whether a fan out queue is emptybooleanisEmpty(String fanoutId, boolean useLatest)Determines whether a fan out queue is emptyvoidlimitBackFileSize(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 queuebyte[]peek(String fanoutId, boolean useLatest)Peek the item at the front of a fanout queue, without removing it from the queueintpeekLength(String fanoutId)Peek the length of the item at the front of a fan out queueintpeekLength(String fanoutId, boolean useLatest)Peek the length of the item at the front of a fan out queuelongpeekTimestamp(String fanoutId)Peek the timestamp of the item at the front of a fan out queuelongpeekTimestamp(String fanoutId, boolean useLatest)Peek the timestamp of the item at the front of a fan out queuevoidremoveAll()Removes all items of a queue, this will empty the queue and delete all back data files.voidremoveBefore(long timestamp)Remove all data before specific timestamp, truncate back files and advance the queue front if necessary.voidresetQueueFrontIndex(String fanoutId, long index)Reset the front index of a fanout queue.longsize()Total number of items remaining in the queue.longsize(String fanoutId)Total number of items remaining in the fan out queuelongsize(String fanoutId, boolean useLatest)Total number of items remaining in the fan out queue
-
-
-
Field Detail
-
EARLIEST
static final long EARLIEST
Constant represents earliest timestamp- See Also:
- Constant Field Values
-
LATEST
static final long LATEST
Constant represents latest timestamp- See Also:
- Constant Field Values
-
-
Method Detail
-
isEmpty
boolean isEmpty(String fanoutId, boolean useLatest) throws IOException
Determines whether a fan out queue is empty- Parameters:
fanoutId- the fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- true if empty, false otherwise
- Throws:
IOException- exception thrown if IO error occurs
-
isEmpty
boolean isEmpty(String fanoutId) throws IOException
Determines whether a fan out queue is empty- Parameters:
fanoutId- the fanout identifier- Returns:
- true if empty, false otherwise
- Throws:
IOException- exception thrown if IO error occurs
-
isEmpty
boolean isEmpty()
Determines whether the queue is empty- Returns:
- true if empty, false otherwise
-
enqueue
long enqueue(byte[] data) throws IOExceptionAdds an item at the back of the queue- Parameters:
data- to be enqueued data- Returns:
- index where the item was appended
- Throws:
IOException- exception throws if there is any IO error during enqueue operation.
-
dequeue
byte[] dequeue(String fanoutId) throws IOException
Retrieves and removes the front of a fan out queue- Parameters:
fanoutId- the fanout identifier- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during dequeue operation.
-
dequeue
byte[] dequeue(String fanoutId, boolean useLatest) throws IOException
Retrieves and removes the front of a fan out queue- Parameters:
fanoutId- the fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during dequeue operation.
-
peek
byte[] peek(String fanoutId) throws IOException
Peek the item at the front of a fanout queue, without removing it from the queue- Parameters:
fanoutId- the fanout identifier- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during peek operation.
-
peek
byte[] peek(String fanoutId, boolean useLatest) throws IOException
Peek the item at the front of a fanout queue, without removing it from the queue- Parameters:
fanoutId- the fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during peek operation.
-
peekLength
int peekLength(String fanoutId) throws IOException
Peek the length of the item at the front of a fan out queue- Parameters:
fanoutId- the fanout identifier- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during peek operation.
-
peekLength
int peekLength(String fanoutId, boolean useLatest) throws IOException
Peek the length of the item at the front of a fan out queue- Parameters:
fanoutId- the fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during peek operation.
-
peekTimestamp
long peekTimestamp(String fanoutId) throws IOException
Peek the timestamp of the item at the front of a fan out queue- Parameters:
fanoutId- the fanout identifier- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during peek operation.
-
peekTimestamp
long peekTimestamp(String fanoutId, boolean useLatest) throws IOException
Peek the timestamp of the item at the front of a fan out queue- Parameters:
fanoutId- the fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- data at the front of a queue
- Throws:
IOException- exception throws if there is any IO error during peek operation.
-
get
byte[] get(long index) throws IOExceptionRetrieves data item at the specific index of the queue- Parameters:
index- data item index- Returns:
- data at index
- Throws:
IOException- exception throws if there is any IO error during fetch operation.
-
getLength
int getLength(long index) throws IOExceptionGet length of data item at specific index of the queue- Parameters:
index- data item index- Returns:
- length of data item
- Throws:
IOException- exception throws if there is any IO error during fetch operation.
-
getTimestamp
long getTimestamp(long index) throws IOExceptionGet timestamp of data item at specific index of the queue, this is the timestamp when corresponding item was appended into the queue.- Parameters:
index- data item index- Returns:
- timestamp of data item
- Throws:
IOException- exception throws if there is any IO error during fetch operation.
-
size
long size(String fanoutId) throws IOException
Total number of items remaining in the fan out queue- Parameters:
fanoutId- the fanout identifier- Returns:
- total number
- Throws:
IOException- exception thrown if IO error occurs
-
size
long size(String fanoutId, boolean useLatest) throws IOException
Total number of items remaining in the fan out queue- Parameters:
fanoutId- the fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- total number
- Throws:
IOException- exception thrown if IO error occurs
-
size
long size()
Total number of items remaining in the queue.- Returns:
- total number
-
flush
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.
-
removeBefore
void removeBefore(long timestamp) throws IOExceptionRemove all data before specific timestamp, truncate back files and advance the queue front if necessary.- Parameters:
timestamp- a timestamp- Throws:
IOException- exception thrown if there was any IO error during the removal operation
-
limitBackFileSize
void limitBackFileSize(long sizeLmit) throws IOExceptionLimit the back file size of this queue, truncate back files and advance the queue front if necessary. Note, this is a best effort call, exact size limit can't be guaranteed- Parameters:
sizeLmit- size limit- Throws:
IOException- exception thrown if there was any IO error during the operation
-
getBackFileSize
long getBackFileSize() throws IOExceptionCurrent total size of the back files of this queue- Returns:
- total back file size
- Throws:
IOException- exception thrown if there was any IO error during the operation
-
findClosestIndex
long findClosestIndex(long timestamp) throws IOExceptionFind an index closest to the specific timestamp when the corresponding item was enqueued. to find latest index, useLATESTas timestamp. to find earliest index, useEARLIESTas timestamp.- Parameters:
timestamp- when the corresponding item was appended- Returns:
- an index
- Throws:
IOException- exception thrown during the operation
-
resetQueueFrontIndex
void resetQueueFrontIndex(String fanoutId, long index) throws IOException
Reset the front index of a fanout queue.- Parameters:
fanoutId- fanout identifierindex- target index- Throws:
IOException- exception thrown during the operation
-
removeAll
void removeAll() throws IOExceptionRemoves all items of a queue, this will empty the queue and delete all back data files.- Throws:
IOException- exception throws if there is any IO error during dequeue operation.
-
getFrontIndex
long getFrontIndex()
Get the queue front index, this is the earliest appended index- Returns:
- an index
-
getFrontIndex
long getFrontIndex(String fanoutId) throws IOException
Get front index of specific fanout queue- Parameters:
fanoutId- fanout identifier- Returns:
- an index
- Throws:
IOException- exception thrown if IO error occurs
-
getFrontIndex
long getFrontIndex(String fanoutId, boolean useLatest) throws IOException
Get front index of specific fanout queue- Parameters:
fanoutId- fanout identifieruseLatest- if no offset has been recorded the head of the queue is used- Returns:
- an index
- Throws:
IOException- exception thrown if IO error occurs
-
getRearIndex
long getRearIndex()
Get the queue rear index, this is the next to be appended index- Returns:
- an index
-
-