Class DefaultQueue<T>

java.lang.Object
io.aleph0.yap.core.transport.queue.DefaultQueue<T>
All Implemented Interfaces:
Measureable<Queue.Metrics>, Queue<T>

public class DefaultQueue<T> extends Object implements Queue<T>
  • Constructor Details

    • DefaultQueue

      public DefaultQueue(int capacity, List<Channel<T>> subscriptions)
  • Method Details

    • builder

      public static <T> DefaultQueue.Builder<T> builder()
    • tryReceive

      public T tryReceive()
      Description copied from interface: Queue
      Attempts to receive a message from the queue. This method will return immediately, even if there are no messages available in the queue. Returns null if the queue is empty, whethere it is closed or not, so users must not conclude that the queue is closed and drained from this method returning null.
      Specified by:
      tryReceive in interface Queue<T>
      Returns:
      the message received from the queue, or null if the queue is empty
    • receive

      public T receive(Duration timeout) throws InterruptedException, TimeoutException
      Description copied from interface: Queue
      Receives a message from the queue, waiting if necessary. This method will block until a message is received from the queue or the timeout expires. If the queue is closed and drained, this method will return null. Users may conclude that the queue is closed and drained from this method returning null.
      Specified by:
      receive in interface Queue<T>
      Parameters:
      timeout - the maximum time to wait for a message to be received
      Returns:
      the message received from the queue, or null if the queue is closed and drained
      Throws:
      InterruptedException - if the thread is interrupted while waiting
      TimeoutException - if the wait times out before a message is received
    • receive

      public T receive() throws InterruptedException
      Description copied from interface: Queue
      Receives a message from the queue, waiting if necessary. This method will block until a message is received from the queue. If the queue is closed and drained, this method will return null. Users may conclude that the queue is closed and drained from this method returning null.
      Specified by:
      receive in interface Queue<T>
      Returns:
      the message received from the queue, or null if the queue is closed and drained
      Throws:
      InterruptedException - if the thread is interrupted while waiting
    • isDrained

      public boolean isDrained()
      Specified by:
      isDrained in interface Queue<T>
    • checkMetrics

      public Queue.Metrics checkMetrics()
      Description copied from interface: Measureable
      Non-destructive check of the metrics. This should be used to check the state of metrics without clearing them, for example in a TaskController.
      Specified by:
      checkMetrics in interface Measureable<T>
      Returns:
      the metrics
    • flushMetrics

      public Queue.Metrics flushMetrics()
      Description copied from interface: Measureable
      Destructive read of the metrics. This should be used to check and reset the state of metrics, for example by the metrics checking thread.
      Specified by:
      flushMetrics in interface Measureable<T>
      Returns:
      the metrics