Class 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:

    1. 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);
    2. 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).

    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().

    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 Detail

      • Native

        public Native()
    • Method Detail

      • isGettimeofdayAvailable

        public 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.
        Returns:
        true if JNR C library is loaded and a call to gettimeofday is possible.
      • isGetpidAvailable

        public 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.
        Returns:
        true if JNR POSIX library is loaded and a call to getpid is possible.
      • currentTimeMicros

        public static long currentTimeMicros()
        Returns the current timestamp with microsecond precision via a system call to gettimeofday, through JNR C library.
        Returns:
        the current timestamp with microsecond precision.
        Throws:
        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.
      • processId

        public static int processId()
        Returns the JVM's process identifier (PID) via a system call to getpid.
        Returns:
        the JVM's process identifier (PID).
        Throws:
        UnsupportedOperationException - if JNR POSIX library is not loaded or getpid is not available.