Package org.apache.ignite.internal.util
Class IgniteUtils
java.lang.Object
org.apache.ignite.internal.util.IgniteUtils
Collection of utility methods used throughout the system.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IgniteCheckedExceptionCasts the passedThrowable ttoIgniteCheckedException.
Iftis aGridClosureException, it is unwrapped and then cast toIgniteCheckedException.static StringReplaces all occurrences oforg.apache.ignite.witho.a.i.,org.apache.ignite.internal.witho.a.i.i.,org.apache.ignite.internal.visor.witho.a.i.i.v.andorg.apache.ignite.scalar.witho.a.i.s..static intcopy(InputStream in, OutputStream out) Copies input byte stream to output byte stream.static longstatic booleanDeletes file or directory with all sub-directories and files.static voiderror(IgniteLogger 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 voiderror(IgniteLogger 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 voiderror(IgniteLogger log, Object shortMsg, Throwable e) static GridIntIteratorforRange(int start, int cnt) ReturnsGridIntIteratorfor range of primitive integers.static inthash(int h) Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions.static inthash(long key) A primitive override ofhash(Object)to avoid unnecessary boxing.static intApplies a supplemental hash function to a given hashCode, which defends against poor quality hash functions.static intCalculate a hashCode for an array.static StringhexLong(long val) Gets a hex string representation of the given long value.static voidConvenience method that interrupts a given thread if it's notnull.static voidConvenience method that interrupts a given thread if it's notnull.static booleanisPow2(int i) static StringGets JDK version.static voidJoins thread.static booleanjoin(Thread t, IgniteLogger log) Waits for completion of a given thread.static booleanjoin(Thread t, IgniteLogger log, long timeout) Waits for completion of a given thread.static booleanjoinThreads(Iterable<? extends Thread> workers, IgniteLogger log) Waits for completion of a given threads.static intmajorJavaVersion(String verStr) Get major Java version from string.static intnextPowerOf2(int v) Round up the argument to the next highest power of 2;static Stringnl()static StringreadableSize(long bytes, boolean si) static byte[]Reads byte array from input stream accounting for null values.static intsafeAbs(int i) Gets absolute value for integer.static longsafeAbs(long i) Gets absolute value for long.static voidsleep(long ms) Sleeps for given number of milliseconds.static StringtoHexString(long addr, int len) static ExceptionUnwraps closure exceptions.static voidwarn(IgniteLogger 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 voidwarn(IgniteLogger log, Object msg, Throwable e) 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 voidwriteByteArray(DataOutput out, byte[] arr) Writes byte array to output stream accounting for null values.
-
Field Details
-
MB
public static final long MB- See Also:
-
GB
public static final long GB- See Also:
-
-
Constructor Details
-
IgniteUtils
public IgniteUtils()
-
-
Method Details
-
cast
Casts the passedThrowable ttoIgniteCheckedException.
Iftis aGridClosureException, it is unwrapped and then cast toIgniteCheckedException. Iftis anIgniteCheckedException, it is returned. Iftis not aIgniteCheckedException, a newIgniteCheckedExceptioncaused bytis returned.- Parameters:
t- Throwable to cast.- Returns:
tcast toIgniteCheckedException.
-
currentTimeMillis
public static long currentTimeMillis() -
compact
Replaces all occurrences oforg.apache.ignite.witho.a.i.,org.apache.ignite.internal.witho.a.i.i.,org.apache.ignite.internal.visor.witho.a.i.i.v.andorg.apache.ignite.scalar.witho.a.i.s..- Parameters:
s- String to replace in.- Returns:
- Replaces string.
-
copy
Copies input byte stream to output byte stream.- Parameters:
in- Input byte stream.out- Output byte stream.- Returns:
- Number of the copied bytes.
- Throws:
IOException- Thrown if an I/O error occurs.
-
delete
Deletes file or directory with all sub-directories and files.- Parameters:
path- File or directory to delete.- Returns:
trueif and only if the file or directory is successfully deleted,falseotherwise
-
error
- Parameters:
log- Optional logger.shortMsg- Message to log using quiet logger.e- Optional exception.
-
error
Depending on whether or not log is provided and quiet mode is enabled logs given messages as quiet message or normal log ERROR message. Iflogisnullor in QUIET mode it will add(err)prefix to the message.- Parameters:
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.
-
forRange
ReturnsGridIntIteratorfor range of primitive integers.- Parameters:
start- Start.cnt- Count.
-
hash
public static int hash(int h) Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions. This is critical because ConcurrentHashMap uses power-of-two length hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower or upper bits.This function has been taken from Java 8 ConcurrentHashMap with slightly modifications.
- Parameters:
h- Value to hash.- Returns:
- Hash value.
-
hash
Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions. This is critical because ConcurrentHashMap uses power-of-two length hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower or upper bits.This function has been taken from Java 8 ConcurrentHashMap with slightly modifications.
- Parameters:
key- Value to hash.- Returns:
- Hash value.
-
hash
public static int hash(long key) A primitive override ofhash(Object)to avoid unnecessary boxing.- Parameters:
key- Value to hash.- Returns:
- Hash value.
-
hashCode
Calculate a hashCode for an array.- Parameters:
obj- Object.
-
hexLong
Gets a hex string representation of the given long value.- Parameters:
val- Value to convert to string.- Returns:
- Hex string.
-
interrupt
Convenience method that interrupts a given thread if it's notnull.- Parameters:
t- Thread to interrupt.
-
interrupt
Convenience method that interrupts a given thread if it's notnull.- Parameters:
workers- Threads to interrupt.
-
isPow2
public static boolean isPow2(int i) - Parameters:
i- Value.- Returns:
trueIf the given value is power of 2 (0 is not power of 2).
-
join
public static void join(Thread t) throws org.apache.ignite.internal.IgniteInterruptedCheckedException Joins thread.- Parameters:
t- Thread.- Throws:
org.apache.ignite.internal.IgniteInterruptedCheckedException- WrappedInterruptedException.
-
join
Waits for completion of a given thread. If thread isnullthen this method returns immediately returningtrue- Parameters:
t- Thread to join.log- Logger for logging errors.- Returns:
trueif thread has finished,falseotherwise.
-
join
Waits for completion of a given thread. If thread isnullthen this method returns immediately returningtrue- Parameters:
t- Thread to join.log- Logger for logging errors.timeout- Join timeout.- Returns:
trueif thread has finished,falseotherwise.
-
joinThreads
Waits for completion of a given threads. If thread isnullthen this method returns immediately returningtrue- Parameters:
workers- Thread to join.log- Logger for logging errors.- Returns:
trueif thread has finished,falseotherwise.
-
jdkVersion
Gets JDK version.- Returns:
- JDK version.
-
error
Depending on whether or not log is provided and quiet mode is enabled logs given messages as quiet message or normal log ERROR message. Iflogisnullor in QUIET mode it will add(err)prefix to the message.- Parameters:
log- Optional logger to use when QUIET mode is not enabled.msg- Message to log.
-
nextPowerOf2
public static int nextPowerOf2(int v) Round up the argument to the next highest power of 2;- Parameters:
v- Value to round up.- Returns:
- Next closest power of 2.
-
majorJavaVersion
Get major Java version from string.- Parameters:
verStr- Version string.- Returns:
- Major version or zero if failed to resolve.
-
nl
- Returns:
line.separatorsystem property.
-
readableSize
- Parameters:
bytes- Number of bytes to display.si- Iftrue, then unit base is 1000, otherwise unit base is 1024.- Returns:
- Formatted size.
-
safeAbs
public static int safeAbs(int i) Gets absolute value for integer. If integer isInteger.MIN_VALUE, then0is returned.- Parameters:
i- Integer.- Returns:
- Absolute value.
-
safeAbs
public static long safeAbs(long i) Gets absolute value for long. If argument isLong.MIN_VALUE, then0is returned.- Parameters:
i- Argument.- Returns:
- Absolute value.
-
sleep
public static void sleep(long ms) throws org.apache.ignite.internal.IgniteInterruptedCheckedException Sleeps for given number of milliseconds.- Parameters:
ms- Time to sleep.- Throws:
org.apache.ignite.internal.IgniteInterruptedCheckedException- WrappedInterruptedException.
-
toHexString
- Parameters:
addr- pointer in memorylen- how much byte to read (should divide 8)- Returns:
- hex representation of memory region
-
unwrap
Unwraps closure exceptions.- Parameters:
t- Exception.- Returns:
- Unwrapped exception.
-
warn
Depending on whether or not log is provided and quiet mode is enabled logs given messages as quiet message or normal log WARN message. Iflogisnullor in QUIET mode it will add(wrn)prefix to the message.- Parameters:
log- Optional logger to use when QUIET mode is not enabled.msg- Message to log.
-
warn
Depending on whether or not log is provided and quiet mode is enabled logs given messages as quiet message or normal log WARN message. Iflogisnullor in QUIET mode it will add(wrn)prefix to the message.- Parameters:
log- Optional logger to use when QUIET mode is not enabled.msg- Message to log using normal logger.e- Optional exception.
-
writeByteArray
Writes byte array to output stream accounting for null values.- Parameters:
out- Output stream to write to.arr- Array to write, possibly null.- Throws:
IOException- If write failed.
-
readByteArray
Reads byte array from input stream accounting for null values.- Parameters:
in- Stream to read from.- Returns:
- Read byte array, possibly null.
- Throws:
IOException- If read failed.
-