Package org.apache.cassandra.utils
Class FBUtilities
- java.lang.Object
-
- org.apache.cassandra.utils.FBUtilities
-
public class FBUtilities extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static booleanisLinuxstatic intMAX_UNSIGNED_SHORTstatic java.math.BigIntegerTWOstatic java.lang.StringUNKNOWN_RELEASE_VERSION
-
Constructor Summary
Constructors Constructor Description FBUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longabs(long index)static longalign(long val, int boundary)static <T> Future<java.util.List<T>>allOf(java.util.Collection<? extends Future<? extends T>> futures)Returns a newFuturewrapping the given list of futures and returning a list of their results.static java.lang.StringcamelToSnake(java.lang.String camel)static FilecassandraTriggerDir()static <T> java.lang.Class<T>classForName(java.lang.String classname, java.lang.String readable)static <T> CloseableIterator<T>closeableIterator(java.util.Iterator<T> iterator)static voidcloseAll(java.util.Collection<? extends java.lang.AutoCloseable> l)static intcompareUnsigned(byte[] bytes1, byte[] bytes2)static intcompareUnsigned(byte[] bytes1, byte[] bytes2, int offset1, int offset2, int len1, int len2)static <T> Tconstruct(java.lang.String classname, java.lang.String readable)Constructs an instance of the given class, which must have a no-arg or default constructor.static longcopy(java.io.InputStream from, java.io.OutputStream to, long limit)static <T> TdeserializeFromJsonFile(java.lang.Class<T> tClass, File file)static <T> java.util.NavigableSet<T>emptySortedSet(java.util.Comparator<? super T> comparator)static voidexec(java.lang.ProcessBuilder pb)Starts and waits for the given @param pb to finish.static java.util.List<java.lang.String>fromJsonList(java.lang.String json)static java.util.Map<java.lang.String,java.lang.String>fromJsonMap(java.lang.String json)static intgetAvailableProcessors()static InetAddressAndPortgetBroadcastAddressAndPort()Get the broadcast address and port for intra-cluster storage traffic.static InetAddressAndPortgetBroadcastNativeAddressAndPort()This returns the address that is bound to for the native protocol for communicating with clients.static java.net.InetAddressgetJustBroadcastAddress()Retrieve just the broadcast address but not the port.static java.net.InetAddressgetJustBroadcastNativeAddress()This returns the address that is bound to for the native protocol for communicating with clients.static java.net.InetAddressgetJustLocalAddress()Please use getJustBroadcastAddress instead.static InetAddressAndPortgetLocalAddressAndPort()The address and port to listen on for intra-cluster storage traffic (not client).static java.lang.StringgetNetworkInterface(java.net.InetAddress localAddress)static java.lang.StringgetPreviousReleaseVersionString()static java.lang.reflect.FieldgetProtectedField(java.lang.Class klass, java.lang.String fieldName)Used to get access to protected/private field of the specified classstatic java.lang.StringgetReleaseVersionMajor()static java.lang.StringgetReleaseVersionString()static FilegetToolsOutputDirectory()static <T> TinstanceOrConstruct(java.lang.String classname, java.lang.String readable)Constructs an instance of the given class, which must have a no-arg or default constructor.static java.lang.Stringjson(java.lang.Object object)static Pair<java.math.BigInteger,java.lang.Boolean>midpoint(java.math.BigInteger left, java.math.BigInteger right, int sigbits)Given two bit arrays represented as BigIntegers, containing the given number of significant bits, calculate a midpoint.static IAuditLoggernewAuditLogger(java.lang.String className, java.util.Map<java.lang.String,java.lang.String> parameters)static IAuthenticatornewAuthenticator(java.lang.String className)static IAuthorizernewAuthorizer(java.lang.String className)static java.security.MessageDigestnewMessageDigest(java.lang.String algorithm)static INetworkAuthorizernewNetworkAuthorizer(java.lang.String className)static IPartitionernewPartitioner(java.lang.String partitionerClassName)static IPartitionernewPartitioner(Descriptor desc)Create a new instance of a partitioner defined in an SSTable Descriptorstatic IRoleManagernewRoleManager(java.lang.String className)static ISslContextFactorynewSslContextFactory(java.lang.String className, java.util.Map<java.lang.String,java.lang.Object> parameters)static java.time.Instantnow()static intnowInSeconds()static java.lang.StringprettyPrintMemory(long size)static java.lang.StringprettyPrintMemory(long size, boolean includeSpace)static java.lang.StringprettyPrintMemoryPerSecond(long rate)static java.lang.StringprettyPrintMemoryPerSecond(long bytes, long timeInNano)static voidpreventIllegalAccessWarnings()Hack to prevent the ugly "illegal access" warnings in Java 11+ like the following.static voidreset()static java.lang.StringresourceToFile(java.lang.String filename)static <T> byte[]serialize(T object, IVersionedSerializer<T> serializer, int version)static voidserializeToJsonFile(java.lang.Object object, File outputFile)static voidsetAvailableProcessors(int value)static voidsetBroadcastInetAddress(java.net.InetAddress addr)THIS IS FOR TESTING ONLY!!static voidsetBroadcastInetAddressAndPort(InetAddressAndPort addr)THIS IS FOR TESTING ONLY!!static voidsetPreviousReleaseVersionString(java.lang.String previousReleaseVersionString)static <T> java.util.NavigableSet<T>singleton(T column, java.util.Comparator<? super T> comparator)static voidsleepQuietly(long millis)static voidsortSampledKeys(java.util.List<DecoratedKey> keys, Range<Token> range)static longtimestampMicros()static java.lang.StringtoString(java.util.Map<?,?> map)Make straing out of the givenMap.static byte[]toWriteUTFBytes(java.lang.String s)static voidupdateChecksum(java.util.zip.CRC32 checksum, java.nio.ByteBuffer buffer)Updates checksum with the provided ByteBuffer.static voidupdateChecksum(java.util.zip.CRC32 checksum, java.nio.ByteBuffer buffer, int offset, int length)Updates checksum with the provided ByteBuffer at the given offset + length.static voidupdateChecksumInt(java.util.zip.Checksum checksum, int v)static <T,F extends java.util.concurrent.Future<? extends T>>
FwaitOnFirstFuture(java.lang.Iterable<? extends F> futures)static <T,F extends java.util.concurrent.Future<? extends T>>
FwaitOnFirstFuture(java.lang.Iterable<? extends F> futures, long delay)Only wait for the first future to finish from a list of futures.static <T> TwaitOnFuture(java.util.concurrent.Future<T> future)static <T> java.util.List<T>waitOnFutures(java.lang.Iterable<? extends java.util.concurrent.Future<? extends T>> futures)static <T> java.util.List<T>waitOnFutures(java.lang.Iterable<? extends java.util.concurrent.Future<? extends T>> futures, long timeout, java.util.concurrent.TimeUnit units)Block for a collection of futures, with optional timeout.
-
-
-
Field Detail
-
UNKNOWN_RELEASE_VERSION
public static final java.lang.String UNKNOWN_RELEASE_VERSION
- See Also:
- Constant Field Values
-
TWO
public static final java.math.BigInteger TWO
-
isLinux
public static final boolean isLinux
-
MAX_UNSIGNED_SHORT
public static final int MAX_UNSIGNED_SHORT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setAvailableProcessors
public static void setAvailableProcessors(int value)
-
getAvailableProcessors
public static int getAvailableProcessors()
-
newMessageDigest
public static java.security.MessageDigest newMessageDigest(java.lang.String algorithm)
-
getJustLocalAddress
public static java.net.InetAddress 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
public static InetAddressAndPort 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
public static java.net.InetAddress 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
public static InetAddressAndPort 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
public static void setBroadcastInetAddress(java.net.InetAddress addr)
THIS IS FOR TESTING ONLY!!
-
setBroadcastInetAddressAndPort
public static void setBroadcastInetAddressAndPort(InetAddressAndPort addr)
THIS IS FOR TESTING ONLY!!
-
getJustBroadcastNativeAddress
public static java.net.InetAddress 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
public static InetAddressAndPort 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
public static java.lang.String getNetworkInterface(java.net.InetAddress localAddress)
-
midpoint
public static Pair<java.math.BigInteger,java.lang.Boolean> midpoint(java.math.BigInteger left, java.math.BigInteger right, int sigbits)
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
public static void sortSampledKeys(java.util.List<DecoratedKey> keys, Range<Token> range)
-
resourceToFile
public static java.lang.String resourceToFile(java.lang.String filename) throws ConfigurationException- Throws:
ConfigurationException
-
cassandraTriggerDir
public static File cassandraTriggerDir()
-
setPreviousReleaseVersionString
public static void setPreviousReleaseVersionString(java.lang.String previousReleaseVersionString)
-
getPreviousReleaseVersionString
public static java.lang.String getPreviousReleaseVersionString()
-
getReleaseVersionString
public static java.lang.String getReleaseVersionString()
-
getReleaseVersionMajor
public static java.lang.String getReleaseVersionMajor()
-
timestampMicros
public static long timestampMicros()
-
nowInSeconds
public static int nowInSeconds()
-
now
public static java.time.Instant now()
-
waitOnFutures
public static <T> java.util.List<T> waitOnFutures(java.lang.Iterable<? extends java.util.concurrent.Future<? extends T>> futures)
-
waitOnFutures
public static <T> java.util.List<T> waitOnFutures(java.lang.Iterable<? extends java.util.concurrent.Future<? extends T>> futures, long timeout, java.util.concurrent.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
public static <T> T waitOnFuture(java.util.concurrent.Future<T> future)
-
waitOnFirstFuture
public static <T,F extends java.util.concurrent.Future<? extends T>> F waitOnFirstFuture(java.lang.Iterable<? extends F> futures)
-
waitOnFirstFuture
public static <T,F extends java.util.concurrent.Future<? extends T>> F waitOnFirstFuture(java.lang.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
public static <T> Future<java.util.List<T>> allOf(java.util.Collection<? extends Future<? extends T>> futures)
Returns a newFuturewrapping the given list of futures and returning a list of their results.
-
newPartitioner
public static IPartitioner newPartitioner(Descriptor desc) throws java.io.IOException
Create a new instance of a partitioner defined in an SSTable Descriptor- Parameters:
desc- Descriptor of an sstable- Returns:
- a new IPartitioner instance
- Throws:
java.io.IOException
-
newPartitioner
public static IPartitioner newPartitioner(java.lang.String partitionerClassName) throws ConfigurationException
- Throws:
ConfigurationException
-
newAuthorizer
public static IAuthorizer newAuthorizer(java.lang.String className) throws ConfigurationException
- Throws:
ConfigurationException
-
newAuthenticator
public static IAuthenticator newAuthenticator(java.lang.String className) throws ConfigurationException
- Throws:
ConfigurationException
-
newRoleManager
public static IRoleManager newRoleManager(java.lang.String className) throws ConfigurationException
- Throws:
ConfigurationException
-
newNetworkAuthorizer
public static INetworkAuthorizer newNetworkAuthorizer(java.lang.String className)
-
newAuditLogger
public static IAuditLogger newAuditLogger(java.lang.String className, java.util.Map<java.lang.String,java.lang.String> parameters) throws ConfigurationException
- Throws:
ConfigurationException
-
newSslContextFactory
public static ISslContextFactory newSslContextFactory(java.lang.String className, java.util.Map<java.lang.String,java.lang.Object> parameters) throws ConfigurationException
- Throws:
ConfigurationException
-
classForName
public static <T> java.lang.Class<T> classForName(java.lang.String classname, java.lang.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(java.lang.String classname, java.lang.String readable) throws ConfigurationExceptionConstructs 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
public static <T> T construct(java.lang.String classname, java.lang.String readable) throws ConfigurationExceptionConstructs 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
public static <T> java.util.NavigableSet<T> singleton(T column, java.util.Comparator<? super T> comparator)
-
emptySortedSet
public static <T> java.util.NavigableSet<T> emptySortedSet(java.util.Comparator<? super T> comparator)
-
toString
@Nonnull public static java.lang.String toString(@Nullable java.util.Map<?,?> map)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
public static java.lang.reflect.Field getProtectedField(java.lang.Class klass, java.lang.String fieldName)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
public static <T> CloseableIterator<T> closeableIterator(java.util.Iterator<T> iterator)
-
fromJsonMap
public static java.util.Map<java.lang.String,java.lang.String> fromJsonMap(java.lang.String json)
-
fromJsonList
public static java.util.List<java.lang.String> fromJsonList(java.lang.String json)
-
json
public static java.lang.String json(java.lang.Object object)
-
serializeToJsonFile
public static void serializeToJsonFile(java.lang.Object object, File outputFile) throws java.io.IOException- Throws:
java.io.IOException
-
deserializeFromJsonFile
public static <T> T deserializeFromJsonFile(java.lang.Class<T> tClass, File file) throws java.io.IOException- Throws:
java.io.IOException
-
prettyPrintMemory
public static java.lang.String prettyPrintMemory(long size)
-
prettyPrintMemory
public static java.lang.String prettyPrintMemory(long size, boolean includeSpace)
-
prettyPrintMemoryPerSecond
public static java.lang.String prettyPrintMemoryPerSecond(long rate)
-
prettyPrintMemoryPerSecond
public static java.lang.String prettyPrintMemoryPerSecond(long bytes, long timeInNano)
-
exec
public static void exec(java.lang.ProcessBuilder pb) throws java.io.IOExceptionStarts and waits for the given @param pb to finish.- Throws:
java.io.IOException- on non-zero exit code
-
updateChecksumInt
public static void updateChecksumInt(java.util.zip.Checksum checksum, int v)
-
updateChecksum
public static void updateChecksum(java.util.zip.CRC32 checksum, java.nio.ByteBuffer buffer, int offset, int length)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
public static void updateChecksum(java.util.zip.CRC32 checksum, java.nio.ByteBuffer buffer)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
public static <T> byte[] serialize(T object, IVersionedSerializer<T> serializer, int version)
-
copy
public static long copy(java.io.InputStream from, java.io.OutputStream to, long limit) throws java.io.IOException- Throws:
java.io.IOException
-
getToolsOutputDirectory
public static File getToolsOutputDirectory()
-
closeAll
public static void closeAll(java.util.Collection<? extends java.lang.AutoCloseable> l) throws java.lang.Exception- Throws:
java.lang.Exception
-
toWriteUTFBytes
public static byte[] toWriteUTFBytes(java.lang.String s)
-
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
public static java.lang.String camelToSnake(java.lang.String camel)
-
-