Package com.lmax.disruptor.util
Class Util
java.lang.Object
com.lmax.disruptor.util.Util
Set of common functions used by the Disruptor.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longawaitNanos(Object mutex, long timeoutNanos) static intceilingNextPowerOfTwo(int x) Calculate the next power of 2, greater than or equal to x.static longgetMinimumSequence(Sequence[] sequences) Get the minimum sequence from an array ofSequences.static longgetMinimumSequence(Sequence[] sequences, long minimum) Get the minimum sequence from an array ofSequences.static Sequence[]getSequencesFor(EventProcessor... processors) Get an array ofSequences for the passedEventProcessors.static intlog2(int value) Calculate the log base 2 of the supplied integer, essentially reports the location of the highest bit.
-
Field Details
-
ONE_MILLISECOND_IN_NANOSECONDS
private static final int ONE_MILLISECOND_IN_NANOSECONDS- See Also:
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
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
Get the minimum sequence from an array ofSequences.- Parameters:
sequences- to compare.- Returns:
- the minimum sequence found or Long.MAX_VALUE if the array is empty.
-
getMinimumSequence
Get the minimum sequence from an array ofSequences.- 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
sequencesandminimum;minimumifsequencesis empty
-
getSequencesFor
Get an array ofSequences for the passedEventProcessors.- Parameters:
processors- for which to get the sequences- Returns:
- the array of
Sequences
-
log2
public static int log2(int value) Calculate the log base 2 of the supplied integer, essentially reports the location of the highest bit.- Parameters:
value- Positive value to calculate log2 for.- Returns:
- The log2 value
-
awaitNanos
- Parameters:
mutex- The object to wait ontimeoutNanos- The number of nanoseconds to wait for- Returns:
- the number of nanoseconds waited (approximately)
- Throws:
InterruptedException- if the underlying call to wait is interrupted
-