org.appng.api.search

## Class BlockingQueueAccessor<E>

- java.lang.Object
- - org.appng.api.search.BlockingQueueAccessor<E>

- Direct Known Subclasses:
    Consumer, Producer

      public abstract class BlockingQueueAccessor<E>
      extends Object

  A `BlockingQueue`-based implementation for consumer-producer-scenarios.
  Note that all available operations are blocking!
  Author:
    Matthias Müller
  See Also:
    `Producer`, `Consumer`

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `BlockingQueueAccessor()` Creates a new `BlockingQueueAccessor` with a queue size of 100}.
    `protected` | `BlockingQueueAccessor(int queueSize)` Creates a new `BlockingQueueAccessor` with the given queue size.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `E` | `get()` Retrieves and removes the head of the queue. This is a blocking operation!
    `E` | `get(long timeoutMillis)` Retrieves and removes the head of the queue, waiting up to `timeoutMillis` milliseconds if necessary.
    `protected BlockingQueue<E>` | `getBlockingQueue()`
    `E` | `getWithTimeout(long timeoutMillis)` Retrieves and removes the head of the queue, waiting up to `timeoutMillis` milliseconds if necessary.
    `void` | `put(E element)` Puts the given `element` into the queue. This is a blocking operation!
    `boolean` | `put(E element, long timeoutMillis)` Puts the given `element` into the queue, waiting up to `timeoutMillis` milliseconds if necessary. This is a blocking operation!
    `void` | `putWithTimeout(E element, long timeoutMillis)` Puts the given `element` into the queue, waiting up to `timeoutMillis` milliseconds if necessary.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BlockingQueueAccessor

          protected BlockingQueueAccessor(int queueSize)

      Creates a new `BlockingQueueAccessor` with the given queue size.
      Parameters:
        `queueSize` - the size of the internal `BlockingQueue`

    - #### BlockingQueueAccessor

          protected BlockingQueueAccessor()

      Creates a new `BlockingQueueAccessor` with a queue size of 100}.

  - ### Method Detail

    - #### put

          public void put(E element)
                   throws InterruptedException

      Puts the given `element` into the queue.
      This is a blocking operation!
      Parameters:
        `element` - the element of type `<E>` to put to the queue
      Throws:
        `InterruptedException` - if interrupted while waiting

    - #### put

          public boolean put(E element,
                             long timeoutMillis)
                      throws InterruptedException

      Puts the given `element` into the queue, waiting up to `timeoutMillis` milliseconds if necessary.
      This is a blocking operation!
      Parameters:
        `element` - the element of type `<E>` to put into the queue
        `timeoutMillis` - the time to wait in milliseconds
      Returns:
        `true` if the element could be added before the timeout, `false` otherwise
      Throws:
        `InterruptedException` - if interrupted while waiting

    - #### putWithTimeout

          public void putWithTimeout(E element,
                                     long timeoutMillis)
                              throws InterruptedException,
                                     TimeoutException

      Puts the given `element` into the queue, waiting up to `timeoutMillis` milliseconds if necessary. If no element could be added, a `TimeoutException` is thrown.
      This is a blocking operation!
      Parameters:
        `element` - the element of type `<E>` to put to the queue
        `timeoutMillis` - the time to wait in milliseconds
      Throws:
        `InterruptedException` - if interrupted while waiting
        `TimeoutException` - if a timeout occurred while waiting

    - #### get

          public E get()
                throws InterruptedException

      Retrieves and removes the head of the queue.
      This is a blocking operation!
      Returns:
        an element of type `<E>`
      Throws:
        `InterruptedException` - if interrupted while waiting

    - #### get

          public E get(long timeoutMillis)
                throws InterruptedException

      Retrieves and removes the head of the queue, waiting up to `timeoutMillis` milliseconds if necessary. If no element could be retrieved, `null` is returned.
      This is a blocking operation!
      Parameters:
        `timeoutMillis` - the time to wait in milliseconds
      Returns:
        an element of type `<E>`, or `null` if no element could be retrieved in `timeoutMillis` milliseconds
      Throws:
        `InterruptedException` - if interrupted while waiting

    - #### getWithTimeout

          public E getWithTimeout(long timeoutMillis)
                           throws InterruptedException,
                                  TimeoutException

      Retrieves and removes the head of the queue, waiting up to `timeoutMillis` milliseconds if necessary. If no element could be retrieved, a `TimeoutException` is thrown.
      This is a blocking operation!
      Parameters:
        `timeoutMillis` - the time to wait in milliseconds
      Returns:
        an element of type `<E>`
      Throws:
        `InterruptedException` - if interrupted while waiting
        `TimeoutException` - if a timeout occurred while waiting

    - #### getBlockingQueue

          protected BlockingQueue<E> getBlockingQueue()

Copyright © 2011–2023 aiticon GmbH. All rights reserved.