Class ProcessUtils

java.lang.Object
com.sun.enterprise.universal.process.ProcessUtils

public final class ProcessUtils extends Object
Includes a somewhat kludgy way to get the pid for "me". Another casualty of the JDK catering to the LEAST common denominator. Some obscure OS might not have a pid! The name returned from the JMX method is like so: 12345
Author:
bnevins, David Matejcek
  • Method Details

    • getExe

      public static File getExe(String name)
      Look for name in the Path. If it is found and if it is executable then return a File object pointing to it. Otherwise return nu
      Parameters:
      name - the name of the file with no path
      Returns:
      the File object or null
    • saveCurrentPid

      public static void saveCurrentPid(File pidFile) throws IOException
      Saves current pid file to the file.
      Parameters:
      pidFile -
      Throws:
      IOException
    • isAlive

      public static boolean isAlive(File pidFile)
      Parameters:
      pidFile -
      Returns:
      true if the pid file exists and the process with the pid inside is alive.
    • isAlive

      public static boolean isAlive(long pid)
    • loadPid

      public static long loadPid(File pidFile) throws IllegalArgumentException
      Parameters:
      pidFile - existing file containing pid.
      Returns:
      pid from the file
      Throws:
      IllegalArgumentException - non-existing, empty or unparseable file
    • isListening

      public static boolean isListening(HostAndPort endpoint)
      Parameters:
      endpoint - endpoint host and port to use.
      Returns:
      true if the endpoint is listening on socket
    • kill

      public static void kill(File pidFile, File watchedPidFile, Duration timeout, boolean printDots) throws KillNotPossibleException, KillTimeoutException
      Kill the process with the given Process ID and wait until it's gone - that means that the watchedPidFile is deleted OR the process is not resolved as alive by the ProcessHandle.isAlive() OR we cannot retrieve the command line of the process via ProcessHandle.Info.commandLine().
      Parameters:
      pidFile - - used to load pid
      watchedPidFile - - if this file vanish, we expect that the process stopped.
      timeout - - timeout to wait until to meet conditions meaning that the process stopped
      printDots - - print one dot per second when waiting.
      Throws:
      KillNotPossibleException - It wasn't possible to send the kill signal to the process.
      KillTimeoutException - Signal was sent, but process is still alive after the timeout.
    • waitFor

      public static boolean waitFor(Supplier<Boolean> sign, Duration timeout, boolean printDots)
      Parameters:
      sign - logic defining what we are waiting for.
      timeout -
      printDots - print dot each second and new line in the end.
      Returns:
      true if the sign returned true before timeout.