Package org.apache.cassandra.utils
Class FBUtilities
java.lang.Object
org.apache.cassandra.utils.FBUtilities
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final booleanstatic final intstatic final BigIntegerstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longabs(long index) static longalign(long val, int boundary) allOf(Collection<? extends Future<? extends T>> futures) Returns a newFuturewrapping the given list of futures and returning a list of their results.static StringcamelToSnake(String camel) static Filestatic <T> Class<T>classForName(String classname, String readable) static <T> CloseableIterator<T>closeableIterator(Iterator<T> iterator) static voidcloseAll(Collection<? extends AutoCloseable> l) static voidstatic intcompareUnsigned(byte[] bytes1, byte[] bytes2) static intcompareUnsigned(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2) static <T> TConstructs an instance of the given class, which must have a no-arg or default constructor.static longcopy(InputStream from, OutputStream to, long limit) static <T> NavigableSet<T>emptySortedSet(Comparator<? super T> comparator) static voidexec(ProcessBuilder pb) Starts and waits for the given @param pb to finish.static StringStarts and waits for the givencmdto finish.static intstatic InetAddressAndPortGet the broadcast address and port for intra-cluster storage traffic.static InetAddressAndPortThis returns the address that is bound to for the native protocol for communicating with clients.static Stringstatic InetAddressRetrieve just the broadcast address but not the port.static InetAddressThis returns the address that is bound to for the native protocol for communicating with clients.static InetAddressPlease use getJustBroadcastAddress instead.static com.vdurmont.semver4j.Semverstatic InetAddressAndPortThe address and port to listen on for intra-cluster storage traffic (not client).static StringgetNetworkInterface(InetAddress localAddress) static Stringstatic FieldgetProtectedField(Class klass, String fieldName) Used to get access to protected/private field of the specified classstatic Stringstatic Stringstatic Filestatic <T> com.google.common.collect.ImmutableList<T>immutableListWithFilteredNulls(T... values) static <T> TinstanceOrConstruct(String classname, String readable) Constructs an instance of the given class, which must have a no-arg or default constructor.static Pair<BigInteger,Boolean> midpoint(BigInteger left, BigInteger right, int sigbits) Given two bit arrays represented as BigIntegers, containing the given number of significant bits, calculate a midpoint.static IAuditLoggernewAuditLogger(String className, Map<String, String> parameters) static AbstractCryptoProvidernewCryptoProvider(String className, Map<String, String> parameters) static MessageDigestnewMessageDigest(String algorithm) static IPartitionernewPartitioner(String partitionerClassName) static IPartitionernewPartitioner(Descriptor desc) Create a new instance of a partitioner defined in an SSTable Descriptorstatic ISslContextFactorynewSslContextFactory(String className, Map<String, Object> parameters) static Instantnow()static longstatic doubleparseHumanReadable(String datum, String separator, String unit) Parse a human-readable value printed using one of the methods above.static longparseHumanReadableBytes(String value) static doubleparsePercent(String value) Parse a double where both a direct value and a percentage are accepted.static StringprettyPrintBinary(double value, String unit, String separator) Convert the given value to a human-readable string using binary (i.e.static StringprettyPrintDecimal(double value, String unit, String separator) Convert the given value to a human-readable string using decimal (i.e.static StringprettyPrintMemory(long size) Convert the given size in bytes to a human-readable value using binary (i.e.static StringprettyPrintMemory(long size, String separator) Convert the given size in bytes to a human-readable value using binary (i.e.static StringprettyPrintMemoryPerSecond(long rate) static StringprettyPrintMemoryPerSecond(long bytes, long timeInNano) static voidHack to prevent the ugly "illegal access" warnings in Java 11+ like the following.static voidreset()static StringresourceToFile(String filename) static <T> byte[]serialize(T object, IVersionedSerializer<T> serializer, int version) static voidsetAvailableProcessors(int value) static voidTHIS IS FOR TESTING ONLY!!static voidTHIS IS FOR TESTING ONLY!!static voidsetKernelVersionSupplier(Supplier<com.vdurmont.semver4j.Semver> supplier) static voidsetPreviousReleaseVersionString(String previousReleaseVersionString) static <T> NavigableSet<T>singleton(T column, Comparator<? super T> comparator) static voidsleepQuietly(long millis) static voidsortSampledKeys(List<DecoratedKey> keys, Range<Token> range) static longstatic StringMake straing out of the givenMap.static byte[]static voidupdateChecksum(CRC32 checksum, ByteBuffer buffer) Updates checksum with the provided ByteBuffer.static voidupdateChecksum(CRC32 checksum, ByteBuffer buffer, int offset, int length) Updates checksum with the provided ByteBuffer at the given offset + length.static voidupdateChecksumInt(Checksum checksum, int v) static <T,F extends Future<? extends T>>
FwaitOnFirstFuture(Iterable<? extends F> futures) static <T,F extends Future<? extends T>>
FwaitOnFirstFuture(Iterable<? extends F> futures, long delay) Only wait for the first future to finish from a list of futures.static <T> TwaitOnFuture(Future<T> future) static <T> List<T>waitOnFutures(Iterable<? extends Future<? extends T>> futures) static <T> List<T>waitOnFutures(Iterable<? extends Future<? extends T>> futures, long timeout, TimeUnit units) Block for a collection of futures, with optional timeout.
-
Field Details
-
UNKNOWN_RELEASE_VERSION
- See Also:
-
UNKNOWN_GIT_SHA
- See Also:
-
TWO
-
isLinux
public static final boolean isLinux -
MAX_UNSIGNED_SHORT
public static final int MAX_UNSIGNED_SHORT- See Also:
-
ASM_BYTECODE_VERSION
public static final int ASM_BYTECODE_VERSION- See Also:
-
-
Constructor Details
-
FBUtilities
public FBUtilities()
-
-
Method Details
-
setAvailableProcessors
public static void setAvailableProcessors(int value) -
setKernelVersionSupplier
-
getAvailableProcessors
public static int getAvailableProcessors() -
newMessageDigest
-
getJustLocalAddress
Please use getJustBroadcastAddress instead. You need this only when you have to listen/connect. It's also missing the port you should be using. 99% of code doesn't want this. -
getLocalAddressAndPort
The address and port to listen on for intra-cluster storage traffic (not client). Use this to get the correct stuff to listen on for intra-cluster communication. -
getJustBroadcastAddress
Retrieve just the broadcast address but not the port. This is almost always the wrong thing to be using because it's ambiguous since you need the address and port to identify a node. You want getBroadcastAddressAndPort -
getBroadcastAddressAndPort
Get the broadcast address and port for intra-cluster storage traffic. This the address to advertise that uniquely identifies the node and is reachable from everywhere. This is the one you want unless you are trying to connect to the local address specifically. -
setBroadcastInetAddress
THIS IS FOR TESTING ONLY!! -
setBroadcastInetAddressAndPort
THIS IS FOR TESTING ONLY!! -
getJustBroadcastNativeAddress
This returns the address that is bound to for the native protocol for communicating with clients. This is ambiguous because it doesn't include the port and it's almost always the wrong thing to be using you want getBroadcastNativeAddressAndPort -
getBroadcastNativeAddressAndPort
This returns the address that is bound to for the native protocol for communicating with clients. This is almost always what you need to identify a node and how to connect to it as a client. -
getNetworkInterface
-
midpoint
Given two bit arrays represented as BigIntegers, containing the given number of significant bits, calculate a midpoint.- Parameters:
left- The left point.right- The right point.sigbits- The number of bits in the points that are significant.- Returns:
- A midpoint that will compare bitwise halfway between the params, and a boolean representing whether a non-zero lsbit remainder was generated.
-
compareUnsigned
public static int compareUnsigned(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2) -
compareUnsigned
public static int compareUnsigned(byte[] bytes1, byte[] bytes2) -
sortSampledKeys
-
resourceToFile
- Throws:
ConfigurationException
-
cassandraTriggerDir
-
setPreviousReleaseVersionString
-
getPreviousReleaseVersionString
-
getReleaseVersionString
-
getGitSHA
-
getReleaseVersionMajor
-
timestampMicros
public static long timestampMicros() -
nowInSeconds
public static long nowInSeconds() -
now
-
waitOnFutures
-
waitOnFutures
public static <T> List<T> waitOnFutures(Iterable<? extends Future<? extends T>> futures, long timeout, TimeUnit units) Block for a collection of futures, with optional timeout.- Parameters:
futures-timeout- The number of units to wait in total. If this value is less than or equal to zero, no tiemout value will be passed toFuture.get().units- The units of timeout.
-
waitOnFuture
-
waitOnFirstFuture
-
waitOnFirstFuture
public static <T,F extends Future<? extends T>> F waitOnFirstFuture(Iterable<? extends F> futures, long delay) Only wait for the first future to finish from a list of futures. Will block until at least 1 future finishes.- Parameters:
futures- The futures to wait on- Returns:
- future that completed.
-
allOf
Returns a newFuturewrapping the given list of futures and returning a list of their results. -
newPartitioner
Create a new instance of a partitioner defined in an SSTable Descriptor- Parameters:
desc- Descriptor of an sstable- Returns:
- a new IPartitioner instance
- Throws:
IOException
-
newPartitioner
public static IPartitioner newPartitioner(String partitionerClassName) throws ConfigurationException - Throws:
ConfigurationException
-
newAuditLogger
public static IAuditLogger newAuditLogger(String className, Map<String, String> parameters) throws ConfigurationException- Throws:
ConfigurationException
-
newSslContextFactory
public static ISslContextFactory newSslContextFactory(String className, Map<String, Object> parameters) throws ConfigurationException- Throws:
ConfigurationException
-
newCryptoProvider
public static AbstractCryptoProvider newCryptoProvider(String className, Map<String, String> parameters) throws ConfigurationException- Throws:
ConfigurationException
-
classForName
public static <T> Class<T> classForName(String classname, String readable) throws ConfigurationException - Parameters:
classname- Fully qualified classname.readable- Descriptive noun for the role the class plays.- Returns:
- The Class for the given name.
- Throws:
ConfigurationException- If the class cannot be found.
-
instanceOrConstruct
public static <T> T instanceOrConstruct(String classname, String readable) throws ConfigurationException Constructs an instance of the given class, which must have a no-arg or default constructor.- Parameters:
classname- Fully qualified classname.readable- Descriptive noun for the role the class plays.- Throws:
ConfigurationException- If the class cannot be found.
-
construct
Constructs an instance of the given class, which must have a no-arg or default constructor.- Parameters:
classname- Fully qualified classname.readable- Descriptive noun for the role the class plays.- Throws:
ConfigurationException- If the class cannot be found.
-
singleton
-
emptySortedSet
-
toString
Make straing out of the givenMap.- Parameters:
map- Map to make string.- Returns:
- String representation of all entries in the map, where key and value pair is concatenated with ':'.
-
getProtectedField
Used to get access to protected/private field of the specified class- Parameters:
klass- - name of the classfieldName- - name of the field- Returns:
- Field or null on error
-
closeableIterator
-
prettyPrintMemory
Convert the given size in bytes to a human-readable value using binary (i.e. 2^10-based) modifiers. For example, 1.000KiB, 2.100GiB etc., up to 8.000 EiB.- Parameters:
size- Number to convert.
-
prettyPrintMemory
Convert the given size in bytes to a human-readable value using binary (i.e. 2^10-based) modifiers. For example, 1.000KiB, 2.100GiB etc., up to 8.000 EiB.- Parameters:
size- Number to convert.separator- Separator between the number and the (modified) unit.
-
prettyPrintBinary
Convert the given value to a human-readable string using binary (i.e. 2^10-based) modifiers. If the number is outside the modifier range (i.e. < 1 qi or > 1 Qi), it will be printed as v*2^e where e is a multiple of 10 with sign. For example, 1.000KiB, 2.100 miB/s, 7.006*2^+150, -Infinity.- Parameters:
value- Number to convert.separator- Separator between the number and the (modified) unit.
-
prettyPrintDecimal
Convert the given value to a human-readable string using decimal (i.e. 10^3-based) modifiers. If the number is outside the modifier range (i.e. < 1 qi or > 1 Qi), it will be printed as vEe where e is a multiple of 3 with sign. For example, 1.000km, 2.100 ms, 10E+45, NaN.- Parameters:
value- Number to convert.separator- Separator between the number and the (modified) unit.
-
prettyPrintMemoryPerSecond
-
prettyPrintMemoryPerSecond
-
parseHumanReadable
Parse a human-readable value printed using one of the methods above. Understands both binary and decimal modifiers, as well as decimal exponents using the E notation and binary exponents using *2^e.- Parameters:
datum- The human-readable number.separator- Expected separator, null to accept any amount of whitespace.unit- Expected unit. If null, the method will accept any string as unit, i.e. it will parse the number at the start of the supplied string and ignore any remainder.- Returns:
- The parsed value.
-
parseHumanReadableBytes
-
parsePercent
Parse a double where both a direct value and a percentage are accepted. For example, for inputs "0.1" and "10%", this function will return 0.1. -
exec
Starts and waits for the given @param pb to finish.- Throws:
IOException- on non-zero exit code
-
exec
public static String exec(Map<String, String> env, Duration timeout, int outBufSize, int errBufSize, String... cmd) throws IOException, TimeoutException, InterruptedExceptionStarts and waits for the givencmdto finish. If the process does not finish withintimeout, it will be destroyed.- Parameters:
env- additional environment variables to settimeout- timeout for the process to finish, or zero/null to wait foreveroutBufSize- the maximum size of the collected std output; the overflow will be discardederrBufSize- the maximum size of the collected std error; the overflow will be discardedcmd- the command to execute- Returns:
- the std output of the process up to the size specified by
outBufSize - Throws:
IOExceptionTimeoutExceptionInterruptedException
-
updateChecksumInt
-
updateChecksum
Updates checksum with the provided ByteBuffer at the given offset + length. Resets position and limit back to their original values on return. This method is *NOT* thread-safe. -
updateChecksum
Updates checksum with the provided ByteBuffer. Resets position back to its original values on return. This method is *NOT* thread-safe. -
abs
public static long abs(long index) -
serialize
-
copy
- Throws:
IOException
-
getToolsOutputDirectory
-
closeAll
- Throws:
Exception
-
toWriteUTFBytes
-
sleepQuietly
public static void sleepQuietly(long millis) -
align
public static long align(long val, int boundary) -
reset
public static void reset() -
preventIllegalAccessWarnings
public static void preventIllegalAccessWarnings()Hack to prevent the ugly "illegal access" warnings in Java 11+ like the following. -
camelToSnake
-
immutableListWithFilteredNulls
@SafeVarargs public static <T> com.google.common.collect.ImmutableList<T> immutableListWithFilteredNulls(T... values) -
closeQuietly
-
getKernelVersion
public static com.vdurmont.semver4j.Semver getKernelVersion()
-