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
  • 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 (like add(CrossNodesEvent)) on a closed queue will throw a IllegalStateException. 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 of CrossNodesEvent to the queue; when operation finished we "guarantee" that the CrossNodesEvent 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

      Remove CrossNodesEvent from head of the queue.
      Throws:
      NoSuchElementException - when doing a remove on an empty queue
      IllegalStateException - 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 if backupQueue(String) is called between peek() and remove() this can cause remove() to delete a different CrossNodesEvent then expected or may throw NoSuchElementException if the new queue after backupQueue(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