public final class Util
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static byte[] |
EMPTY_BYTE_ARRAY |
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY |
(package private) static java.lang.String |
HEX_VALUES |
private static java.lang.String |
INDENT |
private static boolean |
IS_ARRAYS_DEBUG |
private static java.lang.String |
javaVendor
Current Java vendor.
|
private static Log |
log |
Modifier | Constructor and Description |
---|---|
private |
Util()
Prevent instantiation
|
Modifier and Type | Method and Description |
---|---|
private static void |
addHexByte(java.lang.StringBuilder buf,
byte b) |
static <T> java.util.Set<T> |
asSet(T... a) |
static <T> T |
cloneWithMarshaller(Marshaller marshaller,
T x)
Clones parameter x of type T with a given Marshaller reference;
|
static void |
close(java.io.Closeable... cls) |
static void |
close(java.io.Closeable cl) |
static void |
close(javax.naming.Context ctx) |
static void |
close(java.net.Socket s) |
static java.lang.Double |
constructDouble(java.lang.Class<?> type,
java.lang.Object o) |
static long |
currentMillisFromNanotime()
System.nanoTime() is less expensive than System.currentTimeMillis() and better suited
to measure time intervals. |
private static void |
dumpThreadInfo(java.lang.StringBuilder threadDump,
boolean withLocks,
java.lang.management.ThreadMXBean threadMx) |
static int |
findNextHighestPowerOfTwo(int num)
Returns a number such that the number is a power of two that is equal to, or greater than, the number passed in as
an argument.
|
static void |
flushAndCloseOutput(java.io.ObjectOutput o) |
static void |
flushAndCloseStream(java.io.OutputStream o) |
static java.lang.String |
formatString(java.lang.Object message,
java.lang.Object... params) |
static java.lang.ClassLoader[] |
getClassLoaders(java.lang.ClassLoader appClassLoader) |
private static java.lang.reflect.Method |
getFactoryMethod(java.lang.Class<?> c) |
static <T> T |
getInstance(java.lang.Class<T> clazz)
Instantiates a class by first attempting a static factory method named getInstance() on the class
and then falling back to an empty constructor.
|
static <T> T |
getInstance(java.lang.String classname,
java.lang.ClassLoader cl)
Instantiates a class based on the class name provided.
|
static <T> T |
getInstanceStrict(java.lang.Class<T> clazz)
Similar to
getInstance(Class) except that exceptions are propagated to the caller. |
static <T> T |
getInstanceStrict(java.lang.String classname,
java.lang.ClassLoader cl)
Similar to
getInstance(String, ClassLoader) except that exceptions are propagated to the caller. |
static int |
getNormalizedHash(java.lang.Object object,
Hash hashFct)
Applies the given hash function to the hash code of a given object, and then normalizes it to ensure a positive
value is always returned.
|
static int |
getSegmentSize(int numSegments)
Returns the size of each segment, given a number of segments.
|
static int |
hashCode(byte[] bytes,
int size)
A function that calculates hash code of a byte array based on its
contents but using the given size parameter as deliminator for the
content.
|
static java.lang.String |
hexDump(byte[] buffer) |
static java.lang.String |
hexDump(java.nio.ByteBuffer buffer) |
static java.lang.String |
hexIdHashCode(java.lang.Object o)
Prints the identity hash code of the object passed as parameter
in an hexadecimal format in order to safe space.
|
static boolean |
isIBMJavaVendor() |
static boolean |
isOSGiContext()
Tries to determine if the code is running in an OSGi context.
|
static java.lang.String |
join(java.util.List<java.lang.String> strings,
java.lang.String separator) |
static <T> java.lang.Class<T> |
loadClass(java.lang.String classname,
java.lang.ClassLoader cl)
Loads the specified class using the passed classloader, or, if it is
null the Infinispan classes'
classloader. |
static <T> java.lang.Class<T> |
loadClassStrict(java.lang.String classname,
java.lang.ClassLoader userClassLoader)
Loads the specified class using the passed classloader, or, if it is
null the Infinispan classes' classloader. |
static java.lang.String |
padString(java.lang.String s,
int minWidth) |
static java.lang.String |
prettyPrintTime(long millis)
Prints a time for display
|
static java.lang.String |
prettyPrintTime(long time,
java.util.concurrent.TimeUnit unit) |
static java.lang.String |
printArray(byte[] array,
boolean withHash) |
private static void |
printLockInfo(java.lang.management.LockInfo[] locks,
java.lang.StringBuilder threadDump) |
private static void |
printThread(java.lang.management.ThreadInfo threadInfo,
java.lang.StringBuilder threadDump) |
private static void |
printThreadInfo(java.lang.management.ThreadInfo threadInfo,
java.lang.StringBuilder threadDump) |
static byte[] |
readStream(java.io.InputStream is)
Reads the given InputStream fully, closes the stream and returns the result as a byte array.
|
static CacheException |
rewrapAsCacheException(java.lang.Throwable t) |
static boolean |
safeEquals(java.lang.Object a,
java.lang.Object b)
Null-safe equality test.
|
static java.lang.String |
threadDump() |
static java.lang.String |
toHexString(byte[] input) |
static java.lang.String |
toHexString(byte[] input,
int limit) |
static <E> java.lang.String |
toStr(java.util.Collection<E> collection) |
static java.lang.String |
toStr(java.lang.Object o) |
private static final boolean IS_ARRAYS_DEBUG
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
private static final Log log
private static final java.lang.String javaVendor
private static java.lang.String INDENT
static final java.lang.String HEX_VALUES
public static <T> java.lang.Class<T> loadClass(java.lang.String classname, java.lang.ClassLoader cl)
Loads the specified class using the passed classloader, or, if it is null
the Infinispan classes'
classloader.
If loadtime instrumentation via GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap classloader.
If the class is not found, the ClassNotFoundException
or NoClassDefFoundError
is wrapped as a
CacheConfigurationException
and is re-thrown.
classname
- name of the class to loadcl
- the application classloader which should be used to load the class, or null if the class is always packaged with
InfinispanCacheConfigurationException
- if the class cannot be loadedpublic static boolean isOSGiContext()
public static java.lang.ClassLoader[] getClassLoaders(java.lang.ClassLoader appClassLoader)
public static <T> java.lang.Class<T> loadClassStrict(java.lang.String classname, java.lang.ClassLoader userClassLoader) throws java.lang.ClassNotFoundException
Loads the specified class using the passed classloader, or, if it is null
the Infinispan classes' classloader.
If loadtime instrumentation via GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap classloader.
classname
- name of the class to loaduserClassLoader
- the application classloader which should be used to load the class, or null if the class is always packaged with
Infinispanjava.lang.ClassNotFoundException
- if the class cannot be loadedprivate static java.lang.reflect.Method getFactoryMethod(java.lang.Class<?> c)
public static <T> T getInstance(java.lang.Class<T> clazz)
CacheConfigurationException
and rethrown.clazz
- class to instantiatepublic static <T> T getInstanceStrict(java.lang.Class<T> clazz) throws java.lang.IllegalAccessException, java.lang.InstantiationException
getInstance(Class)
except that exceptions are propagated to the caller.clazz
- class to instantiatejava.lang.IllegalAccessException
java.lang.InstantiationException
public static <T> T getInstance(java.lang.String classname, java.lang.ClassLoader cl)
CacheConfigurationException
.classname
- class to instantiatepublic static <T> T getInstanceStrict(java.lang.String classname, java.lang.ClassLoader cl) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
getInstance(String, ClassLoader)
except that exceptions are propagated to the caller.classname
- class to instantiatejava.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
public static <T> T cloneWithMarshaller(Marshaller marshaller, T x)
public static boolean safeEquals(java.lang.Object a, java.lang.Object b)
a
- first object to compareb
- second object to comparepublic static java.lang.String prettyPrintTime(long time, java.util.concurrent.TimeUnit unit)
public static final long currentMillisFromNanotime()
System.nanoTime()
is less expensive than System.currentTimeMillis()
and better suited
to measure time intervals. It's NOT suited to know the current time, for example to be compared
with the time of other nodes.System.nanoTime()
, but converted in Milliseconds.public static java.lang.String prettyPrintTime(long millis)
millis
- time in millispublic static byte[] readStream(java.io.InputStream is) throws java.io.IOException
is
- the stream to readjava.io.IOException
- in case of stream read errorspublic static void close(java.io.Closeable cl)
public static void close(java.net.Socket s)
public static void close(java.io.Closeable... cls)
public static void close(javax.naming.Context ctx)
public static void flushAndCloseStream(java.io.OutputStream o)
public static void flushAndCloseOutput(java.io.ObjectOutput o)
public static java.lang.String formatString(java.lang.Object message, java.lang.Object... params)
public static java.lang.String toStr(java.lang.Object o)
public static <E> java.lang.String toStr(java.util.Collection<E> collection)
public static java.lang.String printArray(byte[] array, boolean withHash)
public static java.lang.String toHexString(byte[] input)
public static java.lang.String toHexString(byte[] input, int limit)
public static java.lang.String padString(java.lang.String s, int minWidth)
public static java.lang.String threadDump()
private static void dumpThreadInfo(java.lang.StringBuilder threadDump, boolean withLocks, java.lang.management.ThreadMXBean threadMx)
private static void printThreadInfo(java.lang.management.ThreadInfo threadInfo, java.lang.StringBuilder threadDump)
private static void printLockInfo(java.lang.management.LockInfo[] locks, java.lang.StringBuilder threadDump)
private static void printThread(java.lang.management.ThreadInfo threadInfo, java.lang.StringBuilder threadDump)
public static CacheException rewrapAsCacheException(java.lang.Throwable t)
public static <T> java.util.Set<T> asSet(T... a)
public static java.lang.String hexIdHashCode(java.lang.Object o)
public static java.lang.String hexDump(byte[] buffer)
public static java.lang.String hexDump(java.nio.ByteBuffer buffer)
private static void addHexByte(java.lang.StringBuilder buf, byte b)
public static java.lang.Double constructDouble(java.lang.Class<?> type, java.lang.Object o)
public static int getNormalizedHash(java.lang.Object object, Hash hashFct)
object
- to hashhashFct
- hash function to applypublic static int getSegmentSize(int numSegments)
numSegments
- number of segments requiredpublic static boolean isIBMJavaVendor()
public static java.lang.String join(java.util.List<java.lang.String> strings, java.lang.String separator)
public static int findNextHighestPowerOfTwo(int num)
public static int hashCode(byte[] bytes, int size)