Size64
, java.io.Closeable
, java.lang.AutoCloseable
public class ObjectDiskQueue<T> extends java.lang.Object implements java.io.Closeable, Size64
This class is a wrapper around a ByteDiskQueue
that provides methods to
enqueue and dequeue() objects. Like a
ByteDiskQueue
, and instance of this class has a suspend()
method that releases
the file handle without deleting the dump file. The file handle is reinitialized lazily (which
implies that a certain number of enqueue(Object)
/dequeue()
calls can be performed on a suspended
class without actually reopening the dump file).
Similarly to a ByteDiskQueue
, you can freeze()
and then
reopen a ObjectDiskQueue
.
ByteDiskQueue
Modifier | Constructor | Description |
---|---|---|
protected |
ObjectDiskQueue(ByteDiskQueue byteDiskQueue) |
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
Clears this queue.
|
void |
close() |
Closes this queue.
|
static <T> ObjectDiskQueue<T> |
createFromFile(long size,
java.io.File file,
int bufferSize,
boolean direct) |
Creates a new disk-based queue of objects using an existing file.
|
static <T> ObjectDiskQueue<T> |
createNew(java.io.File file,
int bufferSize,
boolean direct) |
Creates a new disk-based queue of objects.
|
T |
dequeue() |
Dequeues an object from the queue in FIFO fashion.
|
void |
enlargeBuffer(int newBufferSize) |
Enlarge the buffer of this queue to a given size.
|
void |
enqueue(T o) |
Enqueues an object to this queue.
|
void |
freeze() |
Freezes this queue.
|
boolean |
isEmpty() |
|
int |
size() |
Deprecated.
|
long |
size64() |
|
void |
suspend() |
Suspends this queue.
|
void |
trim() |
Trims this queue.
|
protected ObjectDiskQueue(ByteDiskQueue byteDiskQueue)
public static <T> ObjectDiskQueue<T> createNew(java.io.File file, int bufferSize, boolean direct) throws java.io.IOException
file
- the file that will be used to dump the queue on disk.bufferSize
- the number of items in the circular buffer (will be possibly decreased so to be a power of two).direct
- whether the ByteBuffer
used by this queue should be allocated directly.java.io.IOException
ByteDiskQueue.createNew(File, int, boolean)
public static <T> ObjectDiskQueue<T> createFromFile(long size, java.io.File file, int bufferSize, boolean direct) throws java.io.IOException
Note that you have to supply the correct number of objects contained in the dump file of
the underlying ByteDiskQueue
. Failure to do so will cause unpredictable behaviour.
size
- the number of objects contained in file
.file
- the file that will be used to dump the queue on disk.bufferSize
- the number of items in the circular buffer (will be possibly decreased so to be a power of two).direct
- whether the ByteBuffer
used by this queue should be allocated directly.java.io.IOException
ByteDiskQueue.createFromFile(File, int, boolean)
public void enqueue(T o) throws java.io.IOException
o
- the object to be enqueued.java.io.IOException
public T dequeue() throws java.io.IOException
java.io.IOException
public boolean isEmpty()
public void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
ByteDiskQueue.close()
public void freeze() throws java.io.IOException
java.io.IOException
ByteDiskQueue.freeze()
public void clear()
ByteDiskQueue.clear()
public void trim() throws java.io.IOException
java.io.IOException
ByteDiskQueue.trim()
public void suspend() throws java.io.IOException
java.io.IOException
ByteDiskQueue.suspend()
public void enlargeBuffer(int newBufferSize)
newBufferSize
- the required buffer size.ByteDiskQueue.enlargeBuffer(int)