Class PersistentQueue<T extends Serializable>
- java.lang.Object
-
- org.wso2.carbon.logging.appender.http.utils.queue.PersistentQueue<T>
-
- Type Parameters:
T
- type of the object to be stored in the queue.
- All Implemented Interfaces:
AutoCloseable
public class PersistentQueue<T extends Serializable> extends Object implements AutoCloseable
This class implements a file based queue which can be used to store objects in serialized form in a persistent manner and consumed later.
-
-
Constructor Summary
Constructors Constructor Description PersistentQueue(String queueDirectoryPath, long maxDiskSpaceInBytes, long maxBatchSizeInBytes)
Constructor of the PersistentQueue class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
calculateDiskUsage()
Loops through each file in the queue directory and calculates the disk usage of the queue.void
close()
Closes the queue.T
dequeue()
Dequeues the next object from the queue.void
enqueue(T object)
Enqueues the given object to the queue.float
getUsedSpaceFraction()
Returns the fraction of the disk space used by the queue.boolean
isEmpty()
Checks if the queue is empty.boolean
isFull()
Checks if the queue is full.T
peek()
Peeks the next object from the queue without removing it.
-
-
-
Constructor Detail
-
PersistentQueue
public PersistentQueue(String queueDirectoryPath, long maxDiskSpaceInBytes, long maxBatchSizeInBytes) throws PersistentQueueException
Constructor of the PersistentQueue class.- Parameters:
queueDirectoryPath
- path of the queue directory.maxDiskSpaceInBytes
- maximum disk space that can be used by the queue.maxBatchSizeInBytes
- maximum size of a single queue block.- Throws:
PersistentQueueException
- if an error occurs while creating the queue.
-
-
Method Detail
-
enqueue
public void enqueue(T object) throws PersistentQueueException
Enqueues the given object to the queue.- Parameters:
object
- object to be enqueued.- Throws:
PersistentQueueException
- if an error occurs while enqueuing the object.
-
dequeue
public T dequeue() throws PersistentQueueException
Dequeues the next object from the queue.- Returns:
- dequeued object.
- Throws:
PersistentQueueException
- if an error occurs while dequeue the object.
-
peek
public T peek() throws PersistentQueueException
Peeks the next object from the queue without removing it.- Returns:
- peeked object.
- Throws:
PersistentQueueException
- if an error occurs while peeking the object.
-
isEmpty
public boolean isEmpty()
Checks if the queue is empty.- Returns:
- boolean if the queue is empty.
-
isFull
public boolean isFull()
Checks if the queue is full.- Returns:
- boolean if the queue is full.
-
calculateDiskUsage
public long calculateDiskUsage() throws PersistentQueueException
Loops through each file in the queue directory and calculates the disk usage of the queue.- Returns:
- disk usage of the queue.
- Throws:
PersistentQueueException
- if an error occurs while calculating the disk usage.
-
getUsedSpaceFraction
public float getUsedSpaceFraction()
Returns the fraction of the disk space used by the queue.- Returns:
- fraction of the disk space used by the queue.
-
close
public void close() throws PersistentQueueException
Closes the queue.- Specified by:
close
in interfaceAutoCloseable
- Throws:
PersistentQueueException
- if an error occurs while closing the queue.
-
-