Package org.agrona
Class SystemUtil
java.lang.Object
org.agrona.SystemUtil
Utilities for inspecting the system.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringValue aSystem.getProperties()can be set to so thatnullwill be returned as if the property was not set.static final longPID value if a process id could not be determined. -
Method Summary
Modifier and TypeMethodDescriptionstatic longgetDurationInNanos(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.static longgetPid()Return the current process id from the OS.static StringgetProperty(String propertyName) Get the value of aSystem.getProperty(String)with the exception that if the value isNULL_PROPERTY_VALUEthen returnnull.static StringgetProperty(String propertyName, String defaultValue) Get the value of aSystem.getProperty(String, String)with the exception that if the value isNULL_PROPERTY_VALUEthen returnnull, otherwise if the value is not set then return the default value.static intgetSizeAsInt(String propertyName, int defaultValue) Get a size value as an int from a system property.static longgetSizeAsLong(String propertyName, long defaultValue) Get a size value as a long from a system property.static booleanIs a debugger attached to the JVM?static booleanisLinux()Is the operating system likely to be Linux based onosName().static booleanisMac()Is the operating system likely to be macOS based onosName().static booleanIs the operating system likely to be Windows based onosName().static booleanIs the operating system architecture (osArch()) represents an x86-based system.static voidloadPropertiesFile(String filenameOrUrl) Load system properties from a given filename or url with default toPropertyAction.REPLACE.static voidloadPropertiesFile(PropertyAction propertyAction, String filenameOrUrl) Load system properties from a given filename or url.static voidloadPropertiesFiles(String... filenamesOrUrls) Load system properties from a given set of filenames or URLs with default toPropertyAction.REPLACE.static voidloadPropertiesFiles(PropertyAction propertyAction, String... filenamesOrUrls) Load system properties from a given set of filenames or URLs.static StringosArch()Returns the name of the operating system architecture.static StringosName()Get the name of the operating system as a lower case String.static longparseDuration(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.static longParse a string representation of a value with optional suffix of 'g', 'm', and 'k' suffix to indicate gigabytes, megabytes, or kilobytes respectively.static StringGet a formatted dump of all threads with associated state and stack traces.static voidWrite a formatted dump of all threads with associated state and stack traces to a providedStringBuilder.static StringThe system property forjava.io.tmpdirand ensuring aFile.separatoris at the end.
-
Field Details
-
PID_NOT_FOUND
public static final long PID_NOT_FOUNDPID 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
Value aSystem.getProperties()can be set to so thatnullwill be returned as if the property was not set.- See Also:
-
-
Method Details
-
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
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_FOUNDif PID was not found. - See Also:
-
isWindows
public static boolean isWindows()Is the operating system likely to be Windows based onosName().- Returns:
trueif the operating system is likely to be Windows based onosName().
-
isLinux
public static boolean isLinux()Is the operating system likely to be Linux based onosName().- Returns:
trueif the operating system is likely to be Linux based onosName().
-
isMac
public static boolean isMac()Is the operating system likely to be macOS based onosName().- Returns:
trueif the operating system is likely to be macOS based onosName().
-
isX64Arch
public static boolean isX64Arch()Is the operating system architecture (osArch()) represents an x86-based system.- Returns:
trueif the operating system architecture represents an x86-based system.
-
isDebuggerAttached
public static boolean isDebuggerAttached()Is a debugger attached to the JVM?- Returns:
trueif attached otherwise false.
-
tmpDirName
The system property forjava.io.tmpdirand ensuring aFile.separatoris at the end.- Returns:
- tmp directory for the runtime.
-
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
Write a formatted dump of all threads with associated state and stack traces to a providedStringBuilder.- Parameters:
sb- to write the thread dump to.
-
loadPropertiesFile
Load system properties from a given filename or url with default toPropertyAction.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
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
Load system properties from a given set of filenames or URLs with default toPropertyAction.REPLACE.- Parameters:
filenamesOrUrls- that holds properties.- See Also:
-
loadPropertiesFiles
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
Get the value of aSystem.getProperty(String)with the exception that if the value isNULL_PROPERTY_VALUEthen returnnull.- Parameters:
propertyName- to get the value for.- Returns:
- the value of a
System.getProperty(String)with the exception that if the value isNULL_PROPERTY_VALUEthen returnnull.
-
getProperty
Get the value of aSystem.getProperty(String, String)with the exception that if the value isNULL_PROPERTY_VALUEthen returnnull, 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 isNULL_PROPERTY_VALUEthen returnnull, otherwise if the value is not set then return the default value.
-
getSizeAsInt
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
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
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
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_VALUEthenLong.MAX_VALUEis 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
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_VALUEthenLong.MAX_VALUEis 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.
-