Interface PerNodeLocalQueue
-
- All Known Implementing Classes:
TapePerNodeLocalQueue,TapePerNodeLocalQueueWithStats
public interface PerNodeLocalQueueAbstracts persistent queue implementation A queue represents a FIFO queue ofCrossNodesEventfor a specific nodeBambooNodeInfo. Each node may have from 1 to n queues. Each queue has a single processing (reading) process soBambooClusterSettings.NUMBER_OF_PHYSICAL_QUEUES_UNDER_PER_NODE_QUEUEi.e. the number of processes for each node.BambooClusterSettings.NUMBER_OF_PHYSICAL_QUEUES_UNDER_PER_NODE_QUEUEis the concurrency factor for communicating with a single remote node. Example: if we have a cluster with 3 nodes (node1, node2, node3) on each node there will beBambooClusterSettings.NUMBER_OF_PHYSICAL_QUEUES_UNDER_PER_NODE_QUEUEqueues for each of the "other" 2 remote nodes.- Since:
- 9.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classPerNodeLocalQueue.QueueIdUniquely identifies a queue
-
Field Summary
Fields Modifier and Type Field Description static intNUMBER_OF_PHYSICAL_QUEUES_PER_NODE
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanadd(CrossNodesEvent data)transactional add ofCrossNodesEventto the queue; when operation finished we "guarantee" that theCrossNodesEventis persistedvoidbackupQueue(String prefix)Note: use with caution This method is mainly designed to handle critical state of the queue storage by backing up the current queue persistent store and recreating a new one.voidclose()closes the queue and all resources connected with this queue (like processing thread(s), files); closing a queue is definitive - it will never be open (i.e.@NotNull Optional<Path>getQueueFilePath()booleanhasPermission()@NotNull PerNodeLocalQueue.QueueIdid()booleanisClosed()Some operations (likeadd(CrossNodesEvent)) on a closed queue will throw aIllegalStateException.@NotNull Stringname()static intnodeQueueNumber(long threadId)Utility method to get the nodeQueueNumber for given thread id.static intnodeQueueNumberForCurrentThread()Utility method to get the nodeQueueNumber for current thread.CrossNodesEventpeek()Allows to see what's on the head of the queue without removing it.voidremove()RemoveCrossNodesEventfrom head of the queue.intsize()LongusableSpaceInBytes()
-
-
-
Method Detail
-
close
void close()
closes the queue and all resources connected with this queue (like processing thread(s), files); closing a queue is definitive - it will never be open (i.e. not-closed) again;
-
isClosed
boolean isClosed()
Some operations (likeadd(CrossNodesEvent)) on a closed queue will throw aIllegalStateException. This method allows to check if the queue has not been closed.- Returns:
- true if queue is closed
-
name
@NotNull @NotNull String name()
- Returns:
- name of the queue could be useful for the user, like identifying the queue file path from logs
-
id
@NotNull @NotNull PerNodeLocalQueue.QueueId id()
- Returns:
- queue id which uniquely identifies this queue, i.e destination node and nodeQueueNumber, see
PerNodeLocalQueue.QueueId
-
add
boolean add(CrossNodesEvent data) throws IllegalStateException
transactional add ofCrossNodesEventto the queue; when operation finished we "guarantee" that theCrossNodesEventis persisted- Parameters:
data-- Returns:
- true if message was added or false if dropped (like exceeding queue size limit)
- Throws:
IllegalStateException- when queue is closed
-
peek
@Nullable CrossNodesEvent peek() throws IllegalStateException
Allows to see what's on the head of the queue without removing it.- Returns:
- crossNodesEvent from queue head or null when queue is empty.
- Throws:
IllegalStateException- when queue is closed
-
remove
void remove() throws NoSuchElementException, IllegalStateExceptionRemoveCrossNodesEventfrom head of the queue.- Throws:
NoSuchElementException- when doing a remove on an empty queueIllegalStateException- when queue is closed
-
getQueueFilePath
@NotNull @NotNull Optional<Path> getQueueFilePath()
- Returns:
- the queue file path if exists, empty otherwise
-
hasPermission
boolean hasPermission()
- Returns:
- true if it has read/write access to queue storage
-
usableSpaceInBytes
@Nullable Long usableSpaceInBytes()
- Returns:
- number of bytes left on device where this queue is stored or null if unable to get this value
-
size
int size()
- Returns:
- number of elements in this queue
-
backupQueue
void backupQueue(String prefix) throws IOException
Note: use with caution This method is mainly designed to handle critical state of the queue storage by backing up the current queue persistent store and recreating a new one. Renames current queue file name to [prefix]_[queue_file_name] and re-creates queue file with [queue_file_name]. If file with [prefix]_[queue_file_name] already exists it will be deleted. Note that ifbackupQueue(String)is called betweenpeek()andremove()this can causeremove()to delete a differentCrossNodesEventthen expected or may throwNoSuchElementExceptionif the new queue afterbackupQueue(String)is empty.- Throws:
IOException
-
nodeQueueNumberForCurrentThread
static int nodeQueueNumberForCurrentThread()
Utility method to get the nodeQueueNumber for current thread.- Returns:
- nodeQueueNumber for current thread
-
nodeQueueNumber
static int nodeQueueNumber(long threadId)
Utility method to get the nodeQueueNumber for given thread id.- Returns:
- nodeQueueNumber for given thread id
-
-