| Modifier and Type | Field and Description |
|---|---|
static List<String> |
DFLT_HELP_LINKS
Default help pages.
|
static String |
DFLT_USER_VERSION
Default user version.
|
static byte[] |
GG_HEADER
Network packet header.
|
static byte |
JDK_CLIENT_PROTO_ID
JDK client marshaller ID.
|
static String |
JMX_DOMAIN
JMX domain as 'xxx.gridgain'.
|
static String |
MAC_INVALID_ARG_MSG
MAC OS invalid argument socket error message.
|
static byte |
OPTIMIZED_CLIENT_PROTO_ID
Optimized client marshaller ID.
|
static byte |
PROTOBUF_CLIENT_PROTO_ID
Protobuf client marshaller ID.
|
| Constructor and Description |
|---|
GridUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
acquire(Semaphore sem)
Acquires a permit from provided semaphore.
|
static <V,C extends Collection<? super V>> |
addAll(C c,
V... vals)
Adds values to collection and returns the same collection to allow chaining.
|
static <K,V,M extends Map<K,V>> |
addAll(M m,
GridBiTuple<K,V>... entries)
Adds values to collection and returns the same collection to allow chaining.
|
static <K,V,M extends Map<K,V>> |
addAll(M m,
Map.Entry<K,V>... entries)
Adds values to collection and returns the same collection to allow chaining.
|
static Collection<Handler> |
addJavaNoOpLogger()
Adds no-op console handler for root java logger.
|
static boolean |
addLastCause(Throwable e,
Throwable cause,
GridLogger log)
Adds cause to the end of cause chain.
|
static GridBiTuple<Object,Object> |
addLog4jNoOpLogger()
Adds no-op logger to remove no-appender warning.
|
static String |
addressesAsString(Collection<String> addrs,
Collection<String> hostNames)
Returns string representation of addresses.
|
static String |
addressesAsString(GridNode node)
Returns string representation of node addresses.
|
static Collection<String> |
allLocalIps()
Gets a list of all local non-loopback IPs known to this JVM.
|
static Collection<String> |
allLocalMACs()
Gets a list of all local enabled MACs known to this JVM.
|
static int |
arrayCopy(byte[] src,
int off,
byte[] resBuf,
int resOff,
int len) |
static <T> Iterable<T> |
asIterable(Enumeration<T> e)
Converts enumeration to iterable so it can be used in
foreach construct. |
static void |
asyncLogError(GridFuture<?> f,
GridLogger log)
Adds listener to asynchronously log errors.
|
static GridCacheAtomicityMode |
atomicityMode(GridNode n,
String cacheName)
Gets cache mode or a cache on given node or
null if cache is not
present on given node. |
static void |
await(Condition cond)
Awaits for condition.
|
static boolean |
await(Condition cond,
long time,
TimeUnit unit)
Awaits for condition.
|
static void |
await(CountDownLatch latch)
Awaits for the latch.
|
static boolean |
await(CountDownLatch latch,
long timeout,
TimeUnit unit)
Awaits for the latch.
|
static void |
awaitQuiet(CountDownLatch latch)
Awaits for the latch until it is counted down,
ignoring interruptions.
|
static void |
awaitQuiet(CyclicBarrier barrier)
Awaits for the barrier ignoring interruptions.
|
static Class<?> |
box(Class<?> cls)
Gets wrapper class for a primitive type.
|
static String |
byteArray2HexString(byte[] arr)
Converts byte array to hex string.
|
static String |
byteArray2String(byte[] arr,
String hdrFmt,
String bodyFmt)
Converts byte array to formatted string.
|
static boolean |
bytesEqual(byte[] a,
int aOff,
byte[] b,
int bOff,
int len)
Compares fragments of byte arrays.
|
static double |
bytesToDouble(byte[] bytes,
int off)
Constructs double from byte array.
|
static float |
bytesToFloat(byte[] bytes,
int off)
Constructs float from byte array.
|
static GridUuid |
bytesToGridUuid(byte[] in,
int off)
Converts bytes to GridUuid.
|
static int |
bytesToInt(byte[] bytes,
int off)
Constructs
int from byte array. |
static long |
bytesToLong(byte[] bytes,
int off)
Constructs
long from byte array. |
static short |
bytesToShort(byte[] bytes,
int off)
Constructs
short from byte array. |
static UUID |
bytesToUuid(byte[] bytes,
int off)
Reads an
UUID form byte array. |
static GridCacheAttributes[] |
cacheAttributes(GridNode n)
Gets cache attributes for the node.
|
static GridCacheAttributes |
cacheAttributes(GridNode n,
String cacheName)
Gets cache attributes from the given node for the given cache name.
|
static GridCacheMode |
cacheMode(GridNode n,
String cacheName)
Gets cache mode or a cache on given node or
null if cache is not
present on given node. |
static Collection<String> |
cacheNames(GridNode n)
Gets view on all cache names started on the node.
|
static void |
cancel(GridWorker w)
Cancels given runnable.
|
static void |
cancel(Iterable<? extends GridWorker> ws)
Cancels collection of runnables.
|
static GridException |
cast(Throwable t)
Casts this throwable as
GridException. |
static int |
ceilPow2(int v)
Gets nearest power of 2 larger or equal than v.
|
static String |
classNameToResourceName(String clsName)
Gets resource path for the class.
|
static void |
close(AbstractInterruptibleChannel rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(Closeable rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(Connection rsrc,
GridLogger log)
Closes JDBC connection logging possible checked exception.
|
static void |
close(Context rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(DatagramSocket rsrc)
Closes given resource.
|
static void |
close(Reader rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(ResultSet rsrc,
GridLogger log)
Closes JDBC result set logging possible checked exception.
|
static void |
close(SelectionKey rsrc,
GridLogger log)
Closes given resource logging possible checked exceptions.
|
static void |
close(Selector rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(ServerSocket rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(Socket rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
close(Statement rsrc,
GridLogger log)
Closes JDBC statement logging possible checked exception.
|
static void |
close(URLClassLoader clsLdr,
GridLogger log)
Closes class loader logging possible checked exception.
|
static void |
close(ZipFile rsrc,
GridLogger log)
Closes given resource logging possible checked exception.
|
static void |
closeQuiet(AbstractInterruptibleChannel rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(Closeable rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(Connection rsrc)
Quietly closes JDBC connection ignoring possible checked exception.
|
static void |
closeQuiet(Context rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(Reader rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(ResultSet rsrc)
Quietly closes JDBC result set ignoring possible checked exception.
|
static void |
closeQuiet(SelectionKey rsrc)
Quietly closes given resource ignoring possible checked exceptions.
|
static void |
closeQuiet(Selector rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(ServerSocket rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(Socket rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(Statement rsrc)
Quietly closes JDBC statement ignoring possible checked exception.
|
static void |
closeQuiet(Writer rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static void |
closeQuiet(ZipFile rsrc)
Quietly closes given resource ignoring possible checked exception.
|
static String |
compact(String s)
Replaces all occurrences of
org.gridgain. with o.g.,
org.gridgain.grid. with o.g.g., org.gridgain.visor. with o.g.v. and
org.gridgain.scalar. with o.g.s.. |
static int |
compareVersionNumbers(String v1,
String v2)
Compare java implementation version
|
static int |
concurrentMapSegment(int hash,
int concurLvl) |
static String |
consistentId(Collection<String> addrs,
int port) |
static boolean |
containsAll(Map<?,?> base,
Map<?,?> map)
Checks if the map passed in is contained in base map.
|
static boolean |
containsIntArray(int[] arr,
int val)
Checks for containment of the value in the array.
|
static boolean |
containsObjectArray(Object[] arr,
Collection<Object> c)
Checks for containment of the value in the array.
|
static boolean |
containsObjectArray(Object[] arr,
Object val,
Object... vals)
Checks for containment of the value in the array.
|
static boolean |
containsRegexArray(String[] arr,
String regex)
Checks for containment of value matching given regular expression in the provided array.
|
static boolean |
containsStringArray(String[] arr,
String val,
boolean ignoreCase)
Checks for containment of given string value in the specified array.
|
static boolean |
containsStringCollection(Iterable<String> c,
String val,
boolean ignoreCase)
Checks for containment of given string value in the specified collection.
|
static void |
copy(File src,
File dest,
boolean overwrite)
Copy source file (or folder) to destination file (or folder).
|
static int |
copy(InputStream in,
OutputStream out)
Copies input byte stream to output byte stream.
|
static int |
copy(Reader in,
Writer out)
Copies input character stream to output character stream.
|
static int[] |
copyIfExceeded(int[] arr,
int len)
Copies array only if array length greater than needed length.
|
static <K,V> Map<K,V> |
copyMap(Map<K,V> m) |
static void |
courtesy(GridLogger log,
Object msg)
Depending on whether or not log is provided and quiet mode is enabled logs given messages as
quiet message or normal log WARN message in
org.gridgain.grid.CourtesyConfigNotice
category. |
static void |
courtesy(GridLogger log,
Object longMsg,
Object shortMsg)
Depending on whether or not log is provided and quiet mode is enabled logs given messages as
quiet message or normal log WARN message in
org.gridgain.grid.CourtesyConfigNotice
category. |
static GridClientMarshaller |
createProtobufMarshaller(GridLogger log)
Creates new instance of Protobuf marshaller.
|
static Method |
ctorFactory()
Return SUN specific constructor factory.
|
static long |
currentTimeMillis() |
static String |
customDirectoryLogFileName(String dir,
String fileName)
Substitutes log directory with a custom one.
|
static String |
dash(int len)
Makes a
'+---+' dash line. |
static void |
debug(GridLogger log,
String msg)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
debug(Object msg)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
debugHeapUsage()
Prints heap usage.
|
static void |
debugStack(GridLogger log,
String msg)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
debugx(String msg)
Deprecated.
Calls to this method should never be committed to master.
|
static byte[] |
decodeHex(char[] data)
Converts an array of characters representing hexidecimal values into an
array of bytes of those same values.
|
static boolean |
delete(File file)
Deletes file or directory with all sub-directories and files.
|
static Class<?> |
detectClass(Object obj)
Tries to detect user class from passed in object inspecting
collections, arrays or maps.
|
static ClassLoader |
detectClassLoader(Class<?> cls)
Detects class loader for given class.
|
static ClassLoader |
detectObjectClassLoader(Object obj)
Detects class loader for given object's class.
|
static GridPeerDeployAware |
detectPeerDeployAware(GridPeerDeployAware obj)
Unwraps top level user class for wrapped objects.
|
static int[] |
difference(int[] a,
int aLen,
int[] b,
int bLen)
Returns array which is the difference between two arrays
(array of elements contained in first array but not contained in second).
|
static boolean |
discoOrdered(GridDiscoverySpi discoSpi) |
static byte[] |
doubleToBytes(double d)
Converts primitive double to byte array.
|
static int |
doubleToBytes(double d,
byte[] bytes,
int off)
Converts primitive
double type to byte array and stores
it in the specified byte array. |
static File |
downloadUrl(URL url,
File file)
Downloads resource by URL.
|
static void |
dumpStack()
Deprecated.
Calls to this method should never be committed to master.
|
static void |
dumpStack(GridLogger log,
String msg) |
static void |
dumpStack(String msg)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
dumpStack(String msg,
PrintStream out)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
dumpStack(Thread t)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
dumpStack(Thread t,
PrintStream s)
Deprecated.
Calls to this method should never be committed to master.
|
static void |
dumpThreads(GridLogger log)
Performs thread dump and prints all available info to the given log.
|
static GridEmptyProjectionException |
emptyTopologyException()
Creates appropriate empty projection exception.
|
static void |
error(GridLogger log,
Object msg)
Depending on whether or not log is provided and quiet mode is enabled logs given
messages as quiet message or normal log ERROR message.
|
static void |
error(GridLogger log,
Object longMsg,
Object shortMsg,
Throwable e)
Depending on whether or not log is provided and quiet mode is enabled logs given
messages as quiet message or normal log ERROR message.
|
static void |
error(GridLogger log,
Object shortMsg,
Throwable e)
Shortcut for
error(GridLogger, Object, Object, Throwable). |
static String |
errorMessageWithHelpUrls(String msg)
Checks if exception has help URLs.
|
static GridException |
exceptionWithSuppressed(String msg,
Collection<Throwable> suppressed)
Creates
GridException with the collection of suppressed exceptions. |
static <T> T |
field(Class<?> cls,
String fieldName)
Gets field value.
|
static <T> T |
field(Object obj,
String fieldName)
Gets field value.
|
static String |
filler(int len,
char ch) |
static <T> T |
firstNotNull(T... vals)
Returns a first non-null value in a given array, if such is present.
|
static String |
fl(String msg,
Object... args)
Creates string for log output.
|
static byte[] |
floatToBytes(float f)
Converts primitive float to byte array.
|
static int |
floatToBytes(float f,
byte[] bytes,
int off)
Converts primitive float to byte array.
|
static Constructor<?> |
forceEmptyConstructor(Class<?> cls)
Gets empty constructor for class even if the class does not have empty constructor
declared.
|
static <T> T |
forceNewInstance(Class<?> cls)
Creates new instance of a class even if it does not have public constructor.
|
static String |
format(Date date,
String ptrn)
Formats passed date with specified pattern.
|
static String |
format(long sysTime)
Formats system time in milliseconds for printing in logs.
|
static String |
formatMins(long mins)
Pretty-formatting for minutes.
|
static Class<?> |
forName(String clsName,
ClassLoader ldr)
Gets class for provided name.
|
static <T> T |
get(Future<T> fut)
Gets result from the given future with right exception handling.
|
static <T extends Annotation> |
getAnnotation(Class<?> cls,
Class<T> annCls)
Gets annotation for a class.
|
static boolean |
getBoolean(String name)
Gets boolean system or environment property.
|
static <T> T |
getByIndex(Collection<T> vals,
int idx)
Gets collection value by index.
|
static CompilationMXBean |
getCompilerMx()
Gets compilation MBean.
|
static String |
getGridGainHome()
Retrieves
GRIDGAIN_HOME property. |
static InetAddress |
getLocalHost()
Gets local host.
|
static MemoryMXBean |
getMemoryMx()
Gets memory MBean.
|
static String |
getNetworkInterfaceName(String addr)
Gets display name of the network interface this IP address belongs to.
|
static OperatingSystemMXBean |
getOsMx()
Gets OS MBean.
|
static RuntimeMXBean |
getRuntimeMx()
Gets runtime MBean.
|
static String |
getSimpleName(Class<?> cls)
Gets simple class name taking care of empty names.
|
static String |
getTaskName(Class<? extends GridComputeTask<?,?>> taskCls)
Gets task name for the given task class.
|
static ThreadMXBean |
getThreadMx()
Gets threading MBean.
|
static ClassLoader |
gridClassLoader() |
static String |
gridEventName(int type)
Gets name for given grid event type.
|
static int[] |
gridEvents(int... excl)
Gets all event types.
|
static Collection<UUID> |
gridIds(Collection<? extends Grid> grids)
Converts collection of Grid instances to collection of node IDs.
|
static Collection<String> |
grids2names(Collection<? extends Grid> grids)
Converts collection of Grid instances to collection of grid names.
|
static void |
gridUuidToBytes(GridUuid uuid,
byte[] out,
int off)
Converts GridUuid to bytes.
|
static <T extends Annotation> |
hasAnnotation(Class<?> cls,
Class<T> annCls)
Indicates if class has given annotation.
|
static <T extends Annotation> |
hasAnnotation(Object o,
Class<T> annCls)
Indicates if class has given annotation.
|
static boolean |
hasCache(GridNode n,
String cacheName)
Checks if given node has specified cache started.
|
static int |
hash(int h)
Applies a supplemental hash function to a given hashCode, which
defends against poor quality hash functions.
|
static int |
hash(Object key)
Applies a supplemental hash function to a given hashCode, which
defends against poor quality hash functions.
|
static int |
hashCode(ByteBuffer... bufs)
Calculates hash code for the given byte buffers contents.
|
static boolean |
hasNearCache(GridNode n,
String cacheName)
Checks if given node has near cache enabled for the specified
partitioned cache.
|
static boolean |
hasParent(ClassLoader parent,
ClassLoader ldr) |
static boolean |
hasStreamer(GridNode n,
String streamerName)
Checks if given node has specified streamer started.
|
static double |
heapSize(GridNode node,
int precision)
Gets heap size in GB rounded to specified precision.
|
static double |
heapSize(int precision)
Returns current JVM maxMemory in the same format as
heapSize(GridNode, int). |
static double |
heapSize(Iterable<GridNode> nodes,
int precision)
Gets total heap size in GB rounded to specified precision.
|
static byte[] |
hexString2ByteArray(String hex)
Convert string with hex values to byte array.
|
static String |
hidePassword(String uri)
Replace password in URI string with a single '*' character.
|
static GridClosure<UUID,GridNode> |
id2Node(GridKernalContext ctx) |
static String |
id8(GridUuid id)
Gets 8-character substring of
GridUuid (for terse logging). |
static String |
id8(UUID id)
Gets 8-character substring of UUID (for terse logging).
|
static void |
interrupt(Iterable<? extends Thread> workers)
Convenience method that interrupts a given thread if it's not
null. |
static void |
interrupt(Thread t)
Convenience method that interrupts a given thread if it's not
null. |
static byte[] |
intToBytes(int i)
Converts primitive
int type to byte array. |
static int |
intToBytes(int i,
byte[] bytes,
int off)
Converts primitive
int type to byte array and stores it in specified
byte array. |
static <T> T |
invoke(Class<?> cls,
Object obj,
String mtdName,
Class[] paramTypes,
Object... params)
Invokes method.
|
static boolean |
isFutureNotificationConcurrent(String dflt) |
static boolean |
isFutureNotificationSynchronous(String dflt) |
static boolean |
isGrid(Class<?> cls)
Checks if given class is of
Grid type. |
static boolean |
isGridGain(Class<?> cls)
Checks if given class is of
GridGain type. |
static boolean |
isHotSpot()
Indicates whether HotSpot VM is used.
|
static boolean |
isIncreasingArray(int[] arr,
int len)
Checks if array prefix increases.
|
static boolean |
isJavaVersionAtLeast(String v)
Compare running Java Runtime version with
v |
static boolean |
isJdk(Class<?> cls)
Check if given class is of JDK type.
|
static boolean |
isLinux()
Indicates whether current OS is Linux flavor.
|
static boolean |
isLoadableBy(String clsName,
ClassLoader ldr)
Tests whether or not given class is loadable provided class loader.
|
static boolean |
isLocalHostChanged()
Determines whether current local host is different from previously cached.
|
static boolean |
isMacInvalidArgumentError(Exception e)
Checks if error is MAC invalid argument error which ususally requires special handling.
|
static boolean |
isMacOs()
Indicates whether current OS is Mac OS.
|
static boolean |
isNetWare()
Indicates whether current OS is Netware.
|
static boolean |
isNonDecreasingArray(int[] arr,
int len)
Checks if array prefix do not decreases.
|
static boolean |
isPow2(int i) |
static boolean |
isPrimitiveArray(Object obj)
Checks if object is a primitive array.
|
static boolean |
isPrimitiveOrWrapper(Class<?> cls) |
static boolean |
isSolaris()
Indicates whether current OS is Solaris.
|
static boolean |
isSolarisSparc()
Indicates whether current OS is Solaris on Spark box.
|
static boolean |
isSolarisX86()
Indicates whether current OS is Solaris on x86 box.
|
static boolean |
isSufficientlyTestedOs()
Indicates that GridGain has been sufficiently tested on the current OS.
|
static boolean |
isUnix()
Indicates whether current OS is UNIX flavor.
|
static boolean |
isVisorNode(GridNode node)
Checks whether a node is a Visor node.
|
static boolean |
isVisorNodeStartProperty(String name)
Checks whether property is one added by Visor when node is started via remote SSH session.
|
static boolean |
isVisorRequiredProperty(String name)
Checks whether property is one required by Visor to work correctly.
|
static boolean |
isWindows()
Indicates whether current OS is Windows.
|
static boolean |
isWindows2003()
Indicates whether current OS is Windows Server 2003.
|
static boolean |
isWindows2008()
Indicates whether current OS is Windows Server 2008.
|
static boolean |
isWindows2k()
Indicates whether current OS is Windows 2000.
|
static boolean |
isWindows7()
Indicates whether current OS is Windows 7.
|
static boolean |
isWindows95()
Indicates whether current OS is Windows 95.
|
static boolean |
isWindows98()
Indicates whether current OS is Windows 98.
|
static boolean |
isWindowsNt()
Indicates whether current OS is Windows NT.
|
static boolean |
isWindowsVista()
Indicates whether current OS is Windows Vista.
|
static boolean |
isWindowsXp()
Indicates whether current OS is Windows XP.
|
static String |
jdkName()
Gets JDK name.
|
static String |
jdkString()
Gets JDK string.
|
static String |
jdkVendor()
Gets JDK vendor.
|
static String |
jdkVersion()
Gets JDK version.
|
static JMException |
jmException(Throwable e)
Utility method creating
JMException with given cause. |
static byte[] |
join(byte[]... bufs)
Join byte arrays into single one.
|
static void |
join(GridWorker w)
Joins worker.
|
static boolean |
join(GridWorker w,
GridLogger log)
Joins runnable.
|
static boolean |
join(Iterable<? extends GridWorker> ws,
GridLogger log)
Joins given collection of runnables.
|
static void |
join(Thread t)
Joins thread.
|
static boolean |
join(Thread t,
GridLogger log)
Waits for completion of a given thread.
|
static boolean |
joinThreads(Iterable<? extends Thread> workers,
GridLogger log)
Waits for completion of a given threads.
|
static String |
jreName()
Gets Java Runtime name.
|
static String |
jreVersion()
Gets Java Runtime version.
|
static List<String> |
jvmArgs() |
static String |
jvmName()
Gets JVM implementation name.
|
static int |
jvmPid() |
static String |
jvmSpec()
Gets JVM specification name.
|
static String |
jvmVendor()
Gets JVM implementation vendor.
|
static String |
jvmVersion()
Gets JVM implementation version.
|
static String |
lambdaEnclosingClassName(String clsName)
Extracts full name of enclosing class from JDK8 lambda class name.
|
static void |
log(GridLogger log,
Object msg)
Depending on whether or not log is provided and quiet mode is enabled logs given
messages as quiet message or normal log INF0 message.
|
static void |
log(GridLogger log,
Object longMsg,
Object shortMsg)
Depending on whether or not log is provided and quiet mode is enabled logs given
messages as quiet message or normal log INFO message.
|
static GridLogger |
logger(GridKernalContext ctx,
AtomicReference<GridLogger> logRef,
Class<?> cls)
Initializes logger into/from log reference passed in.
|
static GridLogger |
logger(GridKernalContext ctx,
AtomicReference<GridLogger> logRef,
Object obj)
Initializes logger into/from log reference passed in.
|
static byte[] |
longToBytes(long l)
Converts primitive
long type to byte array. |
static int |
longToBytes(long l,
byte[] bytes,
int off)
Converts primitive
long type to byte array and stores it in specified
byte array. |
static ObjectName |
makeCacheMBeanName(String gridName,
String cacheName,
String name)
Constructs JMX object name with given properties.
|
static ObjectName |
makeMBeanName(String gridName,
String grp,
String name)
Constructs JMX object name with given properties.
|
static String |
maskName(String cacheName)
Mask component name to make sure that it is not
null. |
static long |
microTime() |
static boolean |
mkdirs(File dir) |
static Map<String,Collection<GridNode>> |
neighborhood(Iterable<GridNode> nodes)
Groups given nodes by the node's physical computer (host).
|
static <T> T |
newInstance(Class<T> cls)
Creates new instance of a class only if it has an empty constructor (can be non-public).
|
static String |
nl() |
static String |
nodeIdLogFileName(UUID nodeId,
String fileName)
Attaches node ID to log file name.
|
static Collection<UUID> |
nodeIds(Collection<? extends GridNode> nodes)
Converts collection of nodes to collection of node IDs.
|
static Collection<String> |
nodes2names(Collection<? extends GridNode> nodes)
Converts collection of grid nodes to collection of grid names.
|
static Constructor |
objectConstructor() |
static String |
osArchitecture()
Gets OS CPU-architecture.
|
static String |
osJdkString()
Gets OS JDK string.
|
static String |
osName()
Gets underlying OS name.
|
static String |
osString()
Gets OS string.
|
static String |
osVersion()
Gets underlying OS version.
|
static boolean |
overridesEqualsAndHashCode(Object obj) |
static boolean |
p2pLoader(ClassLoader ldr)
Checks if class loader is an internal P2P class loader.
|
static boolean |
p2pLoader(Object o)
Checks if class loader is an internal P2P class loader.
|
static String |
pad(int len)
Creates space filled string of given length.
|
static Date |
parse(String src,
String ptrn)
Parses passed string with specified date.
|
static Calendar |
parseIsoDate(String str) |
static GridPeerDeployAware |
peerDeployAware(Object obj)
Creates an instance of
GridPeerDeployAware for object. |
static GridPeerDeployAware |
peerDeployAware0(Iterable<?> c)
Gets the peer deploy aware instance for the object with the widest class loader.
|
static GridPeerDeployAware |
peerDeployAware0(Object... c)
Gets the peer deploy aware instance for the object with the widest class loader.
|
static GridPeerDeployAware |
peerDeployAware0(Object obj)
Creates an instance of
GridPeerDeployAware for object. |
static <K,V> void |
printConcurrentHashMapInfo(ConcurrentHashMap<K,V> map) |
static GridProductVersion |
productVersion(GridNode node)
Gets node product version based on node attributes.
|
static <T> T |
property(Object obj,
String propName)
Gets property value.
|
static void |
quiet(boolean err,
Object... objs) |
static void |
quietAndInfo(GridLogger log,
String msg)
Prints out the message in quite and info modes.
|
static void |
quietAndWarn(GridLogger log,
Object msg)
Logs warning message in both verbose and quite modes.
|
static void |
quietAndWarn(GridLogger log,
Object msg,
Object shortMsg)
Logs warning message in both verbose and quite modes.
|
static <T> Iterable<T> |
randomIterable(Collection<T> col)
Takes given collection, shuffles it and returns iterable instance.
|
static boolean |
reachable(InetAddress addr,
int reachTimeout)
Checks if address can be reached using one argument InetAddress.isReachable() version.
|
static boolean |
reachable(NetworkInterface itf,
InetAddress addr,
int reachTimeout)
Checks if address can be reached using three argument InetAddress.isReachable() version.
|
static Object[] |
readArray(ObjectInput in)
Reads array from input stream.
|
static boolean[] |
readBooleanArray(DataInput in)
Reads boolean array from input stream accounting for null values.
|
static byte[] |
readByteArray(ByteBuffer... bufs)
Reads byte array from given buffers (changing buffer positions).
|
static byte[] |
readByteArray(DataInput in)
Reads byte array from input stream accounting for null values.
|
static List<Byte> |
readByteList(DataInput in)
// FIXME: added for DR dataCenterIds, review if it is needed after GG-6879.
|
static List<byte[]> |
readBytesList(DataInput in)
Reads collection of byte arrays from data input.
|
static <E> Collection<E> |
readCollection(ObjectInput in) |
static <K,V> GridPredicate<GridCacheEntry<K,V>>[] |
readEntryFilterArray(ObjectInput in)
Reads array from input stream.
|
static int |
readEnumOrdinal0(DataInput in)
Deprecated.
Need to remove when release will not be to support
backward compatible. Use
Enum.fromOrdinal(int). |
static String |
readFileToString(String fileName,
String charset)
Reads file to string using specified charset.
|
static GridUuid |
readGridUuid(DataInput in)
Reads
GridUuid from input stream. |
static List<GridUuid> |
readGridUuids(DataInput in)
Reads Grid UUIDs from input stream.
|
static Collection<Integer> |
readIntCollection(DataInput in) |
static Map<Integer,Integer> |
readIntKeyIntValueMap(DataInput in) |
static <V> Map<Integer,V> |
readIntKeyMap(ObjectInput in) |
static List<Integer> |
readIntList(DataInput in) |
static Set<Integer> |
readIntSet(DataInput in) |
static <K,V> LinkedHashMap<K,V> |
readLinkedMap(ObjectInput in) |
static <E> List<E> |
readList(ObjectInput in) |
static <K,V> Map<K,V> |
readMap(ObjectInput in) |
static <E> Set<E> |
readSet(ObjectInput in) |
static String |
readString(DataInput in)
Reads string from input stream accounting for
null values. |
static Map<String,String> |
readStringMap(DataInput in)
Reads string-to-string map written by
writeStringMap(DataOutput, Map). |
static <K,V> TreeMap<K,V> |
readTreeMap(ObjectInput in) |
static UUID |
readUuid(DataInput in)
Reads UUID from input stream.
|
static List<UUID> |
readUuids(DataInput in)
Reads UUIDs from input stream.
|
static <T> ObjectName |
registerCacheMBean(MBeanServer mbeanSrv,
String gridName,
String cacheName,
String name,
T impl,
Class<T> itf)
Registers MBean with the server.
|
static <T> ObjectName |
registerMBean(MBeanServer mbeanSrv,
ObjectName name,
T impl,
Class<T> itf)
Registers MBean with the server.
|
static <T> ObjectName |
registerMBean(MBeanServer mbeanSrv,
String gridName,
String grp,
String name,
T impl,
Class<T> itf)
Registers MBean with the server.
|
static boolean |
relaxDiscoveryOrdered() |
static void |
releaseQuiet(FileLock lock)
Quietly releases file lock ignoring all possible exceptions.
|
static void |
removeJavaNoOpLogger(Collection<Handler> rmvHnds)
Removes previously added no-op handler for root java logger.
|
static void |
removeLog4jNoOpLogger(GridBiTuple<Object,Object> t)
Removes previously added no-op logger via method
addLog4jNoOpLogger(). |
static Collection<InetSocketAddress> |
resolveAddresses(GridAddressResolver addrRslvr,
Iterable<String> addrs,
int port)
Resolves all not loopback addresses and collect results.
|
static File |
resolveGridGainPath(String path)
Gets file associated with path.
|
static URL |
resolveGridGainUrl(String path)
Gets URL representing the path passed in.
|
static URL |
resolveGridGainUrl(String path,
boolean metaInf)
Gets URL representing the path passed in.
|
static GridBiTuple<Collection<String>,Collection<String>> |
resolveLocalAddresses(InetAddress locAddr)
Returns host names consistent with
resolveLocalHost(String). |
static InetAddress |
resolveLocalHost(String hostName)
Tries to resolve host by name, returning local host if input is empty.
|
static File |
resolveWorkDirectory(String path,
boolean delIfExist)
Resolves work directory.
|
static void |
rollbackConnection(Connection rsrc,
GridLogger log)
Rollbacks JDBC connection logging possible checked exception.
|
static void |
rollbackConnectionQuiet(Connection rsrc)
Quietly rollbacks JDBC connection ignoring possible checked exception.
|
static int |
safeAbs(int i)
Gets absolute value for integer.
|
static boolean |
sameMacs(GridNode loc,
GridNode rmt) |
static <E> List<E> |
sealList(Collection<E> c)
Seal collection.
|
static <E> List<E> |
sealList(E... a)
Convert array to seal list.
|
static <K,V> Map<K,V> |
sealMap(Map<K,V> m) |
static boolean |
securityEnabled(GridConfiguration cfg)
Checks whether authentication SPI other than noop authentication SPI is configured.
|
static void |
setGridGainHome(String path) |
static void |
setWorkDirectory(String userWorkDir,
String userGgHome) |
static byte[] |
shortToBytes(short s)
Converts primitive
short type to byte array. |
static int |
shortToBytes(short s,
byte[] bytes,
int off)
Converts primitive
short type to byte array and stores it in specified
byte array. |
static void |
shutdownNow(Class<?> owner,
ExecutorService exec,
GridLogger log)
Shutdowns given
ExecutorService and wait for executor service to stop. |
static void |
sleep(long ms)
Sleeps for given number of milliseconds.
|
static String |
spiAttribute(GridSpi spi,
String attrName)
Creates SPI attribute name by adding prefix to the attribute name.
|
static void |
startLifecycleAware(Iterable<?> objs)
For each object provided by the given
Iterable checks if it implements
GridLifecycleAware interface and executes GridLifecycleAware.start() method. |
static void |
startThreads(Iterable<? extends Thread> threads)
Starts given threads.
|
static <T> T |
staticField(Class<?> cls,
String fieldName)
Gets static field value.
|
static void |
stopLifecycleAware(GridLogger log,
Iterable<?> objs)
For each object provided by the given
Iterable checks if it implements
GridLifecycleAware interface and executes GridLifecycleAware.stop() method. |
static Object |
sunReflectionFactory()
SUN JDK specific reflection factory for objects without public constructor.
|
static <T> T[] |
toArray(Collection<? extends T> c,
T[] arr)
Copies all elements from collection to array and asserts that
array is big enough to hold the collection.
|
protected static int |
toDigit(char ch,
int index)
Converts a hexadecimal character to an integer.
|
static Collection<InetAddress> |
toInetAddresses(Collection<String> addrs,
Collection<String> hostNames)
Returns tha list of resolved inet addresses.
|
static Collection<InetAddress> |
toInetAddresses(GridNode node)
Returns tha list of resolved inet addresses.
|
static int[] |
toIntArray(Collection<Integer> c)
Converts collection of integers into array.
|
static List<Integer> |
toIntList(int[] arr,
GridPredicate<Integer>... p)
Converts array of integers into list.
|
static long[] |
toLongArray(Collection<Long> c)
Converts collection of integers into array.
|
static List<Long> |
toLongList(long[] arr)
Converts array of longs into list.
|
static String |
toShortString(Collection<? extends GridNode> ns)
Short node representation.
|
static String |
toShortString(GridNode n)
Short node representation.
|
static Collection<InetSocketAddress> |
toSocketAddresses(Collection<String> addrs,
Collection<String> hostNames,
int port)
Returns tha list of resolved socket addresses.
|
static Collection<InetSocketAddress> |
toSocketAddresses(GridNode node,
int port)
Returns tha list of resolved socket addresses.
|
static int[] |
unique(int[] a,
int aLen,
int[] b,
int bLen)
Returns array which is the union of two arrays
(array of elements contained in any of provided arrays).
|
static Exception |
unwrap(Throwable t)
Unwraps closure exceptions.
|
static void |
unzip(File zipFile,
File toDir,
GridLogger log)
Unzip file to folder.
|
static byte[] |
uuidToBytes(UUID uuid)
Converts an UUID to byte array.
|
static int |
uuidToBytes(UUID uuid,
byte[] arr,
int off)
Encodes
UUID into a sequence of bytes using the ByteBuffer,
storing the result into a new byte array. |
static void |
wait(Object mux)
Converts
InterruptedException to GridException. |
static void |
warn(GridLogger log,
Object msg)
Depending on whether or not log is provided and quiet mode is enabled logs given
messages as quiet message or normal log WARN message.
|
static void |
warn(GridLogger log,
Object longMsg,
Object shortMsg)
Depending on whether or not log is provided and quiet mode is enabled logs given
messages as quiet message or normal log WARN message.
|
static <E extends Throwable> |
withCause(E e,
Throwable cause)
Utility method that sets cause into exception and returns it.
|
static <T extends GridMetadataAware> |
withMeta(T t,
Object obj)
Copies metadata from given object into the passed in metadata aware
instance - if object is not
null and implements GridMetadataAware. |
static <R> R |
wrapThreadLoader(ClassLoader ldr,
Callable<R> c)
Sets thread context class loader to the given loader, executes the closure, and then
resets thread context class loader to its initial value.
|
static <R> R |
wrapThreadLoader(ClassLoader ldr,
GridOutClosure<R> c)
Sets thread context class loader to the given loader, executes the closure, and then
resets thread context class loader to its initial value.
|
static void |
wrapThreadLoader(ClassLoader ldr,
Runnable c)
Sets thread context class loader to the given loader, executes the closure, and then
resets thread context class loader to its initial value.
|
static <T> void |
writeArray(ObjectOutput out,
T[] arr)
Writes array to output stream.
|
static void |
writeBooleanArray(DataOutput out,
boolean[] arr)
Writes boolean array to output stream accounting for null values.
|
static void |
writeByteArray(DataOutput out,
byte[] arr)
Writes byte array to output stream accounting for null values.
|
static void |
writeByteCollection(DataOutput out,
Collection<Byte> col)
// FIXME: added for DR dataCenterIds, review if it is needed after GG-6879.
|
static void |
writeBytesCollection(DataOutput out,
Collection<byte[]> bytes)
Writes collection of byte arrays to data output.
|
static void |
writeCollection(ObjectOutput out,
Collection<?> col) |
static <E extends Enum> |
writeEnum(DataOutput out,
E e)
Writes enum to output stream accounting for
null values. |
static <E extends Enum> |
writeEnum0(DataOutput out,
E e)
Deprecated.
Need to remove when release will not be to support
backward compatible. Use
U.writeEnum(DataOutput, Enum). |
static void |
writeGridUuid(DataOutput out,
GridUuid uid)
Writes
GridUuid to output stream. |
static void |
writeGridUuids(DataOutput out,
Collection<GridUuid> col)
Writes Grid UUIDs to output stream.
|
static void |
writeIntCollection(DataOutput out,
Collection<Integer> col) |
static void |
writeIntKeyIntValueMap(DataOutput out,
Map<Integer,Integer> map) |
static void |
writeIntKeyMap(ObjectOutput out,
Map<Integer,?> map) |
static void |
writeMap(ObjectOutput out,
Map<?,?> map) |
static void |
writeString(DataOutput out,
String s)
Writes string to output stream accounting for
null values. |
static void |
writeStringMap(DataOutput out,
Map<String,String> map)
Writes string-to-string map to given data output.
|
static void |
writeStringToFile(File file,
String s)
Writes string to file.
|
static void |
writeStringToFile(File file,
String s,
String charset)
Writes string to file.
|
static void |
writeStringToFile(File file,
String s,
String charset,
boolean append)
Writes string to file.
|
static void |
writeUuid(DataOutput out,
UUID uid)
Writes UUID to output stream.
|
static void |
writeUuids(DataOutput out,
Collection<UUID> col)
Writes UUIDs to output stream.
|
static byte[] |
zipBytes(byte[] input)
Zips byte array.
|
static byte[] |
zipBytes(byte[] input,
int initBufSize)
Zips byte array.
|
public static final String DFLT_USER_VERSION
public static final byte OPTIMIZED_CLIENT_PROTO_ID
public static final byte PROTOBUF_CLIENT_PROTO_ID
public static final byte JDK_CLIENT_PROTO_ID
public static final String JMX_DOMAIN
public static final byte[] GG_HEADER
public static final String MAC_INVALID_ARG_MSG
public static long currentTimeMillis()
public static long microTime()
System.nanoTime() in microseconds.public static int ceilPow2(int v)
v - Value.public static boolean isPow2(int i)
i - Value.true If the given value is power of 2 (0 is not power of 2).@Nullable public static Method ctorFactory()
public static Constructor objectConstructor()
@Nullable public static Object sunReflectionFactory()
public static String gridEventName(int type)
type - Event type.public static int[] gridEvents(int... excl)
excl - Optional exclude events.public static boolean discoOrdered(GridDiscoverySpi discoSpi)
discoSpi - Discovery SPI.True if ordering is supported.public static boolean securityEnabled(GridConfiguration cfg)
cfg - Configuration to check.True if authentication SPI is configured.public static boolean relaxDiscoveryOrdered()
@Deprecated public static void debug(Object msg)
msg - Message to debug.@Deprecated public static void debugx(String msg)
msg - Message to debug.@Deprecated public static void debug(GridLogger log, String msg)
log - Logger.msg - Message to debug.@Deprecated public static void dumpStack()
System.out.@Deprecated public static void dumpStack(String msg)
System.out.msg - Message to print with the stack.public static void dumpStack(@Nullable GridLogger log, String msg)
log - Logger.msg - Message.@Deprecated public static void dumpStack(String msg, PrintStream out)
msg - Message to print with the stack.out - Output to dump stack to.@Deprecated public static void debugStack(GridLogger log, String msg)
log - Logger.msg - Message to print with the stack.public static void debugHeapUsage()
public static double heapSize(GridNode node, int precision)
node - Node.precision - Precision.public static double heapSize(Iterable<GridNode> nodes, int precision)
nodes - Nodes.precision - Precision.public static double heapSize(int precision)
heapSize(GridNode, int).precision - Precision.public static void dumpThreads(@Nullable GridLogger log)
log - Logger.@Nullable public static Constructor<?> forceEmptyConstructor(Class<?> cls) throws GridException
cls - Class to get empty constructor for.null otherwise.GridException - If failed.@Nullable public static <T> T newInstance(Class<T> cls) throws GridException
cls - Class to instantiate.null if empty constructor could not be assigned.GridException - If failed.@Nullable public static <T> T forceNewInstance(Class<?> cls) throws GridException
cls - Class to instantiate.null if empty constructor could not be assigned.GridException - If failed.public static String formatMins(long mins)
mins - Minutes to format.public static String id8(UUID id)
id - Input ID.public static String id8(GridUuid id)
GridUuid (for terse logging).
The ID8 will be constructed as follows:
GridUuid.globalId().GridUuid.localId().id - Input ID.GridUuid.public static String filler(int len, char ch)
len - Number of characters to fill in.ch - Character to fill with.public static <T> void writeArray(ObjectOutput out, T[] arr) throws IOException
T - Array type.out - Output stream.arr - Array to write.IOException - If failed.@Nullable public static Object[] readArray(ObjectInput in) throws IOException, ClassNotFoundException
in - Input stream.IOException - If failed.ClassNotFoundException - If class not found.@Nullable public static <K,V> GridPredicate<GridCacheEntry<K,V>>[] readEntryFilterArray(ObjectInput in) throws IOException, ClassNotFoundException
in - Input stream.IOException - If failed.ClassNotFoundException - If class not found.public static void writeCollection(ObjectOutput out, Collection<?> col) throws IOException
out - Output.col - Set to write.IOException - If write failed.public static void writeBytesCollection(DataOutput out, Collection<byte[]> bytes) throws IOException
out - Output to write to.bytes - Collection with byte arrays.IOException - If write failed.public static List<byte[]> readBytesList(DataInput in) throws IOException
in - Data input to read from.IOException - If read failed.public static void writeIntCollection(DataOutput out, Collection<Integer> col) throws IOException
out - Output.col - Set to write.IOException - If write failed.@Nullable public static <E> Collection<E> readCollection(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If deserialization failed.ClassNotFoundException - If deserialized class could not be found.@Nullable public static Collection<Integer> readIntCollection(DataInput in) throws IOException
in - Input.IOException - If deserialization failed.public static <K,V> Map<K,V> copyMap(Map<K,V> m)
K - Key type.V - Value typem - Map to copy.public static <K,V> Map<K,V> sealMap(Map<K,V> m)
K - Key type.V - Value typem - Map to seal.public static <E> List<E> sealList(Collection<E> c)
E - Entry typec - Collection to seal.public static <E> List<E> sealList(E... a)
E - Entry typea - Array for convert to seal list.@Nullable public static String getNetworkInterfaceName(String addr)
addr - IP address for which to find network interface name.null if can't be found.public static InetAddress resolveLocalHost(@Nullable String hostName) throws IOException
GridConfiguration.getLocalHost() should
be handled in most places.hostName - Hostname or null if local host should be returned.IOException - If attempt to get local host failed.public static boolean isLocalHostChanged()
throws IOException
true or false depending on whether or not local host
has changed from the cached value.IOException - If attempt to get local host failed.public static GridBiTuple<Collection<String>,Collection<String>> resolveLocalAddresses(InetAddress locAddr) throws IOException, GridException
resolveLocalHost(String). So when it returns
a common address this method returns single host name, and when a wildcard address passed
this method tries to collect addresses of all available interfaces.locAddr - Local address to resolve.IOException - If failed.GridException - If no network interfaces found.public static InetAddress getLocalHost() throws IOException
Note that this method is synchronized to make sure that local host initialization happens only once.
IOException - If attempt to get local host failed.public static boolean reachable(NetworkInterface itf, InetAddress addr, int reachTimeout)
itf - Network interface to use for test.addr - Address to check.reachTimeout - Timeout for the check.True if address is reachable.public static boolean reachable(InetAddress addr, int reachTimeout)
addr - Address to check.reachTimeout - Timeout for the check.True if address is reachable.public static boolean sameMacs(GridNode loc, GridNode rmt)
loc - Local node.rmt - Remote node.public static Collection<String> allLocalIps()
public static Collection<String> allLocalMACs()
Note that if network interface is disabled - its MAC won't be included. All local network interfaces are probed including loopbacks. Virtual interfaces (sub-interfaces) are skipped.
Note that on linux getHardwareAddress() can return null from time to time if NetworkInterface.getHardwareAddress() method is called from many threads.
public static File downloadUrl(URL url, File file) throws IOException
url - URL to download.file - File where downloaded resource should be stored.IOException - If error occurred.public static <T extends GridMetadataAware> T withMeta(T t, @Nullable Object obj)
null and implements GridMetadataAware.
Otherwise - returns passed metadata aware instance unchanged.T - Type of the metadata aware instance.t - Passed in metadata aware instance.obj - Object to copy metadata from.@Nullable public static String hidePassword(@Nullable String uri)
Parses given URI by applying ".*://(.*:.*)@.*" regular expression pattern and than if URI matches it replaces password strings between '/' and '@' with '*'.
uri - URI which password should be replaced.public static ClassLoader gridClassLoader()
public static boolean hasParent(@Nullable ClassLoader parent, ClassLoader ldr)
parent - Parent to find.ldr - Loader to check.True if parent found.public static String dash(int len)
'+---+' dash line.len - Length of the dash line to make.public static String pad(int len)
len - Number of spaces.public static String format(long sysTime)
sysTime - System time.public static <T> Iterable<T> randomIterable(Collection<T> col)
T - Type of elements to create iterator for.col - Collection to shuffle.public static <T> Iterable<T> asIterable(Enumeration<T> e)
foreach construct.T - Types of instances for iteration.e - Enumeration to convert.public static void copy(File src, File dest, boolean overwrite) throws IOException
src - Source file or folder.dest - Destination file or folder.overwrite - Whether or not overwrite existing files and folders.IOException - Thrown if an I/O error occurs.public static int copy(InputStream in, OutputStream out) throws IOException
in - Input byte stream.out - Output byte stream.IOException - Thrown if an I/O error occurs.public static int copy(Reader in, Writer out) throws IOException
in - Input character stream.out - Output character stream.IOException - Thrown if an I/O error occurs.public static void writeStringToFile(File file, String s) throws IOException
file - File.s - String to write.IOException - Thrown if an I/O error occurs.public static void writeStringToFile(File file, String s, String charset) throws IOException
file - File.s - String to write.charset - Encoding.IOException - Thrown if an I/O error occurs.public static String readFileToString(String fileName, String charset) throws IOException
fileName - File name.charset - File charset.IOException - If error occurred.public static void writeStringToFile(File file, String s, String charset, boolean append) throws IOException
file - File.s - String to write.charset - Encoding.append - If true, then specified string will be added to the end of the file.IOException - Thrown if an I/O error occurs.public static <E extends Throwable> E withCause(E e, @Nullable Throwable cause)
E - Type of the exception.e - Exception to set cause to and return.cause - Optional cause to set (if not null).public static boolean delete(File file)
file - File or directory to delete.true if and only if the file or directory is successfully deleted,
false otherwisepublic static boolean mkdirs(File dir)
dir - Directory to create along with all non-existent parent directories.True if directory exists (has been created or already existed),
false if has not been created and does not exist.public static boolean getBoolean(String name)
name - Property name.True if system or environment property is set to true. Otherwise returns false.@Nullable public static String getGridGainHome()
GRIDGAIN_HOME property. The property is retrieved from system
properties or from environment in that order.GRIDGAIN_HOME property.public static void setGridGainHome(@Nullable String path)
path - GridGain home. May be null.@Nullable public static File resolveGridGainPath(String path)
First check if path is relative to GRIDGAIN_HOME.
If not, check if path is absolute.
If all checks fail, then null is returned.
See getGridGainHome() for information on how GRIDGAIN_HOME is retrieved.
path - Path to resolve.null if path cannot be resolved.@Nullable public static URL resolveGridGainUrl(String path)
META-INF folder in classpath.
If not, then the check is made if path is relative to ${GRIDGAIN_HOME}.
If all checks fail,
then null is returned, otherwise URL representing path is returned.
See getGridGainHome() for information on how GRIDGAIN_HOME is retrieved.
path - Path to resolve.null if path cannot be resolved.getGridGainHome()@Nullable public static URL resolveGridGainUrl(String path, boolean metaInf)
META-INF folder in classpath.
If not, then the check is made if path is relative to ${GRIDGAIN_HOME}.
If all checks fail,
then null is returned, otherwise URL representing path is returned.
See getGridGainHome() for information on how GRIDGAIN_HOME is retrieved.
path - Path to resolve.metaInf - Flag to indicate whether META-INF folder should be checked or class path root.null if path cannot be resolved.getGridGainHome()public static byte[] join(byte[]... bufs)
bufs - list of byte arrays to concatenate.public static String byteArray2String(byte[] arr, String hdrFmt, String bodyFmt)
...
byte[] data = {10, 20, 30, 40, 50, 60, 70, 80, 90};
U.byteArray2String(data, "0x%02X", ",0x%02X")
...
the result will be:
... 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x46, 0x50, 0x5A ...
arr - Array of byte.hdrFmt - C-style string format for the first element.bodyFmt - C-style string format for second and following elements, if any.public static String byteArray2HexString(byte[] arr)
arr - Array of bytes.public static byte[] hexString2ByteArray(String hex) throws IllegalArgumentException
hex - Hexadecimal string to convert.IllegalArgumentException - If input character differs from certain hex characters.public static byte[] doubleToBytes(double d)
d - Double to convert.public static int doubleToBytes(double d,
byte[] bytes,
int off)
double type to byte array and stores
it in the specified byte array.d - Double to convert.bytes - Array of bytes.off - Offset.public static byte[] floatToBytes(float f)
f - Float to convert.public static int floatToBytes(float f,
byte[] bytes,
int off)
f - Float to convert.bytes - Array of bytes.off - Offset.public static byte[] longToBytes(long l)
long type to byte array.l - Long value.public static int longToBytes(long l,
byte[] bytes,
int off)
long type to byte array and stores it in specified
byte array.l - Long value.bytes - Array of bytes.off - Offset in bytes array.bytes array.public static byte[] intToBytes(int i)
int type to byte array.i - Integer value.public static int intToBytes(int i,
byte[] bytes,
int off)
int type to byte array and stores it in specified
byte array.i - Integer value.bytes - Array of bytes.off - Offset in bytes array.bytes array.public static byte[] shortToBytes(short s)
short type to byte array.s - Short value.public static int shortToBytes(short s,
byte[] bytes,
int off)
short type to byte array and stores it in specified
byte array.s - Short value.bytes - Array of bytes.off - Offset in bytes array.bytes array.public static int uuidToBytes(@Nullable UUID uuid, byte[] arr, int off)
UUID into a sequence of bytes using the ByteBuffer,
storing the result into a new byte array.uuid - Unique identifier.arr - Byte array to fill with result.off - Offset in arr.bytes array.public static byte[] uuidToBytes(@Nullable UUID uuid)
uuid - UUID value.UUID.public static short bytesToShort(byte[] bytes,
int off)
short from byte array.bytes - Array of bytes.off - Offset in bytes array.public static int bytesToInt(byte[] bytes,
int off)
int from byte array.bytes - Array of bytes.off - Offset in bytes array.public static long bytesToLong(byte[] bytes,
int off)
long from byte array.bytes - Array of bytes.off - Offset in bytes array.public static UUID bytesToUuid(byte[] bytes, int off)
UUID form byte array.
If given array contains all 0s then null will be returned.bytes - array of bytes.off - Offset in bytes array.null.public static double bytesToDouble(byte[] bytes,
int off)
bytes - Byte array.off - Offset in bytes array.public static float bytesToFloat(byte[] bytes,
int off)
bytes - Byte array.off - Offset in bytes array.public static boolean bytesEqual(byte[] a,
int aOff,
byte[] b,
int bOff,
int len)
a - First array.aOff - First array offset.b - Second array.bOff - Second array offset.len - Length of fragments.true if fragments are equal, false otherwise.public static boolean containsObjectArray(@Nullable Object[] arr, Object val, @Nullable Object... vals)
null. Two nulls are considered equal.arr - Array of objects.val - Value to check for containment inside of array.vals - Additional values.true if contains object, false otherwise.public static boolean containsObjectArray(@Nullable Object[] arr, @Nullable Collection<Object> c)
null. Two nulls are considered equal.arr - Array of objects.c - Collection to check.true if contains object, false otherwise.public static boolean containsIntArray(int[] arr,
int val)
arr - Array of objects.val - Value to check for containment inside of array.true if contains object, false otherwise.public static boolean containsStringArray(String[] arr, @Nullable String val, boolean ignoreCase)
null. Tow nulls are considered equal.arr - Array of strings.val - Value to check for containment inside of array.ignoreCase - Ignoring case if true.true if contains string, false otherwise.public static boolean containsStringCollection(Iterable<String> c, @Nullable String val, boolean ignoreCase)
null. Tow nulls are considered equal.c - Array of strings.val - Value to check for containment inside of array.ignoreCase - Ignoring case if true.true if contains string, false otherwise.public static boolean containsRegexArray(String[] arr, String regex)
arr - Array of strings.regex - Regular expression.true if string matching given regular expression found, false otherwise.public static void close(@Nullable Closeable rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Closeable rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable Socket rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Socket rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable ServerSocket rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable ServerSocket rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable AbstractInterruptibleChannel rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable AbstractInterruptibleChannel rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable SelectionKey rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable SelectionKey rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable Reader rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Reader rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void closeQuiet(@Nullable Writer rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable ZipFile rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable ZipFile rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable DatagramSocket rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable Selector rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Selector rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable Context rsrc, @Nullable GridLogger log)
rsrc - Resource to close. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Context rsrc)
rsrc - Resource to close. If it's null - it's no-op.public static void close(@Nullable Connection rsrc, @Nullable GridLogger log)
rsrc - JDBC connection to close. If connection is null, it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Connection rsrc)
rsrc - JDBC connection to close. If connection is null, it's no-op.public static void close(@Nullable Statement rsrc, @Nullable GridLogger log)
rsrc - JDBC statement to close. If statement is null, it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable Statement rsrc)
rsrc - JDBC statement to close. If statement is null, it's no-op.public static void close(@Nullable ResultSet rsrc, @Nullable GridLogger log)
rsrc - JDBC result set to close. If result set is null, it's no-op.log - Logger to log possible checked exception with (optional).public static void closeQuiet(@Nullable ResultSet rsrc)
rsrc - JDBC result set to close. If result set is null, it's no-op.public static void close(@Nullable URLClassLoader clsLdr, @Nullable GridLogger log)
clsLdr - Class loader. If it's null - it's no-op.log - Logger to log possible checked exception with (optional).public static void releaseQuiet(@Nullable FileLock lock)
lock - File lock. If it's null - it's no-op.public static void rollbackConnection(@Nullable Connection rsrc, @Nullable GridLogger log)
rsrc - JDBC connection to rollback. If connection is null, it's no-op.log - Logger to log possible checked exception with (optional).public static void courtesy(@Nullable GridLogger log, Object msg)
org.gridgain.grid.CourtesyConfigNotice
category. If log is null or in QUIET mode it will add (courtesy)
prefix to the message.log - Optional logger to use when QUIET mode is not enabled.msg - Message to log.public static void courtesy(@Nullable GridLogger log, Object longMsg, Object shortMsg)
org.gridgain.grid.CourtesyConfigNotice
category. If log is null or in QUIET mode it will add (courtesy)
prefix to the message.log - Optional logger to use when QUIET mode is not enabled.longMsg - Message to log using normal logger.shortMsg - Message to log using quiet logger.public static void warn(@Nullable GridLogger log, Object msg)
log is null
or in QUIET mode it will add (wrn) prefix to the message.log - Optional logger to use when QUIET mode is not enabled.msg - Message to log.public static void quietAndWarn(GridLogger log, Object msg)
log - Logger to use.msg - Message to log.public static void quietAndWarn(GridLogger log, Object msg, Object shortMsg)
log - Logger to use.shortMsg - Short message.msg - Message to log.public static void error(@Nullable GridLogger log, Object msg)
log is null
or in QUIET mode it will add (err) prefix to the message.log - Optional logger to use when QUIET mode is not enabled.msg - Message to log.public static void warn(@Nullable GridLogger log, Object longMsg, Object shortMsg)
log is null
or in QUIET mode it will add (wrn) prefix to the message.log - Optional logger to use when QUIET mode is not enabled.longMsg - Message to log using normal logger.shortMsg - Message to log using quiet logger.public static void log(@Nullable GridLogger log, Object longMsg, Object shortMsg)
NOTE: unlike the normal logging when INFO level may not be enabled and therefore no logging will happen - using this method the log will be written always either via INFO log or quiet mode.
USE IT APPROPRIATELY.
log - Optional logger to use when QUIET mode is not enabled.longMsg - Message to log using normal logger.shortMsg - Message to log using quiet logger.public static void log(@Nullable GridLogger log, Object msg)
NOTE: unlike the normal logging when INFO level may not be enabled and therefore no logging will happen - using this method the log will be written always either via INFO log or quiet mode.
USE IT APPROPRIATELY.
log - Optional logger to use when QUIET mode is not enabled.msg - Message to log.public static void error(@Nullable GridLogger log, Object longMsg, Object shortMsg, @Nullable Throwable e)
log is null
or in QUIET mode it will add (err) prefix to the message.log - Optional logger to use when QUIET mode is not enabled.longMsg - Message to log using normal logger.shortMsg - Message to log using quiet logger.e - Optional exception.public static void error(@Nullable GridLogger log, Object shortMsg, @Nullable Throwable e)
error(GridLogger, Object, Object, Throwable).log - Optional logger.shortMsg - Message to log using quiet logger.e - Optional exception.public static void quiet(boolean err,
Object... objs)
err - Whether to print to System.err.objs - Objects to log in quiet mode.public static void quietAndInfo(GridLogger log, String msg)
log - Logger.msg - Message to print.public static void rollbackConnectionQuiet(@Nullable Connection rsrc)
rsrc - JDBC connection to rollback. If connection is null, it's no-op.public static ObjectName makeMBeanName(@Nullable String gridName, @Nullable String grp, String name) throws MalformedObjectNameException
groups used for proper object name construction.gridName - Grid name.grp - Name of the group.name - Name of mbean.MalformedObjectNameException - Thrown in case of any errors.public static String maskName(@Nullable String cacheName)
null.cacheName - Component name to mask, possibly null.public static ObjectName makeCacheMBeanName(@Nullable String gridName, @Nullable String cacheName, String name) throws MalformedObjectNameException
groups used for proper object name construction.gridName - Grid name.cacheName - Name of the cache.name - Name of mbean.MalformedObjectNameException - Thrown in case of any errors.public static <T> ObjectName registerMBean(MBeanServer mbeanSrv, @Nullable String gridName, @Nullable String grp, String name, T impl, @Nullable Class<T> itf) throws JMException
T - Type of mbean.mbeanSrv - MBean server.gridName - Grid name.grp - Name of the group.name - Name of mbean.impl - MBean implementation.itf - MBean interface.JMException - If MBean creation failed.public static <T> ObjectName registerMBean(MBeanServer mbeanSrv, ObjectName name, T impl, Class<T> itf) throws JMException
T - Type of mbean.mbeanSrv - MBean server.name - MBean object name.impl - MBean implementation.itf - MBean interface.JMException - If MBean creation failed.public static <T> ObjectName registerCacheMBean(MBeanServer mbeanSrv, @Nullable String gridName, @Nullable String cacheName, String name, T impl, Class<T> itf) throws JMException
T - Type of mbean.mbeanSrv - MBean server.gridName - Grid name.cacheName - Name of the cache.name - Name of mbean.impl - MBean implementation.itf - MBean interface.JMException - If MBean creation failed.public static void interrupt(@Nullable Thread t)
null.t - Thread to interrupt.public static void interrupt(Iterable<? extends Thread> workers)
null.workers - Threads to interrupt.public static boolean join(@Nullable Thread t, @Nullable GridLogger log)
null then
this method returns immediately returning truet - Thread to join.log - Logger for logging errors.true if thread has finished, false otherwise.public static boolean joinThreads(Iterable<? extends Thread> workers, @Nullable GridLogger log)
null then
this method returns immediately returning trueworkers - Thread to join.log - Logger for logging errors.true if thread has finished, false otherwise.public static void startThreads(Iterable<? extends Thread> threads)
threads - Threads to start.public static void cancel(@Nullable GridWorker w)
w - Worker to cancel - it's no-op if runnable is null.public static void cancel(Iterable<? extends GridWorker> ws)
ws - Collection of workers - it's no-op if collection is null.public static boolean join(@Nullable GridWorker w, @Nullable GridLogger log)
w - Worker to join.log - The logger to possible exception.true if worker has not been interrupted, false if it was interrupted.public static boolean join(Iterable<? extends GridWorker> ws, GridLogger log)
ws - Collection of workers to join.log - The logger to possible exceptions.true if none of the worker have been interrupted,
false if at least one was interrupted.public static void shutdownNow(Class<?> owner, @Nullable ExecutorService exec, @Nullable GridLogger log)
ExecutorService and wait for executor service to stop.owner - The ExecutorService owner.exec - ExecutorService to shutdown.log - The logger to possible exceptions and warnings.public static GridEmptyProjectionException emptyTopologyException()
public static void writeUuids(DataOutput out, @Nullable Collection<UUID> col) throws IOException
Externalizable interface.out - Output stream.col - UUIDs to write.IOException - If write failed.@Nullable public static List<UUID> readUuids(DataInput in) throws IOException
Externalizable interface.in - Input stream.IOException - If read failed.public static void writeGridUuids(DataOutput out, @Nullable Collection<GridUuid> col) throws IOException
Externalizable interface.out - Output stream.col - Grid UUIDs to write.IOException - If write failed.@Nullable public static List<GridUuid> readGridUuids(DataInput in) throws IOException
Externalizable interface.in - Input stream.IOException - If read failed.public static void writeUuid(DataOutput out, UUID uid) throws IOException
Externalizable interface.out - Output stream.uid - UUID to write.IOException - If write failed.@Nullable public static UUID readUuid(DataInput in) throws IOException
Externalizable interface.in - Input stream.IOException - If read failed.public static void writeGridUuid(DataOutput out, GridUuid uid) throws IOException
GridUuid to output stream. This method is meant to be used by
implementations of Externalizable interface.out - Output stream.uid - UUID to write.IOException - If write failed.@Nullable public static GridUuid readGridUuid(DataInput in) throws IOException
GridUuid from input stream. This method is meant to be used by
implementations of Externalizable interface.in - Input stream.IOException - If read failed.public static void gridUuidToBytes(GridUuid uuid, byte[] out, int off)
uuid - GridUuid to convert.out - Output array to write to.off - Offset from which to write.public static GridUuid bytesToGridUuid(byte[] in, int off)
in - Input byte array.off - Offset from which start reading.public static void writeByteArray(DataOutput out, @Nullable byte[] arr) throws IOException
out - Output stream to write to.arr - Array to write, possibly null.IOException - If write failed.@Nullable public static byte[] readByteArray(DataInput in) throws IOException
in - Stream to read from.IOException - If read failed.public static void writeBooleanArray(DataOutput out, @Nullable boolean[] arr) throws IOException
out - Output stream to write to.arr - Array to write, possibly null.IOException - If write failed.@Nullable public static boolean[] readBooleanArray(DataInput in) throws IOException
in - Stream to read from.IOException - If read failed.public static byte[] readByteArray(ByteBuffer... bufs)
bufs - Byte buffers.public static int hashCode(ByteBuffer... bufs)
Arrays.hashCode(byte[])
with the same content. Does not change buffers positions.bufs - Byte buffers.public static void writeMap(ObjectOutput out, Map<?,?> map) throws IOException
out - Output.map - Map to write.IOException - If write failed.@Nullable public static <K,V> Map<K,V> readMap(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If de-serialization failed.ClassNotFoundException - If deserialized class could not be found.@Nullable public static <K,V> TreeMap<K,V> readTreeMap(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If de-serialization failed.ClassNotFoundException - If deserialized class could not be found.public static void writeStringMap(DataOutput out, @Nullable Map<String,String> map) throws IOException
out - Data output.map - Map.IOException - If write failed.public static Map<String,String> readStringMap(DataInput in) throws IOException
writeStringMap(DataOutput, Map).in - Data input.IOException - If write failed.@Nullable public static <K,V> LinkedHashMap<K,V> readLinkedMap(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If de-serialization failed.ClassNotFoundException - If deserialized class could not be found.public static void writeIntKeyMap(ObjectOutput out, Map<Integer,?> map) throws IOException
out - Output.map - Map to write.IOException - If write failed.@Nullable public static <V> Map<Integer,V> readIntKeyMap(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If de-serialization failed.ClassNotFoundException - If deserialized class could not be found.public static void writeIntKeyIntValueMap(DataOutput out, Map<Integer,Integer> map) throws IOException
out - Output.map - Map to write.IOException - If write failed.@Nullable public static Map<Integer,Integer> readIntKeyIntValueMap(DataInput in) throws IOException
in - Input.IOException - If de-serialization failed.@Nullable public static <E> List<E> readList(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If deserialization failed.ClassNotFoundException - If deserialized class could not be found.@Nullable public static List<Integer> readIntList(DataInput in) throws IOException
in - Input.IOException - If deserialization failed.public static void writeByteCollection(DataOutput out, Collection<Byte> col) throws IOException
out - Output.col - Set to write.IOException - If write failed.@Nullable public static List<Byte> readByteList(DataInput in) throws IOException
in - Input.IOException - If deserialization failed.@Nullable public static <E> Set<E> readSet(ObjectInput in) throws IOException, ClassNotFoundException
in - Input.IOException - If deserialization failed.ClassNotFoundException - If deserialized class could not be found.@Nullable public static Set<Integer> readIntSet(DataInput in) throws IOException
in - Input.IOException - If deserialization failed.public static void writeString(DataOutput out, String s) throws IOException
null values.out - Output stream to write to.s - String to write, possibly null.IOException - If write failed.@Nullable public static String readString(DataInput in) throws IOException
null values.in - Stream to read from.null.IOException - If read failed.public static <E extends Enum> void writeEnum(DataOutput out, E e) throws IOException
null values.
Note: method writes only one byte for every enum. Therefore, this method
only for Enums with maximum count of values equals to 128.out - Output stream to write to.e - Enum value to write, possibly null.IOException - If write failed.@Deprecated public static <E extends Enum> void writeEnum0(DataOutput out, E e) throws IOException
U.writeEnum(DataOutput, Enum).null values.out - Output stream to write to.e - Enum value to write, possibly null.IOException - If write failed.@Deprecated public static int readEnumOrdinal0(DataInput in) throws IOException
Enum.fromOrdinal(int).null values.in - Stream to read from.-1 means null.IOException - If read failed.public static <T> T getByIndex(Collection<T> vals, int idx)
T - Type of collection values.vals - Collection of values.idx - Index of value in the collection.@Nullable public static <T extends Annotation> T getAnnotation(Class<?> cls, Class<T> annCls)
T - Type of annotation to return.cls - Class to get annotation from.annCls - Annotation to get.null if not found.public static <T extends Annotation> boolean hasAnnotation(Class<?> cls, Class<T> annCls)
T - Annotation type.cls - Class to get annotation from.annCls - Annotation to get.true if class has annotation or false otherwise.public static <T extends Annotation> boolean hasAnnotation(Object o, Class<T> annCls)
o - Object to get annotation from.annCls - Annotation to get.true if class has annotation or false otherwise.public static String getSimpleName(Class<?> cls)
cls - Class to get the name for.public static boolean containsAll(Map<?,?> base, Map<?,?> map)
base - Base map.map - Map to check.True if all entries within map are contained in base map,
false otherwise.public static String getTaskName(Class<? extends GridComputeTask<?,?>> taskCls)
taskCls - Task class.GridComputeTaskName})
or task class name if there is no annotation.public static String spiAttribute(GridSpi spi, String attrName)
spi - SPI.attrName - attribute name.public static String classNameToResourceName(String clsName)
clsName - Class name.public static RuntimeMXBean getRuntimeMx()
public static ThreadMXBean getThreadMx()
public static OperatingSystemMXBean getOsMx()
public static MemoryMXBean getMemoryMx()
public static CompilationMXBean getCompilerMx()
public static Class<?> detectClass(Object obj)
obj - Object.public static ClassLoader detectClassLoader(Class<?> cls)
This method will first check if Thread.getContextClassLoader() is appropriate.
If yes, then context class loader will be returned, otherwise
the Class.getClassLoader() will be returned.
cls - Class to find class loader for.null).@Nullable public static ClassLoader detectObjectClassLoader(@Nullable Object obj)
obj - Object to find class loader for class of.null).public static boolean isLoadableBy(String clsName, @Nullable ClassLoader ldr)
clsName - Class name to test.ldr - Class loader to test with. If null - we'll use system class loader instead.
If System class loader is not set - this method will return false.True if class is loadable, false otherwise.public static GridPeerDeployAware peerDeployAware0(@Nullable Iterable<?> c)
null, empty or contains only nulls - the peer
deploy aware object based on system class loader will be returned.c - Collection.IllegalArgumentException - Thrown in case when common class loader for all
elements in this collection cannot be found. In such case - peer deployment
is not possible.public static GridPeerDeployAware peerDeployAware0(@Nullable Object... c)
null, empty or contains only nulls - the peer
deploy aware object based on system class loader will be returned.c - Objects.IllegalArgumentException - Thrown in case when common class loader for all
elements in this array cannot be found. In such case - peer deployment
is not possible.public static GridPeerDeployAware peerDeployAware0(Object obj)
GridPeerDeployAware for object.
Checks, if the object is an instance of collection or object
array.obj - Object to deploy.GridPeerDeployAware instance for given object.public static GridPeerDeployAware peerDeployAware(Object obj)
GridPeerDeployAware for object.obj - Object to deploy.GridPeerDeployAware instance for given object.public static GridPeerDeployAware detectPeerDeployAware(GridPeerDeployAware obj)
obj - Object to check.public static boolean isGridGain(Class<?> cls)
GridGain type.cls - Class to check.True if given class is of GridGain type.public static boolean isGrid(Class<?> cls)
Grid type.cls - Class to check.True if given class is of Grid type.public static String compact(String s)
org.gridgain. with o.g.,
org.gridgain.grid. with o.g.g., org.gridgain.visor. with o.g.v. and
org.gridgain.scalar. with o.g.s..s - String to replace in.public static boolean isJdk(Class<?> cls)
cls - Class to check.True if object is JDK type.public static void wait(Object mux) throws GridInterruptedException
InterruptedException to GridException.mux - Mux to wait on.GridInterruptedException - If interrupted.public static void unzip(File zipFile, File toDir, @Nullable GridLogger log) throws IOException
zipFile - ZIP file.toDir - Directory to unzip file content.log - Grid logger.IOException - In case of error.public static String osJdkString()
public static String osString()
public static String jdkString()
public static boolean isLinux()
true if current OS is Linux - false otherwise.public static String jdkName()
public static String jdkVendor()
public static String jdkVersion()
public static String osArchitecture()
public static String osName()
public static String osVersion()
public static boolean isMacOs()
true if current OS is Mac OS - false otherwise.public static boolean isNetWare()
true if current OS is Netware - false otherwise.public static boolean isSolaris()
true if current OS is Solaris (SPARC or x86) - false otherwise.public static boolean isSolarisSparc()
true if current OS is Solaris SPARC - false otherwise.public static boolean isSolarisX86()
true if current OS is Solaris x86 - false otherwise.public static boolean isUnix()
true if current OS is UNIX - false otherwise.public static boolean isWindows()
true if current OS is Windows (any versions) - false otherwise.public static boolean isWindowsVista()
true if current OS is Windows Vista - false otherwise.public static boolean isWindows7()
true if current OS is Windows 7 - false otherwise.public static boolean isWindows2k()
true if current OS is Windows 2000 - false otherwise.public static boolean isWindows2003()
true if current OS is Windows Server 2003 - false otherwise.public static boolean isWindows2008()
true if current OS is Windows Server 2008 - false otherwise.public static boolean isWindows95()
true if current OS is Windows 95 - false otherwise.public static boolean isWindows98()
true if current OS is Windows 98 - false otherwise.public static boolean isWindowsNt()
true if current OS is Windows NT - false otherwise.public static boolean isSufficientlyTestedOs()
true if current OS was sufficiently tested - false otherwise.public static boolean isWindowsXp()
true if current OS is Windows XP- false otherwise.public static String jvmSpec()
public static String jvmVersion()
public static String jvmVendor()
public static String jvmName()
public static int compareVersionNumbers(@Nullable String v1, @Nullable String v2)
v1 - - java implementation versionv2 - - java implementation version0 if v1 == v2;
a value less than 0 if v1 < v2; and
a value greater than 0 if v1 > v2public static GridProductVersion productVersion(GridNode node)
node - Node to get version from.public static boolean isJavaVersionAtLeast(String v)
vv - - java implementation versiontrue if running on Java Runtime version greater than vpublic static String jreName()
public static String jreVersion()
public static boolean isHotSpot()
true if current JVM implementation is a Sun HotSpot VM, false otherwise.@Nullable public static <R> R wrapThreadLoader(ClassLoader ldr, Callable<R> c) throws GridException
R - Return type.ldr - Class loader to run the closure under.c - Callable to run.GridException - If call failed.@Nullable public static <R> R wrapThreadLoader(ClassLoader ldr, GridOutClosure<R> c)
R - Return type.ldr - Class loader to run the closure under.c - Closure to run.public static void wrapThreadLoader(ClassLoader ldr, Runnable c)
ldr - Class loader to run the closure under.c - Closure to run.public static String toShortString(GridNode n)
n - Grid node.public static String toShortString(Collection<? extends GridNode> ns)
ns - Grid nodes.public static int[] toIntArray(@Nullable Collection<Integer> c)
c - Collection of integers.public static List<Integer> toIntList(@Nullable int[] arr, GridPredicate<Integer>... p)
arr - Array of integers.p - Optional predicate array.public static long[] toLongArray(@Nullable Collection<Long> c)
c - Collection of integers.public static List<Long> toLongList(@Nullable long[] arr)
arr - Array of longs.public static <T> T[] toArray(Collection<? extends T> c, T[] arr)
Collection.toArray(Object[])
method.T - Element type.c - Collection to convert to array.arr - Array to populate.public static int[] unique(int[] a,
int aLen,
int[] b,
int bLen)
a - First array.aLen - Length of prefix a.b - Second array.bLen - Length of prefix b.a and b.public static int[] difference(int[] a,
int aLen,
int[] b,
int bLen)
a - First array.aLen - Length of prefix a.b - Second array.bLen - Length of prefix b.a and b.public static boolean isIncreasingArray(int[] arr,
int len)
arr - Array.len - Prefix length.True if arr from 0 to (len - 1) increases.public static boolean isNonDecreasingArray(int[] arr,
int len)
arr - Array.len - Prefix length.True if arr from 0 to (len - 1) do not decreases.public static int[] copyIfExceeded(int[] arr,
int len)
arr - Array.len - Prefix length.arr is equals to len,
otherwise copy of array.public static Calendar parseIsoDate(String str) throws GridException
str - ISO date.GridException - Thrown in case of any errors.public static <V,C extends Collection<? super V>> C addAll(C c, V... vals)
V - Value type.c - Collection to add values to.vals - Values.public static <K,V,M extends Map<K,V>> M addAll(M m, Map.Entry<K,V>... entries)
K - Key type.V - Value type.M - Map type.m - Map to add entries to.entries - Entries.public static <K,V,M extends Map<K,V>> M addAll(M m, GridBiTuple<K,V>... entries)
K - Key type.V - Value type.M - Map type.m - Map to add entries to.entries - Entries.public static JMException jmException(Throwable e)
JMException with given cause.e - Cause exception.JMException.public static Exception unwrap(Throwable t)
t - Exception.public static GridException cast(Throwable t)
GridException. Creates wrapping
GridException, if needed.t - Throwable to cast.public static Date parse(String src, String ptrn) throws ParseException
src - String to parse.ptrn - Pattern.ParseException - If exception occurs while parsing.public static boolean p2pLoader(Object o)
o - Object to check.True if P2P class loader.public static boolean p2pLoader(ClassLoader ldr)
ldr - Class loader to check.True if P2P class loader.public static String format(Date date, String ptrn)
date - Date to format.ptrn - Pattern.public static GridClosure<UUID,GridNode> id2Node(GridKernalContext ctx)
ctx - Kernal context.@Deprecated public static void dumpStack(Thread t)
t - Thread to dump stack for.@Deprecated public static void dumpStack(Thread t, PrintStream s)
t - Thread to dump stack for.s - PrintStream to use for output.public static boolean isPrimitiveArray(Object obj)
obj - Object to check.True if Object is primitive array.public static boolean isPrimitiveOrWrapper(Class<?> cls)
cls - Class.True if given class represents a primitive or a primitive wrapper class.public static void await(Condition cond) throws GridInterruptedException
cond - Condition to await for.GridInterruptedException - Wrapped InterruptedExceptionpublic static boolean await(Condition cond, long time, TimeUnit unit) throws GridInterruptedException
cond - Condition to await for.time - The maximum time to wait,unit - The unit of the time argument.false if the waiting time detectably elapsed before return from the method, else trueGridInterruptedException - Wrapped InterruptedExceptionpublic static void await(CountDownLatch latch) throws GridInterruptedException
latch - Latch to wait for.GridInterruptedException - Wrapped InterruptedException.public static boolean await(CountDownLatch latch, long timeout, TimeUnit unit) throws GridInterruptedException
latch - Latch to wait for.timeout - Maximum time to wait.unit - Time unit for timeout.True if the count reached zero and false
if the waiting time elapsed before the count reached zero.GridInterruptedException - Wrapped InterruptedException.public static void awaitQuiet(CountDownLatch latch)
If calling thread was interrupted, interrupted status will be recovered prior to return.
latch - Latch to wait for.public static void awaitQuiet(CyclicBarrier barrier)
If calling thread was interrupted, interrupted status will be recovered prior to return. If the barrier is already broken, return immediately without throwing any exceptions.
barrier - Barrier to wait for.public static void sleep(long ms)
throws GridInterruptedException
ms - Time to sleep.GridInterruptedException - Wrapped InterruptedException.public static void join(GridWorker w) throws GridInterruptedException
w - Worker.GridInterruptedException - Wrapped InterruptedException.public static <T> T get(Future<T> fut) throws GridException
fut - Future.GridException - If failed.public static void join(Thread t) throws GridInterruptedException
t - Thread.GridInterruptedException - Wrapped InterruptedException.public static void acquire(Semaphore sem) throws GridInterruptedException
sem - Semaphore.GridInterruptedException - Wrapped InterruptedException.public static GridCacheAttributes[] cacheAttributes(GridNode n)
n - Node to get cache attributes for.@Nullable public static GridCacheAttributes cacheAttributes(GridNode n, @Nullable String cacheName)
n - Node.cacheName - Cache name.public static Collection<String> cacheNames(GridNode n)
n - Node to get cache names for.public static boolean hasCache(GridNode n, @Nullable String cacheName)
n - Node to check.cacheName - Cache name to check.True if given node has specified cache started.public static boolean hasStreamer(GridNode n, @Nullable String streamerName)
n - Node to check.streamerName - Streamer name to check.True if given node has specified streamer started.@Nullable public static GridCacheMode cacheMode(GridNode n, String cacheName)
null if cache is not
present on given node.n - Node to check.cacheName - Cache to check.null if cache is not found.@Nullable public static GridCacheAtomicityMode atomicityMode(GridNode n, String cacheName)
null if cache is not
present on given node.n - Node to check.cacheName - Cache to check.null if cache is not found.public static boolean hasNearCache(GridNode n, String cacheName)
n - Node.cacheName - Cache name.true if given node has near cache enabled for the
specified partitioned cache.public static boolean isFutureNotificationSynchronous(String dflt)
dflt - Default value.true if future notification should work synchronously.public static boolean isFutureNotificationConcurrent(String dflt)
dflt - Default value.true if future notification should work concurrently.public static void asyncLogError(GridFuture<?> f, GridLogger log)
f - Future to listen to.log - Logger.public static Collection<UUID> nodeIds(@Nullable Collection<? extends GridNode> nodes)
nodes - Nodes.public static Collection<UUID> gridIds(@Nullable Collection<? extends Grid> grids)
grids - Grids.public static Collection<String> grids2names(@Nullable Collection<? extends Grid> grids)
grids - Grids.public static Collection<String> nodes2names(@Nullable Collection<? extends GridNode> nodes)
nodes - Nodes.public static boolean addLastCause(@Nullable Throwable e, @Nullable Throwable cause, GridLogger log)
e - Error to add cause to.cause - Cause to add.log - Logger to log failure when cause can not be added.True if cause was added.public static String nl()
line.separator system property.public static GridLogger logger(GridKernalContext ctx, AtomicReference<GridLogger> logRef, Object obj)
ctx - Context.logRef - Log reference.obj - Object to get logger for.public static GridLogger logger(GridKernalContext ctx, AtomicReference<GridLogger> logRef, Class<?> cls)
ctx - Context.logRef - Log reference.cls - Class to get logger for.public static int concurrentMapSegment(int hash,
int concurLvl)
hash - Hash code of the object to put.concurLvl - Concurrency level.public static <K,V> void printConcurrentHashMapInfo(ConcurrentHashMap<K,V> map)
map - Map.public static <T> T field(Object obj, String fieldName)
obj - Object.fieldName - Field name.public static <T> T field(Class<?> cls, String fieldName) throws GridException
cls - Class.fieldName - Field name.GridException - If static field with given name cannot be retreived.public static <T> T invoke(@Nullable Class<?> cls, @Nullable Object obj, String mtdName, Class[] paramTypes, Object... params) throws GridException
cls - Object.obj - Object.mtdName - Field name.paramTypes - Parameter types.params - Parameters.GridException - If static field with given name cannot be retreived.public static <T> T property(Object obj, String propName)
obj - Object.propName - Property name.public static <T> T staticField(Class<?> cls, String fieldName) throws GridException
cls - Class.fieldName - Field name.GridException - If failed.public static boolean isVisorNode(GridNode node)
node - Node to check.True if node is a Visor node, false otherwise.public static boolean isVisorNodeStartProperty(String name)
name - Property name to check.True if property is Visor node startup property, false otherwise.public static boolean isVisorRequiredProperty(String name)
name - Property name to check.True if property is required by Visor, false otherwise.public static GridBiTuple<Object,Object> addLog4jNoOpLogger() throws GridException
null
if it did not found in classpath. Notice that in this case logging is not suppressed.GridException - In case of failure to add no-op logger for Log4j.public static void removeLog4jNoOpLogger(GridBiTuple<Object,Object> t) throws GridException
addLog4jNoOpLogger().t - Tuple with root log and null appender instances.GridException - In case of failure to remove previously added no-op logger for Log4j.public static Collection<Handler> addJavaNoOpLogger()
public static void removeJavaNoOpLogger(Collection<Handler> rmvHnds)
rmvHnds - Previously removed handlers.public static String nodeIdLogFileName(UUID nodeId, String fileName)
nodeId - Node ID.fileName - File name.public static String customDirectoryLogFileName(@Nullable String dir, String fileName)
dir - Directory.fileName - Original path.public static String fl(String msg, Object... args)
msg - Message to start string.args - Even length array where the odd elements are parameter names
and even elements are parameter values.public static int safeAbs(int i)
Integer.MIN_VALUE, then 0 is returned.i - Integer.@Nullable public static Class<?> box(@Nullable Class<?> cls)
cls - Class. If null, method is no-op.@Nullable public static Class<?> forName(@Nullable String clsName, @Nullable ClassLoader ldr) throws ClassNotFoundException
clsName - Class name.ldr - Class loader.ClassNotFoundException - If class not found.public static int hash(int h)
This function has been taken from Java 8 ConcurrentHashMap with slightly modifications.
h - Value to hash.public static int hash(Object key)
This function has been taken from Java 8 ConcurrentHashMap with slightly modifications.
key - Value to hash.public static byte[] zipBytes(byte[] input)
throws IOException
input - Input bytes.IOException - If failed.public static byte[] zipBytes(byte[] input,
int initBufSize)
throws IOException
input - Input bytes.initBufSize - Initial buffer size.IOException - If failed.public static int jvmPid()
-1 if it can't be determined.public static List<String> jvmArgs()
public static int arrayCopy(byte[] src,
int off,
byte[] resBuf,
int resOff,
int len)
src - Buffer to copy from (length included).off - Offset in source buffer.resBuf - Result buffer.resOff - Result offset.len - Length.bytes array.public static String errorMessageWithHelpUrls(String msg)
msg - Error message.public static String consistentId(Collection<String> addrs, int port)
addrs - Node's addresses.port - Port discovery number.GridNode.consistentId() requirements.public static boolean overridesEqualsAndHashCode(Object obj)
obj - Object.True if given object has overridden equals and hashCode method.public static boolean isMacInvalidArgumentError(Exception e)
e - Exception.True if error is invalid argument error on MAC.@Nullable public static <T> T firstNotNull(@Nullable T... vals)
vals - Input array.null, if array is empty or contains
only nulls.public static void startLifecycleAware(Iterable<?> objs) throws GridException
Iterable checks if it implements
GridLifecycleAware interface and executes GridLifecycleAware.start() method.objs - Objects.GridException - If GridLifecycleAware.start() fails.public static void stopLifecycleAware(GridLogger log, Iterable<?> objs)
Iterable checks if it implements
GridLifecycleAware interface and executes GridLifecycleAware.stop() method.log - Logger used to log error message in case of stop failure.objs - Object passed to GridGain configuration.public static Map<String,Collection<GridNode>> neighborhood(Iterable<GridNode> nodes)
Detection of the same physical computer (host) is based on comparing set of network interface MACs. If two nodes have the same set of MACs, GridGain considers these nodes running on the same physical computer.
nodes - Nodes.public static Collection<InetAddress> toInetAddresses(GridNode node) throws GridException
node - Grid node.GridException - If non of addresses can be resolved.public static Collection<InetAddress> toInetAddresses(Collection<String> addrs, Collection<String> hostNames) throws GridException
addrs - Addresses.hostNames - Host names.GridException - If non of addresses can be resolved.public static Collection<InetSocketAddress> toSocketAddresses(GridNode node, int port)
node - Grid node.port - Port.public static Collection<InetSocketAddress> toSocketAddresses(Collection<String> addrs, Collection<String> hostNames, int port)
addrs - Addresses.hostNames - Host names.port - Port.public static Collection<InetSocketAddress> resolveAddresses(GridAddressResolver addrRslvr, Iterable<String> addrs, int port) throws GridException
addrRslvr - Address resolver.addrs - Addresses.port - Port.GridException - If failed.public static String addressesAsString(GridNode node)
node - Grid node.public static String addressesAsString(Collection<String> addrs, Collection<String> hostNames)
addrs - Addresses.hostNames - Host names.public static void setWorkDirectory(@Nullable String userWorkDir, @Nullable String userGgHome) throws GridException
userWorkDir - GridGain work folder provided by user.userGgHome - GridGain home folder provided by user.GridExceptionpublic static File resolveWorkDirectory(String path, boolean delIfExist) throws GridException
path - Path to resolve.delIfExist - Flag indicating whether to delete the specify directory or not.GridException - If failed.public static GridException exceptionWithSuppressed(String msg, @Nullable Collection<Throwable> suppressed)
GridException with the collection of suppressed exceptions.msg - Message.suppressed - The collections of suppressed exceptions.GridException.@Nullable public static String lambdaEnclosingClassName(String clsName)
clsName - JDK8 lambda class name.null if passed in name is not related to lambda.@Nullable public static GridClientMarshaller createProtobufMarshaller(GridLogger log)
gridgain-protobuf
module is not enabled, null is returned.log - Logger.null if gridgain-protobuf module is not enabled.public static byte[] decodeHex(char[] data)
throws GridException
data - An array of characters containing hexidecimal digitsGridException - Thrown if an odd number or illegal of characters is supplied.protected static int toDigit(char ch,
int index)
throws GridException
ch - A character to convert to an integer digitindex - The index of the character in the sourceGridException - Thrown if ch is an illegal hex characterCopyright © 2014. All rights reserved.