Interface PerNodeLocalQueue
- All Known Implementing Classes:
TapePerNodeLocalQueue
,TapePerNodeLocalQueueWithStats
public interface PerNodeLocalQueue
Abstracts persistent queue implementation
A queue represents a FIFO queue of
CrossNodesEvent
for a specific node BambooNodeInfo
.
Each node may have from 1 to n queues. Each queue has a single processing (reading) process so
BambooClusterSettings.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 be
BambooClusterSettings.NUMBER_OF_PHYSICAL_QUEUES_UNDER_PER_NODE_QUEUE
queues for each of the "other" 2 remote nodes.- Since:
- 9.5
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Uniquely identifies a queue -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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.boolean
@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
Utility method to get the nodeQueueNumber for current thread.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()
-
Field Details
-
NUMBER_OF_PHYSICAL_QUEUES_PER_NODE
static final int NUMBER_OF_PHYSICAL_QUEUES_PER_NODE
-
-
Method Details
-
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
- Returns:
- name of the queue could be useful for the user, like identifying the queue file path from logs
-
id
- Returns:
- queue id which uniquely identifies this queue, i.e destination node and nodeQueueNumber, see
PerNodeLocalQueue.QueueId
-
add
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
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
RemoveCrossNodesEvent
from head of the queue.- Throws:
NoSuchElementException
- when doing a remove on an empty queueIllegalStateException
- when queue is closed
-
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
- 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
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
-