public final class Native extends Object
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 to gettimeofday()
, the driver
is able to generate timestamps with true microsecond precision (see AtomicMonotonicTimestampGenerator
or ThreadLocalMonotonicTimestampGenerator
for
more information);
processId()
: thanks to a system call to getpid()
, the driver has access to
the JVM's process ID it is running under – which makes time-based UUID generation easier
and more reliable (see UUIDs
for more
information).
getCPU()
: thanks to Platform.getCPU()
, the driver is able to report the
current processor architecture the JVM is running on.
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
calling isGettimeofdayAvailable()
or isGetpidAvailable()
or isPlatformAvailable()
. The method getCPU()
should always be available, unless the
jnr-ffi dependency itself is not present on the classpath.
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.
Constructor and Description |
---|
Native() |
Modifier and Type | Method and Description |
---|---|
static long |
currentTimeMicros()
Returns the current timestamp with microsecond precision via a system call to
gettimeofday , through JNR C library. |
static String |
getCPU()
Returns the current processor architecture the JVM is running on, as reported by
Platform.getCPU() . |
static boolean |
isGetpidAvailable()
Returns
true if JNR POSIX library is loaded and a call to getpid is possible
through this library on this system, and false otherwise. |
static boolean |
isGettimeofdayAvailable()
Returns
true if JNR C library is loaded and a call to gettimeofday is possible
through this library on this system, and false otherwise. |
static boolean |
isPlatformAvailable()
Returns
true if JNR Platform class is loaded, and false otherwise. |
static int |
processId()
Returns the JVM's process identifier (PID) via a system call to
getpid . |
public static boolean isGettimeofdayAvailable()
true
if JNR C library is loaded and a call to gettimeofday
is possible
through this library on this system, and false
otherwise.true
if JNR C library is loaded and a call to gettimeofday
is possible.public static boolean isGetpidAvailable()
true
if JNR POSIX library is loaded and a call to getpid
is possible
through this library on this system, and false
otherwise.true
if JNR POSIX library is loaded and a call to getpid
is possible.public static boolean isPlatformAvailable()
true
if JNR Platform
class is loaded, and false
otherwise.true
if JNR Platform
class is loaded.public static long currentTimeMicros()
gettimeofday
, through JNR C library.UnsupportedOperationException
- if JNR C library is not loaded or gettimeofday
is
not available.IllegalStateException
- if the call to gettimeofday
did not complete with return
code 0.public static int processId()
getpid
.UnsupportedOperationException
- if JNR POSIX library is not loaded or getpid
is
not available.public static String getCPU()
Platform.getCPU()
.UnsupportedOperationException
- if JNR Platform library is not loaded.Copyright © 2012–2019. All rights reserved.