Class ToolServices

java.lang.Object
noaa.coastwatch.tools.ToolServices

public class ToolServices extends Object
The tool services class defines various static methods relating to the CoastWatch tools.
Since:
3.1.2
Author:
Peter Hollemans
  • Field Details

  • Method Details

    • startExecution

      public static void startExecution(String name)
      Logs a starting time for an executable task.
      Parameters:
      name - the name of the task starting.
      Since:
      3.5.0
    • finishExecution

      public static void finishExecution(String name)
      Logs a finishing time for a executable task.
      Parameters:
      name - the name of the task finishing.
      Since:
      3.5.0
    • setSystemExit

      public static void setSystemExit(boolean flag)
      Sets the system exit flag.
      Parameters:
      flag - the exit flag, true to actually exit the system on a call to exitWithCode(int) or false to not.
      Since:
      3.5.0
    • getAbout

      public static String getAbout(String tool)
      Gets an about string appropriate for an about dialog box.
      Parameters:
      tool - the tool or program name.
      Returns:
      the about string.
    • getSplash

      public static String getSplash(String tool)
      Gets a string appropriate for a splash screen annotation.
      Parameters:
      tool - the tool or program name.
      Returns:
      the splash screen string.
    • getVersion

      public static String getVersion()
      Gets a simple version string.
      Returns:
      the version string, for example "3.2.2".
    • getToolVersion

      public static String getToolVersion(String tool)
      Gets a tool version string.
      Parameters:
      tool - the tool or program name.
      Returns:
      the tool version string, for example "[cwutils 3.2.2] cwrender".
    • getJavaVersion

      public static String getJavaVersion()
      Gets a Java runtime and OS version.
    • getFullVersion

      public static String getFullVersion(String tool)
      Gets a full tool and Java runtime version string for printing on the command line.
      Parameters:
      tool - the tool or program name.
      Returns:
      the full version string.
    • setCommandLine

      public static void setCommandLine(String command, String[] argv)
      Sets the current tool command line. This method should be called by all tools at the beginning of main() so that other classes may retrieve the current command line via getCommandLine(). This is especially important for tools that create new data files, so that writers can insert the command line into the data file history.
      Parameters:
      command - the command or program name. If this is a class name, only the final part of the class name is retained as the program name.
      argv - an array of command line arguments.
    • getCommandLine

      public static String getCommandLine()
      Gets the current tool command line, or null if none has been set.
    • startMemoryMonitor

      public static void startMemoryMonitor(int interval)
      Starts a memory monitor task that repeatedly outputs the status of memory usage to standard output until the VM exits.
      Parameters:
      interval - the interval in seconds for the memory status message.
      Since:
      3.8.1
    • startMemoryMonitor

      public static void startMemoryMonitor()
      Starts a memory monitor task that repeatedly outputs the status of memory usage to standard output until the VM exits.
    • getSplitRegex

      public static String getSplitRegex()
      Gets the current command line parameter splitting regular expression.
      Returns:
      the current splitting expression.
    • setSplitRegex

      public static void setSplitRegex(String expr)
      Sets the current command line parameter splitting regular expression.
      Parameters:
      expr - the new splitting expression.
    • checkSetup

      public static String checkSetup()
      Checks the setup of tool services.
      Returns:
      an error string if any issues encountered, or null if none.
    • exitWithCode

      public static void exitWithCode(int code)
      Performs an exit of a tool with the specified code. The exit may be a system exit, or a soft exit depending on the exit mode. The default is to actually perform a system exit.
      Parameters:
      code - the code to use for exiting.
      Since:
      3.5.0
      See Also:
    • warnOutOfMemory

      public static void warnOutOfMemory(Throwable th)
      Logs a warning to the user if the throwable or any of its causes is an OutOfMemory error.
      Parameters:
      th - the throwable to check.
      Since:
      3.5.1
    • shortTrace

      public static Throwable shortTrace(Throwable error, String prefix)
      Shortens the stack trace contained in a throwable error so that it ends at the mention of a specific class. If the thowable has a non-null cause, it is modified as well.
      Parameters:
      error - the throwable to check.
      prefix - the prefix of the class name to look for. Any stack trace elements after the last one that contains the prefix are removed.
      Returns:
      the throwable error passed in, for convenience.
      Since:
      3.7.1