Interface ServicesQueue

All Superinterfaces:
AutoCloseable

public interface ServicesQueue extends AutoCloseable
A queue for receiving service query answers.
Author:
David M. Lloyd
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Wait for a queue entry to become available.
    void
    await(long time, TimeUnit unit)
    Wait for a certain amount of time for a queue entry to become available.
    void
    Cancel any in-progress discovery for this queue.
    Get a list of problems that occurred during discovery.
    boolean
    Query whether this queue is finished (all services have been read).
    boolean
    Query whether there is a value ready to be read.
    default URI
    Get the location URI of the next entry from the queue without blocking.
    Get the next entry from the queue without blocking.
    default URI
    Get the location URI of the next entry from the queue, blocking until one is available or the thread is interrupted.
    Get the next entry from the queue, blocking until one is available or the thread is interrupted.
    takeService(long timeout, TimeUnit timeUnit)
    Get the next entry from the queue, blocking until one is available or timeout expires.
    withTimeout(long time, TimeUnit unit)
    Create a version of this queue which has an absolute timeout, relative to when this method is called.
  • Method Details

    • await

      void await() throws InterruptedException
      Wait for a queue entry to become available. When this method returns, poll() will return a value (or null if all services have been read) and take() will return without blocking.
      Throws:
      InterruptedException - if the calling thread was interrupted while waiting for the next entry
    • await

      void await(long time, TimeUnit unit) throws InterruptedException
      Wait for a certain amount of time for a queue entry to become available.
      Parameters:
      time - the amount of time to wait
      unit - the unit of time (must not be null)
      Throws:
      InterruptedException - if the calling thread was interrupted while waiting for the next entry
    • isReady

      boolean isReady()
      Query whether there is a value ready to be read.
      Returns:
      true if the queue has a value, false otherwise
    • poll

      default URI poll()
      Get the location URI of the next entry from the queue without blocking. Returns null if there is no entry ready, or if the queue is finished (all services have been read). Use isFinished() to distinguish the cases.
      Returns:
      the next URI, or null if the queue is not ready or is finished
    • take

      default URI take() throws InterruptedException
      Get the location URI of the next entry from the queue, blocking until one is available or the thread is interrupted. Returns null if the queue is finished (all services have been read).
      Returns:
      the next URI, or null if the queue is finished
      Throws:
      InterruptedException - if the calling thread was interrupted while waiting for the next entry
    • pollService

      ServiceURL pollService()
      Get the next entry from the queue without blocking. Returns null if there is no entry ready, or if the queue is finished (all services have been read). Use isFinished() to distinguish the cases.
      Returns:
      the next service URL, or null if the queue is not ready or is finished
    • takeService

      ServiceURL takeService() throws InterruptedException
      Get the next entry from the queue, blocking until one is available or the thread is interrupted. Returns null if the queue is finished (all services have been read).
      Returns:
      the next service URL, or null if the queue is finished
      Throws:
      InterruptedException - if the calling thread was interrupted while waiting for the next entry
    • takeService

      ServiceURL takeService(long timeout, TimeUnit timeUnit) throws InterruptedException
      Get the next entry from the queue, blocking until one is available or timeout expires. Returns null if the queue is finished (all services have been read).
      Returns:
      the next service URL, or null if the queue is finished
      Throws:
      InterruptedException - if the calling thread was interrupted while waiting for the next entry
    • isFinished

      boolean isFinished()
      Query whether this queue is finished (all services have been read).
      Returns:
      true if the queue is finished, false otherwise
    • close

      void close()
      Cancel any in-progress discovery for this queue. This method is idempotent.
      Specified by:
      close in interface AutoCloseable
    • getProblems

      @NotNull List<Throwable> getProblems()
      Get a list of problems that occurred during discovery.
      Returns:
      a list of problems that occurred during discovery (not null)
    • withTimeout

      default ServicesQueue withTimeout(long time, TimeUnit unit)
      Create a version of this queue which has an absolute timeout, relative to when this method is called.
      Parameters:
      time - the timeout time
      unit - the timeout unit (must not be null)
      Returns:
      the services queue with a timeout (not null)