Class Util


  • public final class Util
    extends java.lang.Object
    Set of common functions used by the Disruptor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static sun.misc.Unsafe THE_UNSAFE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int ceilingNextPowerOfTwo​(int x)
      Calculate the next power of 2, greater than or equal to x.
      static long getMinimumSequence​(Sequence[] sequences)
      Get the minimum sequence from an array of Sequences.
      static long getMinimumSequence​(Sequence[] sequences, long minimum)
      Get the minimum sequence from an array of Sequences.
      static Sequence[] getSequencesFor​(EventProcessor... processors)
      Get an array of Sequences for the passed EventProcessors
      static sun.misc.Unsafe getUnsafe()
      Get a handle on the Unsafe instance, used for accessing low-level concurrency and memory constructs.
      static int log2​(int i)
      Calculate the log base 2 of the supplied integer, essentially reports the location of the highest bit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • THE_UNSAFE

        private static final sun.misc.Unsafe THE_UNSAFE
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • 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
      • getMinimumSequence

        public static long getMinimumSequence​(Sequence[] sequences)
        Get the minimum sequence from an array of Sequences.
        Parameters:
        sequences - to compare.
        Returns:
        the minimum sequence found or Long.MAX_VALUE if the array is empty.
      • getMinimumSequence

        public static long getMinimumSequence​(Sequence[] sequences,
                                              long minimum)
        Get the minimum sequence from an array of Sequences.
        Parameters:
        sequences - to compare.
        minimum - an initial default minimum. If the array is empty this value will be returned.
        Returns:
        the smaller of minimum sequence value found in sequences and minimum; minimum if sequences is empty
      • getUnsafe

        public static sun.misc.Unsafe getUnsafe()
        Get a handle on the Unsafe instance, used for accessing low-level concurrency and memory constructs.
        Returns:
        The Unsafe
      • log2

        public static int log2​(int i)
        Calculate the log base 2 of the supplied integer, essentially reports the location of the highest bit.
        Parameters:
        i - Value to calculate log2 for.
        Returns:
        The log2 value