Class SystemUtils

java.lang.Object
org.jppf.utils.SystemUtils

public final class SystemUtils extends Object
Collection of utility methods used as a convenience for retrieving JVM-level or System-level information.
Author:
Laurent Cohen
  • Method Details

    • getSystemProperties

      public static TypedProperties getSystemProperties()
      Return a set of properties guaranteed to always be part of those returned by System.getProperties().
      Returns:
      the properties as a TypedProperties instance.
    • getRuntimeInformation

      public static TypedProperties getRuntimeInformation()
      Get information about the number of processors available to the JVM and the JVM memory usage.
      Returns:
      a TypedProperties instance holding the requested information.
    • getStorageInformation

      public static TypedProperties getStorageInformation()
      Get storage information about the file system roots available on the current host. This method populates a TypedProperties object with root name, free space, total space and usable space information for each root.

      An example root name would be "C:\" for a Windows system and "/" for a Unix system.

      Returns:
      TypedProperties object with storage information.
    • getEnvironment

      public static TypedProperties getEnvironment()
      Get a map of the environment variables.
      Returns:
      a mapping of environment variables to their value.
    • getNetwork

      public static TypedProperties getNetwork()
      Get a map of the environment variables.
      Returns:
      a mapping of environment variables to their value.
    • maxFreeHeap

      public static long maxFreeHeap()
      Compute the maximum memory currently available for the Java heap.
      Returns:
      the maximum number of free bytes in the heap.
    • heapUsage

      public static long heapUsage()
      Compute the used heap.
      Returns:
      the heap memory used in bytes.
    • heapUsagePct

      public static double heapUsagePct()
      Compute the percentage of used heap as compared to the maximum heap size of the JVM.
      Returns:
      the percentage of heap memory used.
    • isWindows

      public static boolean isWindows()
      Determine whether the current OS is Windows.
      Returns:
      true if the system is Windows, false otherwise.
    • isX11

      public static boolean isX11()
      Determine whether the current OS is X11-based.
      Returns:
      true if the system is X11, false otherwise.
    • isMac

      public static boolean isMac()
      Determine whether the current OS is Mac-based.
      Returns:
      true if the system is Mac-based, false otherwise.
    • getPID

      public static int getPID()
      Returns:
      the current process pid as an int, or -1 if the pid could not be obtained.
    • printPidAndUuid

      public static void printPidAndUuid(String component, String uuid)
      Prints the JPPF process id and uuid to System.out.
      Parameters:
      component - the JPPF component type: driver, node or client.
      uuid - the component uuid.
    • getOS

      public static TypedProperties getOS()
      Get the available physical ram information for the local machine.
      Returns:
      the memory information eelements as a TypedProperties instance.
    • getUsedMemory

      public static long getUsedMemory()
      Returns:
      the currently used heap memory.
    • getPctUsedMemory

      public static double getPctUsedMemory()
      Returns:
      the currently used heap memory.
    • isOneOf

      @SafeVarargs public static <T> boolean isOneOf(T value, T... possibles)
      Determine whether the specified value is one of the possibles.
      Type Parameters:
      T - the type of values to check.
      Parameters:
      value - the value to compare.
      possibles - the possible values to compare with
      Returns:
      true if value is one of the possibe values, false otherwise.
    • printSystemProperties

      public static String printSystemProperties()
      Print the system properties to a string.
      Returns:
      the system properties printed one per line.
    • getSystemIdentityName

      public static String getSystemIdentityName(Object o)
      Get a name for an object in the form simple_class_name@hex_identity_hashcode.
      Parameters:
      o - the object for which to get a name.
      Returns:
      the object's identity name.
    • getSystemIdentity

      public static String getSystemIdentity(Object o)
      Get a name for an object in the form class_fqn@hex_identity_hashcode.
      Parameters:
      o - the object for which to get a name.
      Returns:
      the object's identity name.
    • areEqual

      public static boolean areEqual(Object o1, Object o2)
      Determine whether 2 objects are equal.
      Parameters:
      o1 - the first object.
      o2 - the second object.
      Returns:
      true if the 2 objects are equal, false otherwise.