org.apache.cassandra.utils
Class FBUtilities
java.lang.Object
org.apache.cassandra.utils.FBUtilities
public class FBUtilities
- extends java.lang.Object
Method Summary |
static long |
absoluteFromFraction(double fractOrAbs,
long total)
|
static void |
atomicSetMax(java.util.concurrent.atomic.AtomicInteger atomic,
int i)
|
static void |
atomicSetMax(java.util.concurrent.atomic.AtomicLong atomic,
long i)
|
static void |
atomicSetMax(java.util.concurrent.atomic.AtomicReference<IClock> atomic,
IClock newClock)
Sets an atomic clock reference to the maximum of its current value and
a new value. |
static int |
byteArrayToInt(byte[] bytes)
|
static int |
byteArrayToInt(byte[] bytes,
int offset)
|
static java.lang.String |
bytesToHex(byte... bytes)
|
static
|
classForName(java.lang.String classname,
java.lang.String readable)
|
static int |
compareByteArrays(byte[] bytes1,
byte[] bytes2)
|
static
|
construct(java.lang.String classname,
java.lang.String readable)
Constructs an instance of the given class, which must have a no-arg constructor. |
static java.lang.String |
decodeToUTF8(byte[] bytes)
|
static void |
deserialize(org.apache.thrift.TDeserializer deserializer,
org.apache.thrift.TBase struct,
java.io.DataInput in)
|
static int |
encodedUTF8Length(java.lang.String st)
|
static org.apache.commons.collections.iterators.CollatingIterator |
getCollatingIterator()
|
static AbstractType |
getComparator(java.lang.String compareWith)
|
static java.net.InetAddress |
getLocalAddress()
|
static java.lang.String |
getReleaseVersionString()
|
static java.util.TreeSet<byte[]> |
getSingleColumnSet(byte[] column)
|
static byte[] |
hash(java.lang.String type,
byte[]... data)
|
static byte[] |
hexToBytes(java.lang.String str)
|
static java.math.BigInteger |
md5hash(byte[] data)
|
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 IPartitioner |
newPartitioner(java.lang.String partitionerClassName)
|
static double |
parseDoubleOrPercent(java.lang.String value)
Parses a string representing either a fraction, absolute value or percentage. |
static byte[] |
readByteArray(java.io.DataInput in)
|
static byte[] |
readShortByteArray(java.io.DataInput in)
|
static void |
renameWithConfirm(java.lang.String tmpFilename,
java.lang.String filename)
|
static java.lang.String |
resourceToFile(java.lang.String filename)
|
static void |
serialize(org.apache.thrift.TSerializer serializer,
org.apache.thrift.TBase struct,
java.io.DataOutput out)
|
static void |
sortSampledKeys(java.util.List<DecoratedKey> keys,
Range range)
|
static long |
timestampMicros()
|
static byte[] |
toByteArray(int i)
|
static byte[] |
toByteArray(long n)
|
static void |
tryMlockall()
|
static void |
waitOnFutures(java.util.Collection<java.util.concurrent.Future<?>> futures)
|
static void |
writeByteArray(byte[] bytes,
java.io.DataOutput out)
|
static void |
writeShortByteArray(byte[] name,
java.io.DataOutput out)
|
static byte[] |
xor(byte[] left,
byte[] right)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TWO
public static final java.math.BigInteger TWO
MAX_UNSIGNED_SHORT
public static final int MAX_UNSIGNED_SHORT
- See Also:
- Constant Field Values
byteArrayComparator
public static final java.util.Comparator<byte[]> byteArrayComparator
FBUtilities
public FBUtilities()
parseDoubleOrPercent
public static double parseDoubleOrPercent(java.lang.String value)
- Parses a string representing either a fraction, absolute value or percentage.
getLocalAddress
public static java.net.InetAddress getLocalAddress()
absoluteFromFraction
public static long absoluteFromFraction(double fractOrAbs,
long total)
- Parameters:
fractOrAbs
- A double that may represent a fraction or absolute value.total
- If fractionOrAbs is a fraction, the total to take the fraction from
- Returns:
- An absolute value which may be larger than the total.
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.
toByteArray
public static byte[] toByteArray(int i)
byteArrayToInt
public static int byteArrayToInt(byte[] bytes)
byteArrayToInt
public static int byteArrayToInt(byte[] bytes,
int offset)
compareByteArrays
public static int compareByteArrays(byte[] bytes1,
byte[] bytes2)
xor
public static byte[] xor(byte[] left,
byte[] right)
- Returns:
- The bitwise XOR of the inputs. The output will be the same length as the
longer input, but if either input is null, the output will be null.
md5hash
public static java.math.BigInteger md5hash(byte[] data)
hash
public static byte[] hash(java.lang.String type,
byte[]... data)
writeByteArray
public static void writeByteArray(byte[] bytes,
java.io.DataOutput out)
throws java.io.IOException
- Throws:
java.io.IOException
readByteArray
public static byte[] readByteArray(java.io.DataInput in)
throws java.io.IOException
- Throws:
java.io.IOException
writeShortByteArray
public static void writeShortByteArray(byte[] name,
java.io.DataOutput out)
readShortByteArray
public static byte[] readShortByteArray(java.io.DataInput in)
throws java.io.IOException
- Throws:
java.io.IOException
hexToBytes
public static byte[] hexToBytes(java.lang.String str)
bytesToHex
public static java.lang.String bytesToHex(byte... bytes)
renameWithConfirm
public static void renameWithConfirm(java.lang.String tmpFilename,
java.lang.String filename)
throws java.io.IOException
- Throws:
java.io.IOException
getCollatingIterator
public static org.apache.commons.collections.iterators.CollatingIterator getCollatingIterator()
atomicSetMax
public static void atomicSetMax(java.util.concurrent.atomic.AtomicInteger atomic,
int i)
atomicSetMax
public static void atomicSetMax(java.util.concurrent.atomic.AtomicLong atomic,
long i)
atomicSetMax
public static void atomicSetMax(java.util.concurrent.atomic.AtomicReference<IClock> atomic,
IClock newClock)
- Sets an atomic clock reference to the maximum of its current value and
a new value.
The function is not synchronized and does not guarantee that the resulting
reference will hold either the old or new value, but it does guarantee
that it will hold a value, v, such that: v = max(oldValue, newValue, v).
- Parameters:
atomic
- the atomic reference to setnewClock
- the new provided value
serialize
public static void serialize(org.apache.thrift.TSerializer serializer,
org.apache.thrift.TBase struct,
java.io.DataOutput out)
throws java.io.IOException
- Throws:
java.io.IOException
deserialize
public static void deserialize(org.apache.thrift.TDeserializer deserializer,
org.apache.thrift.TBase struct,
java.io.DataInput in)
throws java.io.IOException
- Throws:
java.io.IOException
sortSampledKeys
public static void sortSampledKeys(java.util.List<DecoratedKey> keys,
Range range)
encodedUTF8Length
public static int encodedUTF8Length(java.lang.String st)
decodeToUTF8
public static java.lang.String decodeToUTF8(byte[] bytes)
throws java.nio.charset.CharacterCodingException
- Throws:
java.nio.charset.CharacterCodingException
toByteArray
public static byte[] toByteArray(long n)
resourceToFile
public static java.lang.String resourceToFile(java.lang.String filename)
throws ConfigurationException
- Throws:
ConfigurationException
getReleaseVersionString
public static java.lang.String getReleaseVersionString()
timestampMicros
public static long timestampMicros()
waitOnFutures
public static void waitOnFutures(java.util.Collection<java.util.concurrent.Future<?>> futures)
newPartitioner
public static IPartitioner newPartitioner(java.lang.String partitionerClassName)
throws ConfigurationException
- Throws:
ConfigurationException
getComparator
public static AbstractType getComparator(java.lang.String compareWith)
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.
construct
public static <T> T construct(java.lang.String classname,
java.lang.String readable)
throws ConfigurationException
- Constructs an instance of the given class, which must have a no-arg constructor.
TODO: Similar method for our 'instance member' singleton pattern would be nice.
- Parameters:
classname
- Fully qualified classname.readable
- Descriptive noun for the role the class plays.
- Throws:
ConfigurationException
- If the class cannot be found.
tryMlockall
public static void tryMlockall()
getSingleColumnSet
public static java.util.TreeSet<byte[]> getSingleColumnSet(byte[] column)
Copyright © 2010 The Apache Software Foundation