/** * If there is a native library available for the JVM's platform/operating system, <code>true</code> is returned. If * the JVM's platform does not have native libraries available, <code>false</code> is returned (in which case, the * only {@link SystemInfo} implementation that is available is {@link JavaSystemInfo}). * * @return <code>true</code> if there are native library APIs available for the JVM platform * @see JavaSystemInfo */ public static boolean isNativeSystemInfoAvailable() { initialize(); return nativeLibraryLoadable; }
/** * If there is a native library available for the JVM's platform/operating system, <code>true</code> is returned. If * the JVM's platform does not have native libraries available, <code>false</code> is returned (in which case, the * only {@link SystemInfo} implementation that is available is {@link JavaSystemInfo}). * * @return <code>true</code> if there are native library APIs available for the JVM platform * @see JavaSystemInfo */ public static boolean isNativeSystemInfoAvailable() { initialize(); return nativeLibraryLoadable; }
/** * Returns the appropriate {@link SystemInfo} implementation based on the platform/operating system the JVM is * running on. * * @return a {@link NativeSystemInfo} implementation or a {@link JavaSystemInfo} if the native libraries are * {@link #isNativeSystemInfoAvailable() not available for the platform} or have been * {@link #disableNativeSystemInfo() disabled}. */ public static synchronized SystemInfo createSystemInfo() { if (cachedSystemInfo == null) { initialize(); // make sure we've loaded the native libraries, if appropriate SystemInfo nativePlatform = null; if (!isNativeSystemInfoDisabled() && isNativeSystemInfoAvailable()) { // we could use SIGAR here, but this should be enough if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) { nativePlatform = new WindowsNativeSystemInfo(); } else { // we either don't know what OS it is or we don't have a specific native subclass for it; // but we know we have a native library for it! so just create the generic NativePlatform to represent it. nativePlatform = new NativeSystemInfo(); } } if (nativePlatform == null) { nativePlatform = javaSystemInfo; } cachedSystemInfo = nativePlatform; } return cachedSystemInfo; }
/** * Returns the appropriate {@link SystemInfo} implementation based on the platform/operating system the JVM is * running on. * * @return a {@link NativeSystemInfo} implementation or a {@link JavaSystemInfo} if the native libraries are * {@link #isNativeSystemInfoAvailable() not available for the platform} or have been * {@link #disableNativeSystemInfo() disabled}. */ public static synchronized SystemInfo createSystemInfo() { if (cachedSystemInfo == null) { initialize(); // make sure we've loaded the native libraries, if appropriate SystemInfo nativePlatform = null; if (!isNativeSystemInfoDisabled() && isNativeSystemInfoAvailable()) { // we could use SIGAR here, but this should be enough if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) { nativePlatform = new WindowsNativeSystemInfo(); } else { // we either don't know what OS it is or we don't have a specific native subclass for it; // but we know we have a native library for it! so just create the generic NativePlatform to represent it. nativePlatform = new NativeSystemInfo(); } } if (nativePlatform == null) { nativePlatform = javaSystemInfo; } cachedSystemInfo = nativePlatform; } return cachedSystemInfo; }
/** * If the native system is both {@link #isNativeSystemInfoAvailable() available} and * {@link #isNativeSystemInfoDisabled() enabled}, this will return the native system's version string. Otherwise, a * generic Java version message is returned. * * @return native system version string */ public static synchronized String getNativeSystemInfoVersion() { String version = null; Throwable error = null; initialize(); // make sure we've loaded the native libraries, if appropriate if (!isNativeSystemInfoDisabled() && isNativeSystemInfoAvailable()) { try { version = "Version=" + invokeApi(NativeApi.VERSION_STRING) + " (" + invokeApi(NativeApi.BUILD_DATE) + "); Native version=" + invokeApi(NativeApi.NATIVE_VERSION_STRING) + " (" + invokeApi(NativeApi.NATIVE_BUILD_DATE) + ")"; } catch (Throwable t) { error = t; } } if (version == null) { version = "Native system not supported - Java version is " + System.getProperty("java.version"); if (error != null) { version += " : " + error; } } return version; }
/** * If the native system is both {@link #isNativeSystemInfoAvailable() available} and * {@link #isNativeSystemInfoDisabled() enabled}, this will return the native system's version string. Otherwise, a * generic Java version message is returned. * * @return native system version string */ public static synchronized String getNativeSystemInfoVersion() { String version = null; Throwable error = null; initialize(); // make sure we've loaded the native libraries, if appropriate if (!isNativeSystemInfoDisabled() && isNativeSystemInfoAvailable()) { try { version = "Version=" + invokeApi(NativeApi.VERSION_STRING) + " (" + invokeApi(NativeApi.BUILD_DATE) + "); Native version=" + invokeApi(NativeApi.NATIVE_VERSION_STRING) + " (" + invokeApi(NativeApi.NATIVE_BUILD_DATE) + ")"; } catch (Throwable t) { error = t; } } if (version == null) { version = "Native system not supported - Java version is " + System.getProperty("java.version"); if (error != null) { version += " : " + error; } } return version; }