public class BigQueueImpl extends Object implements IBigQueue
IBigQueue.ItemIterator| Constructor and Description |
|---|
BigQueueImpl(String queueDir,
String queueName)
A big, fast and persistent queue implementation,
use default back data page size, see
BigArrayImpl.DEFAULT_DATA_PAGE_SIZE |
BigQueueImpl(String queueDir,
String queueName,
int pageSize)
A big, fast and persistent queue implementation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
applyForEach(IBigQueue.ItemIterator iterator)
apply an implementation of a ItemIterator interface for each queue item
|
void |
close() |
byte[] |
dequeue()
Retrieves and removes the front of a queue
|
CompletableFuture<byte[]> |
dequeueAsync()
Retrieves a Future which will complete if new Items where enqued.
|
void |
enqueue(byte[] data)
Adds an item at the back of a queue
|
void |
flush()
Force to persist current state of the queue,
normally, you don't need to flush explicitly since:
1.) BigQueue will automatically flush a cached page when it is replaced out,
2.) BigQueue 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.
|
void |
gc()
Delete all used data files to free disk space.
|
boolean |
isEmpty()
Determines whether a queue is empty
|
byte[] |
peek()
Retrieves the item at the front of a queue
|
CompletableFuture<byte[]> |
peekAsync()
Retrieves the item at the front of a queue asynchronously.
|
void |
removeAll()
Removes all items of a queue, this will empty the queue and delete all back data files.
|
long |
size()
Total number of items available in the queue.
|
public BigQueueImpl(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 BigQueueImpl(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 boolean isEmpty()
IBigQueuepublic void enqueue(byte[] data)
throws IOException
IBigQueueenqueue in interface IBigQueuedata - to be enqueued dataIOException - exception throws if there is any IO error during enqueue operation.public byte[] dequeue()
throws IOException
IBigQueuedequeue in interface IBigQueueIOException - exception throws if there is any IO error during dequeue operation.public CompletableFuture<byte[]> dequeueAsync()
IBigQueuedequeueAsync in interface IBigQueuepublic void removeAll()
throws IOException
IBigQueueremoveAll in interface IBigQueueIOException - exception throws if there is any IO error during dequeue operation.public byte[] peek()
throws IOException
IBigQueuepeek in interface IBigQueueIOException - exception throws if there is any IO error during peek operation.public CompletableFuture<byte[]> peekAsync()
IBigQueuepublic void applyForEach(IBigQueue.ItemIterator iterator) throws IOException
applyForEach in interface IBigQueueiterator - Callback used for each item in array.IOException - exception thrown if IO error occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void gc()
throws IOException
IBigQueuegc in interface IBigQueueIOException - exception throws if there is any IO error during gc operation.public void flush()
IBigQueueCopyright © 2022. All rights reserved.