Package org.agrona

Class SystemUtil

java.lang.Object
org.agrona.SystemUtil

public final class SystemUtil extends Object
Utilities for inspecting the system.
  • Field Details

    • PID_NOT_FOUND

      public static final long PID_NOT_FOUND
      PID value if a process id could not be determined. This value should be equal to a kernel only process id for the platform so that it does not indicate a real process id.
      See Also:
    • NULL_PROPERTY_VALUE

      public static final String NULL_PROPERTY_VALUE
      Value a System.getProperties() can be set to so that null will be returned as if the property was not set.
      See Also:
    • SUN_PID_PROP_NAME

      private static final String SUN_PID_PROP_NAME
      See Also:
    • MAX_G_VALUE

      private static final long MAX_G_VALUE
      See Also:
    • MAX_M_VALUE

      private static final long MAX_M_VALUE
      See Also:
    • MAX_K_VALUE

      private static final long MAX_K_VALUE
      See Also:
    • OS_NAME

      private static final String OS_NAME
    • OS_ARCH

      private static final String OS_ARCH
    • PID

      private static final long PID
  • Constructor Details

    • SystemUtil

      private SystemUtil()
  • Method Details

    • osName

      public static String osName()
      Get the name of the operating system as a lower case String.

      This is what is returned from System.getProperty("os.name").toLowerCase().

      Returns:
      the name of the operating system as a lower case String.
    • osArch

      public static String osArch()
      Returns the name of the operating system architecture.

      This is the same a calling the System.getProperty("os.arch", "unknown").

      Returns:
      name of the operating system architecture or unknown.
    • getPid

      public static long getPid()
      Return the current process id from the OS.
      Returns:
      current process id or PID_NOT_FOUND if PID was not found.
      See Also:
    • isWindows

      public static boolean isWindows()
      Is the operating system likely to be Windows based on osName().
      Returns:
      true if the operating system is likely to be Windows based on osName().
    • isLinux

      public static boolean isLinux()
      Is the operating system likely to be Linux based on osName().
      Returns:
      true if the operating system is likely to be Linux based on osName().
    • isX64Arch

      public static boolean isX64Arch()
      Is the operating system architecture (osArch()) represents an x86-based system.
      Returns:
      true if the operating system architecture represents an x86-based system.
    • isDebuggerAttached

      public static boolean isDebuggerAttached()
      Is a debugger attached to the JVM?
      Returns:
      true if attached otherwise false.
    • tmpDirName

      public static String tmpDirName()
      The system property for java.io.tmpdir and ensuring a File.separator is at the end.
      Returns:
      tmp directory for the runtime.
    • threadDump

      public static String threadDump()
      Get a formatted dump of all threads with associated state and stack traces.
      Returns:
      a formatted dump of all threads with associated state and stack traces.
    • threadDump

      public static void threadDump(StringBuilder sb)
      Write a formatted dump of all threads with associated state and stack traces to a provided StringBuilder.
      Parameters:
      sb - to write the thread dump to.
    • loadPropertiesFile

      public static void loadPropertiesFile(String filenameOrUrl)
      Load system properties from a given filename or url with default to PropertyAction.REPLACE.

      File is first searched for in resources using the system ClassLoader, then file system, then URL. All are loaded if multiples found.

      Parameters:
      filenameOrUrl - that holds properties.
    • loadPropertiesFile

      public static void loadPropertiesFile(PropertyAction propertyAction, String filenameOrUrl)
      Load system properties from a given filename or url.

      File is first searched for in resources using the system ClassLoader, then file system, then URL. All are loaded if multiples found.

      Parameters:
      propertyAction - to take with each loaded property.
      filenameOrUrl - that holds properties.
    • loadPropertiesFiles

      public static void loadPropertiesFiles(String... filenamesOrUrls)
      Load system properties from a given set of filenames or URLs with default to PropertyAction.REPLACE.
      Parameters:
      filenamesOrUrls - that holds properties.
      See Also:
    • loadPropertiesFiles

      public static void loadPropertiesFiles(PropertyAction propertyAction, String... filenamesOrUrls)
      Load system properties from a given set of filenames or URLs.
      Parameters:
      propertyAction - to take with each loaded property.
      filenamesOrUrls - that holds properties.
      See Also:
    • getProperty

      public static String getProperty(String propertyName)
      Get the value of a System.getProperty(String) with the exception that if the value is NULL_PROPERTY_VALUE then return null.
      Parameters:
      propertyName - to get the value for.
      Returns:
      the value of a System.getProperty(String) with the exception that if the value is NULL_PROPERTY_VALUE then return null.
    • getProperty

      public static String getProperty(String propertyName, String defaultValue)
      Get the value of a System.getProperty(String, String) with the exception that if the value is NULL_PROPERTY_VALUE then return null, otherwise if the value is not set then return the default value.
      Parameters:
      propertyName - to get the value for.
      defaultValue - to use if the property is not set.
      Returns:
      the value of a System.getProperty(String, String) with the exception that if the value is NULL_PROPERTY_VALUE then return null, otherwise if the value is not set then return the default value.
    • getSizeAsInt

      public static int getSizeAsInt(String propertyName, int defaultValue)
      Get a size value as an int from a system property. Supports a 'g', 'm', and 'k' suffix to indicate gigabytes, megabytes, or kilobytes respectively.
      Parameters:
      propertyName - to lookup.
      defaultValue - to be applied if the system property is not set.
      Returns:
      the int value.
      Throws:
      NumberFormatException - if the value is out of range or mal-formatted.
    • getSizeAsLong

      public static long getSizeAsLong(String propertyName, long defaultValue)
      Get a size value as a long from a system property. Supports a 'g', 'm', and 'k' suffix to indicate gigabytes, megabytes, or kilobytes respectively.
      Parameters:
      propertyName - to lookup.
      defaultValue - to be applied if the system property is not set.
      Returns:
      the long value.
      Throws:
      NumberFormatException - if the value is out of range or mal-formatted.
    • parseSize

      public static long parseSize(String propertyName, String propertyValue)
      Parse a string representation of a value with optional suffix of 'g', 'm', and 'k' suffix to indicate gigabytes, megabytes, or kilobytes respectively.
      Parameters:
      propertyName - that associated with the size value.
      propertyValue - to be parsed.
      Returns:
      the long value.
      Throws:
      NumberFormatException - if the value is out of range or mal-formatted.
    • getDurationInNanos

      public static long getDurationInNanos(String propertyName, long defaultValue)
      Get a string representation of a time duration with an optional suffix of 's', 'ms', 'us', or 'ns' suffix to indicate seconds, milliseconds, microseconds, or nanoseconds respectively.

      If the resulting duration is greater than Long.MAX_VALUE then Long.MAX_VALUE is used.

      Parameters:
      propertyName - associated with the duration value.
      defaultValue - to be used if the property is not present.
      Returns:
      the long value.
      Throws:
      NumberFormatException - if the value is negative or malformed.
    • parseDuration

      public static long parseDuration(String propertyName, String propertyValue)
      Parse a string representation of a time duration with an optional suffix of 's', 'ms', 'us', or 'ns' to indicate seconds, milliseconds, microseconds, or nanoseconds respectively.

      If the resulting duration is greater than Long.MAX_VALUE then Long.MAX_VALUE is used.

      Parameters:
      propertyName - associated with the duration value.
      propertyValue - to be parsed.
      Returns:
      the long value.
      Throws:
      NumberFormatException - if the value is negative or malformed.
    • isX64Arch

      static boolean isX64Arch(String arch)
    • loadProperties

      private static void loadProperties(PropertyAction propertyAction, InputStream in) throws IOException
      Throws:
      IOException