Class SystemState

java.lang.Object
edu.wisc.ssec.mcidasv.util.SystemState

public class SystemState extends Object
Utility methods for querying the state of the user's machine.
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
      Handy logging object.
  • Constructor Details

  • Method Details

    • escapeWhitespaceChars

      public static String escapeWhitespaceChars(CharSequence sequence)
    • queryPlatformBean

      private static <T> T queryPlatformBean(String attrName, T defaultValue)
      Query an OperatingSystemMXBean attribute and return the result.
      Type Parameters:
      T - Type of the expected return value and defaultValue.
      Parameters:
      attrName - Name of the OperatingSystemMXBean attribute to query. Cannot be null or empty.
      defaultValue - Value returned if attrName could not be queried.
      Returns:
      Either the value corresponding to attrName or defaultValue.
    • queryJythonProps

      public static Map<Object,Object> queryJythonProps()
      Returns the contents of Jython's registry (basically just Jython-specific properties) as well as some of the information from Python's "sys" module.
      Returns:
      Jython's configuration settings.
    • queryOpSysProps

      public static Map<String,String> queryOpSysProps()
      Attempts to call methods belonging to com.sun.management.OperatingSystemMXBean. If successful, we'll have the following information:
      • opsys.memory.virtual.committed: virtual memory that is guaranteed to be available
      • opsys.memory.swap.total: total amount of swap space in bytes
      • opsys.memory.swap.free: free swap space in bytes
      • opsys.cpu.time: CPU time used by the process (nanoseconds)
      • opsys.memory.physical.free: free physical memory in bytes
      • opsys.memory.physical.total: physical memory in bytes
      • opsys.load: system load average for the last minute
      Returns:
      Map of properties that contains interesting information about the hardware McIDAS-V is using.
    • queryMachine

      public static Map<String,String> queryMachine()
      Polls Java for information about the user's machine. We're specifically after memory statistics, number of processors, and display information.
      Returns:
      Map of properties that describes the user's machine.
    • getDisplayBounds

      Returns a mapping of display number to a Rectangle that represents the "bounds" of the display.
      Returns:
      Rectangles representing the "bounds" of the current display devices.
    • getVirtualDisplayBounds

    • queryJava3d

      public static Map<String,Object> queryJava3d()
      Polls Java 3D for information about its environment. Specifically, we call VirtualUniverse.getProperties() and Canvas3D.queryProperties().
      Returns:
      As much information as Java 3D can provide.
    • getIdvVersionString

      public static String getIdvVersionString()
      Gets a human-friendly representation of the information embedded within IDV's build.properties.
      Returns:
      String that looks like "IDV version major.minor<b>revision</b> built <b>date</b>". For example: IDV version 2.9u4 built 2011-04-13 14:01 UTC.
    • getMcvVersionString

      public static String getMcvVersionString()
      Gets a human-friendly representation of the information embedded within McIDAS-V's build.properties.
      Returns:
      String that looks like "McIDAS-V version major.minor<b>release</b> built <b>date</b>". For example: McIDAS-V version 1.02beta1 built 2011-04-14 17:36.
    • getVisadVersionString

      public static String getVisadVersionString()
      Gets a human-friendly representation of the version information embedded within VisAD's "DATE" file.
      Returns:
      String that looks "VisAD version <b>revision</b> built <b>date</b>". For example: VisAD version 5952 built Thu Mar 22 13:01:31 CDT 2012.
    • getNcidvVersionString

      public static String getNcidvVersionString()
      Gets a human-friendly representation of the ncIdv.jar version information.
      Returns:
      String that looks like "netCDF-Java version <b>revision</b> <b>built</b>".
    • resourceAsStream

      private static InputStream resourceAsStream(String name)
      Open a file for reading.
      Parameters:
      name - File to open.
      Returns:
      InputStream used to read name, or null if name could not be found.
    • queryVisadBuildProperties

      Returns a Map containing any relevant version information.

      Currently this information consists of the date visad.jar was built, as well as the (then-current) Subversion revision number.

      Returns:
      Map of the contents of VisAD's DATE file.
    • getMcvJarname

      private static String getMcvJarname(String jarDir) throws IOException
      Determine the actual name of the McIDAS-V JAR file.

      This is needed because we're now following the Maven naming convention, and this means that "mcidasv.jar" no longer exists.

      Parameters:
      jarDir - Directory containing all of the McIDAS-V JARs. Cannot be null.
      Returns:
      Name (note: not path) of the McIDAS-V JAR file.
      Throws:
      IOException - if there was a problem locating the McIDAS-V JAR.
    • getMcvJarClasspath

      public static List<String> getMcvJarClasspath()
      Return McIDAS-V's classpath.

      This may differ from what is reported by System.getProperty("java.class.path"). This is because McIDAS-V specifies its classpath using META-INF/MANIFEST.MF in mcidasv.jar.

      This is used by console_init.py to figure out where the VisAD, IDV, and McIDAS-V JAR files are located.

      Returns:
      Either a list of strings containing the path to each JAR file in the classpath, or an empty list.
    • queryNcidvBuildProperties

      Returns a Map containing version and buildDate keys.
      Returns:
      Map containing netCDF-Java version and build date.
    • queryIdvBuildProperties

      Returns a Map of the (currently) most useful contents of ucar/unidata/idv/resources/build.properties.

      Consider the output of getIdvVersionString(); it's built with the the following:

      • idv.version.major: currently "3"
      • idv.version.minor: currently "0"
      • idv.version.revision: currently "u2"}
      • idv.build.date: varies pretty frequently, as it's the build timestamp for idv.jar
      Returns:
      A Map of at least the useful parts of build.properties.
    • queryMcvBuildProperties

      Returns a Map of the (currently) most useful contents of edu/wisc/ssec/mcidasv/resources/build.properties.

      Consider the output of getMcvVersionString(); it's built with the the following:

      • mcidasv.version.major: currently "1"
      • mcidasv.version.minor: currently "02"
      • mcidasv.version.release: currently "beta1"
      • mcidasv.build.date: varies pretty frequently, as it's the build timestamp for mcidasv.jar.
      Returns:
      A Map of at least the useful parts of build.properties.
    • queryMcvState

      public static Map<String,Object> queryMcvState(McIDASV mcv)
      Queries McIDAS-V for information about its state. There's not a good way to characterize what we're interested in, so let's leave it at "whatever seems useful".
      Parameters:
      mcv - The McIDASV "god" object.
      Returns:
      Information about the state of McIDAS-V.
    • getStateAsString

      public static String getStateAsString(McIDASV mcv)
      Builds a (filtered) subset of the McIDAS-V system properties and returns the results as a String.
      Parameters:
      mcv - The McIDASV "god" object.
      Returns:
      The McIDAS-V system properties in the following format: KEY=VALUE\n. This is so we kinda-sorta conform to the standard Properties file format.
      See Also:
    • getStateAsString

      public static String getStateAsString(McIDASV mcv, boolean firehose)
      Builds the McIDAS-V system properties and returns the results as a String.
      Parameters:
      mcv - The McIDASV "god" object.
      firehose - If true, enables "unfiltered" output.
      Returns:
      The McIDAS-V system properties in the following format: KEY=VALUE\n. This is so we kinda-sorta conform to the standard Properties file format.