Class QueueBlock
java.lang.Object
org.wso2.carbon.logging.appender.http.utils.queue.QueueBlock
This class represents a block of the queue. Each block is a file in the disk.
-
Constructor Summary
ConstructorsConstructorDescriptionQueueBlock(String queueDirectoryPath, String fileName, long length) This constructor is to be used when creating a new block. -
Method Summary
Modifier and TypeMethodDescriptionbooleanappend(byte[] data) Appends the given data to the block.booleancanAppend(int length) Returns if the block can append the given length of data.voidclose()Closes the block.byte[]consume()Consumes the next item in the block.voiddelete()Deletes the block.Returns the name of the file relevant to the block.booleanReturns if the block has unprocessed items.static voidThis method is to be used when initializing the class.static QueueBlockThis method is to be used when loading the next queue block to memory.byte[]Peeks the next item in the block without consuming.voidResets the block.
-
Constructor Details
-
QueueBlock
public QueueBlock(String queueDirectoryPath, String fileName, long length) throws PersistentQueueException This constructor is to be used when creating a new block.- Parameters:
queueDirectoryPath- path of the queue directoryfileName- name of the filelength- length of the file- Throws:
PersistentQueueException- if an error occurs while creating the block.
-
-
Method Details
-
initClass
This method is to be used when initializing the class.- Parameters:
queueDirectoryPath- path of the queue directory
-
loadBlock
public static QueueBlock loadBlock(String directoryPath, String fileName) throws PersistentQueueException This method is to be used when loading the next queue block to memory.- Parameters:
directoryPath- path of the queue directoryfileName- name of the file- Returns:
- QueueBlock next queue block
- Throws:
PersistentQueueException- if an error occurs while creating the block.
-
canAppend
public boolean canAppend(int length) Returns if the block can append the given length of data.- Parameters:
length- length of the data- Returns:
- boolean if the block can append the given length of data.
-
hasUnprocessedItems
public boolean hasUnprocessedItems()Returns if the block has unprocessed items.- Returns:
- boolean if the block has unprocessed items.
-
append
public boolean append(byte[] data) Appends the given data to the block.- Parameters:
data- byte stream to be appended- Returns:
- boolean if the append operation was successful.
-
consume
public byte[] consume()Consumes the next item in the block.- Returns:
- byte stream of the next item
-
peekNextItem
public byte[] peekNextItem()Peeks the next item in the block without consuming.- Returns:
- byte stream of the next item
-
delete
Deletes the block.- Throws:
PersistentQueueException- if an error occurs while deleting the block.
-
getFileName
Returns the name of the file relevant to the block.- Returns:
- name of the block
-
close
Closes the block.- Throws:
PersistentQueueException- if an error occurs while closing the block.
-
setValuesToDefault
public void setValuesToDefault()Resets the block.
-