Class Queues

java.lang.Object
reactor.util.concurrent.Queues

public final class Queues extends Object
Queue utilities and suppliers for 1-producer/1-consumer ready queues adapted for various given capacities.
  • Field Details

    • CAPACITY_UNSURE

      public static final int CAPACITY_UNSURE
      See Also:
    • XS_BUFFER_SIZE

      public static final int XS_BUFFER_SIZE
      An allocation friendly default of available slots in a given container, e.g. slow publishers and or fast/few subscribers
    • SMALL_BUFFER_SIZE

      public static final int SMALL_BUFFER_SIZE
      A small default of available slots in a given container, compromise between intensive pipelines, small subscribers numbers and memory use.
  • Method Details

    • capacity

      public static int capacity(Queue q)
      Return the capacity of a given Queue in a best effort fashion. Queues that are known to be unbounded will return Integer.MAX_VALUE and queues that have a known bounded capacity will return that capacity. For other Queue implementations not recognized by this method or not providing this kind of information, CAPACITY_UNSURE (Integer.MIN_VALUE) is returned.
      Parameters:
      q - the Queue to try to get a capacity for
      Returns:
      the capacity of the queue, if discoverable with confidence, or CAPACITY_UNSURE negative constant.
    • ceilingNextPowerOfTwo

      public static int ceilingNextPowerOfTwo(int x)
      Calculate the next power of 2, greater than or equal to x.

      From Hacker's Delight, Chapter 3, Harry S. Warren Jr.

      Parameters:
      x - Value to round up
      Returns:
      The next power of 2 from x inclusive
    • get

      public static <T> Supplier<Queue<T>> get(int batchSize)
      Type Parameters:
      T - the reified Queue generic type
      Parameters:
      batchSize - the bounded or unbounded (int.max) queue size
      Returns:
      an unbounded or bounded Queue Supplier
    • isPowerOfTwo

      public static boolean isPowerOfTwo(int x)
      Parameters:
      x - the int to test
      Returns:
      true if x is a power of 2
    • empty

      public static <T> Supplier<Queue<T>> empty()
      A Supplier for an empty immutable Queue, to be used as a placeholder in methods that require a Queue when one doesn't expect to store any data in said Queue.
      Type Parameters:
      T - the reified Queue generic type
      Returns:
      an immutable empty Queue Supplier
    • one

      public static <T> Supplier<Queue<T>> one()
      Type Parameters:
      T - the reified Queue generic type
      Returns:
      a bounded Queue Supplier
    • small

      public static <T> Supplier<Queue<T>> small()
      Type Parameters:
      T - the reified Queue generic type
      Returns:
      a bounded Queue Supplier
    • unbounded

      public static <T> Supplier<Queue<T>> unbounded()
      Type Parameters:
      T - the reified Queue generic type
      Returns:
      an unbounded Queue Supplier
    • unbounded

      public static <T> Supplier<Queue<T>> unbounded(int linkSize)
      Returns an unbounded, linked-array-based Queue. Integer.max sized link will return the default SMALL_BUFFER_SIZE size.
      Type Parameters:
      T - the reified Queue generic type
      Parameters:
      linkSize - the link size
      Returns:
      an unbounded Queue Supplier
    • xs

      public static <T> Supplier<Queue<T>> xs()
      Type Parameters:
      T - the reified Queue generic type
      Returns:
      a bounded Queue Supplier
    • unboundedMultiproducer

      public static <T> Supplier<Queue<T>> unboundedMultiproducer()
      Returns an unbounded queue suitable for multi-producer/single-consumer (MPSC) scenarios.
      Type Parameters:
      T - the reified Queue generic type
      Returns:
      an unbounded MPSC Queue Supplier