Package com.datastax.driver.core
Class Native
- java.lang.Object
-
- com.datastax.driver.core.Native
-
public final class Native extends Object
Helper class to deal with native system calls through the JNR library.The driver can benefit from native system calls to improve its performance and accuracy in some situations.
Currently, the following features may be used by the driver when available:
currentTimeMicros(): thanks to a system call togettimeofday(), the driver is able to generate timestamps with true microsecond precision (seeAtomicMonotonicTimestampGeneratororThreadLocalMonotonicTimestampGeneratorfor more information);processId(): thanks to a system call togetpid(), the driver has access to the JVM's process ID it is running under – which makes time-based UUID generation easier and more reliable (seeUUIDsfor more information).
The availability of the aforementioned system calls depends on the underlying operation system's capabilities. For instance,
gettimeofday()is not available under Windows systems. You can check if any of the system calls exposed through this class is available by callingisGettimeofdayAvailable()orisGetpidAvailable().Note: This class is public because it needs to be accessible from other packages of the Java driver, but it is not meant to be used directly by client code.
- See Also:
- JNR library on Github
-
-
Constructor Summary
Constructors Constructor Description Native()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longcurrentTimeMicros()Returns the current timestamp with microsecond precision via a system call togettimeofday, through JNR C library.static booleanisGetpidAvailable()Returnstrueif JNR POSIX library is loaded and a call togetpidis possible through this library on this system, andfalseotherwise.static booleanisGettimeofdayAvailable()Returnstrueif JNR C library is loaded and a call togettimeofdayis possible through this library on this system, andfalseotherwise.static intprocessId()Returns the JVM's process identifier (PID) via a system call togetpid.
-
-
-
Method Detail
-
isGettimeofdayAvailable
public static boolean isGettimeofdayAvailable()
Returnstrueif JNR C library is loaded and a call togettimeofdayis possible through this library on this system, andfalseotherwise.- Returns:
trueif JNR C library is loaded and a call togettimeofdayis possible.
-
isGetpidAvailable
public static boolean isGetpidAvailable()
Returnstrueif JNR POSIX library is loaded and a call togetpidis possible through this library on this system, andfalseotherwise.- Returns:
trueif JNR POSIX library is loaded and a call togetpidis possible.
-
currentTimeMicros
public static long currentTimeMicros()
Returns the current timestamp with microsecond precision via a system call togettimeofday, through JNR C library.- Returns:
- the current timestamp with microsecond precision.
- Throws:
UnsupportedOperationException- if JNR C library is not loaded orgettimeofdayis not available.IllegalStateException- if the call togettimeofdaydid not complete with return code 0.
-
processId
public static int processId()
Returns the JVM's process identifier (PID) via a system call togetpid.- Returns:
- the JVM's process identifier (PID).
- Throws:
UnsupportedOperationException- if JNR POSIX library is not loaded orgetpidis not available.
-
-