Package org.agrona
Class SystemUtil
java.lang.Object
org.agrona.SystemUtil
Utilities for inspecting the system.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
private static final long
private static final long
static final String
Value aSystem.getProperties()
can be set to so thatnull
will be returned as if the property was not set.private static final String
private static final String
private static final long
static final long
PID value if a process id could not be determined.private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static long
getPid()
Return the current process id from the OS.static String
getProperty
(String propertyName) Get the value of aSystem.getProperty(String)
with the exception that if the value isNULL_PROPERTY_VALUE
then returnnull
.static String
getProperty
(String propertyName, String defaultValue) Get the value of aSystem.getProperty(String, String)
with the exception that if the value isNULL_PROPERTY_VALUE
then returnnull
, otherwise if the value is not set then return the default value.static int
getSizeAsInt
(String propertyName, int defaultValue) Get a size value as an int from a system property.static long
getSizeAsLong
(String propertyName, long defaultValue) Get a size value as a long from a system property.static boolean
Is a debugger attached to the JVM?static boolean
isLinux()
Is the operating system likely to be Linux based onosName()
.static boolean
Is the operating system likely to be Windows based onosName()
.static boolean
Is the operating system architecture (osArch()
) represents an x86-based system.(package private) static boolean
private static void
loadProperties
(PropertyAction propertyAction, InputStream in) static void
loadPropertiesFile
(String filenameOrUrl) Load system properties from a given filename or url with default toPropertyAction.REPLACE
.static void
loadPropertiesFile
(PropertyAction propertyAction, String filenameOrUrl) Load system properties from a given filename or url.static void
loadPropertiesFiles
(String... filenamesOrUrls) Load system properties from a given set of filenames or URLs with default toPropertyAction.REPLACE
.static void
loadPropertiesFiles
(PropertyAction propertyAction, String... filenamesOrUrls) Load system properties from a given set of filenames or URLs.static String
osArch()
Returns the name of the operating system architecture.static String
osName()
Get the name of the operating system as a lower case String.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.static long
Parse a string representation of a value with optional suffix of 'g', 'm', and 'k' suffix to indicate gigabytes, megabytes, or kilobytes respectively.static String
Get a formatted dump of all threads with associated state and stack traces.static void
Write a formatted dump of all threads with associated state and stack traces to a providedStringBuilder
.static String
The system property forjava.io.tmpdir
and ensuring aFile.separator
is 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 thatnull
will be returned as if the property was not set.- See Also:
-
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
-
OS_ARCH
-
PID
private static final long PID
-
-
Constructor Details
-
SystemUtil
private SystemUtil()
-
-
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_FOUND
if PID was not found. - See Also:
-
isWindows
public static boolean isWindows()Is the operating system likely to be Windows based onosName()
.- Returns:
true
if 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:
true
if the operating system is likely to be Linux based onosName()
.
-
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
The system property forjava.io.tmpdir
and ensuring aFile.separator
is 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_VALUE
then 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_VALUE
then returnnull
.
-
getProperty
Get the value of aSystem.getProperty(String, String)
with the exception that if the value isNULL_PROPERTY_VALUE
then 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_VALUE
then 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_VALUE
thenLong.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
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
thenLong.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
-
loadProperties
private static void loadProperties(PropertyAction propertyAction, InputStream in) throws IOException - Throws:
IOException
-