Interface PerNodeLocalQueue
-
- All Known Implementing Classes:
TapePerNodeLocalQueue
,TapePerNodeLocalQueueWithStats
public interface PerNodeLocalQueue
Abstracts persistent queue implementation A queue represents a FIFO queue ofCrossNodesEvent
for 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_QUEUE
i.e. the number of processes for each node.BambooClusterSettings.NUMBER_OF_PHYSICAL_QUEUES_UNDER_PER_NODE_QUEUE
is 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_QUEUE
queues for each of the "other" 2 remote nodes.- Since:
- 9.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
PerNodeLocalQueue.QueueId
Uniquely identifies a queue
-
Field Summary
Fields Modifier and Type Field Description static int
NUMBER_OF_PHYSICAL_QUEUES_PER_NODE
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
add(CrossNodesEvent data)
transactional add ofCrossNodesEvent
to the queue; when operation finished we "guarantee" that theCrossNodesEvent
is persistedvoid
backupQueue(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.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.@NotNull Optional<Path>
getQueueFilePath()
boolean
hasPermission()
@NotNull PerNodeLocalQueue.QueueId
id()
boolean
isClosed()
Some operations (likeadd(CrossNodesEvent)
) on a closed queue will throw aIllegalStateException
.@NotNull String
name()
static int
nodeQueueNumber(long threadId)
Utility method to get the nodeQueueNumber for given thread id.static int
nodeQueueNumberForCurrentThread()
Utility method to get the nodeQueueNumber for current thread.CrossNodesEvent
peek()
Allows to see what's on the head of the queue without removing it.void
remove()
RemoveCrossNodesEvent
from head of the queue.int
size()
Long
usableSpaceInBytes()
-
-
-
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 ofCrossNodesEvent
to the queue; when operation finished we "guarantee" that theCrossNodesEvent
is 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, IllegalStateException
RemoveCrossNodesEvent
from 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 differentCrossNodesEvent
then expected or may throwNoSuchElementException
if 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
-
-