java.lang.Object
de.iip_ecosphere.platform.configuration.maven.ProcessUnit

public class ProcessUnit extends Object
Represents a process.
Author:
Holger Eichelberger, SSE
  • Field Details

    • PROP_MAVEN_BIN

      public static final String PROP_MAVEN_BIN
      See Also:
    • SCRIPT_NAMES

      public static final Set<String> SCRIPT_NAMES
    • WIN_BAT_PREFIX

      public static final String[] WIN_BAT_PREFIX
    • UNKOWN_EXIT_STATUS

      public static final int UNKOWN_EXIT_STATUS
      See Also:
    • timer

      private static Timer timer
    • description

      private String description
    • process

      private Process process
    • timeoutTask

      private TimerTask timeoutTask
    • closeables

      private List<Closeable> closeables
    • logMatches

      private boolean logMatches
    • checkRegEx

      private List<Pattern> checkRegEx
    • logger

      private de.iip_ecosphere.platform.tools.maven.python.Logger logger
    • listener

  • Constructor Details

    • ProcessUnit

      private ProcessUnit(String description, Process process, long timeout, ProcessUnit.TerminationListener listener, List<Pattern> checkRegEx, de.iip_ecosphere.platform.tools.maven.python.Logger logger)
      Creates a process unit.
      Parameters:
      description - the description
      process - the process being executed
      timeout - maximum lifetime of process in milliseconds, ignored if not positive
      listener - optional listener to be called when the execution/testing termination is reached, null for none
      checkRegEx - the regular expressions to be applied to the log output
      logger - the logging instance
  • Method Details

    • attach

      private void attach(ProcessUnit.InputStreamHandler handler)
      Attaches a handler.
      Parameters:
      handler - the handler to be attached
    • attach

      private void attach(Closeable closeable)
      Attaches a closeable.
      Parameters:
      closeable - the closeable to attache
    • notifyLogMatches

      private void notifyLogMatches(boolean terminateByLogMatch)
      Called when there is a log-regex matching result.
      Parameters:
      terminateByLogMatch - terminate the process by a log match or not
    • handleListenerNotification

      private void handleListenerNotification(ProcessUnit.TerminationReason reason)
      Handles a listener notification and decides about stopping the process, either as the reason requires immediate stop or as the listener decides.
      Parameters:
      reason - the reason for the notification.
    • getLogMatches

      public boolean getLogMatches()
      Returns whether the regular expressions for process logging specified during creation matched so far.
      Returns:
      true for match, false else (default)
    • getExitValue

      public int getExitValue()
      Returns the exit status of the contained process. Only returns a value if the process came to an end by itself, i.e., not terminated by a timeout or by a log match.
      Returns:
      the process exit value, UNKOWN_EXIT_STATUS for unknown
    • isFailed

      public static boolean isFailed(int status)
      Returns whether a process failed (status is not UNKOWN_EXIT_STATUS and not 0).
      Parameters:
      status - the status to check
      Returns:
      true if failed, false may be running, not started or successful
    • isSuccess

      public static boolean isSuccess(int status)
      Returns whether a process failed (status is not UNKOWN_EXIT_STATUS and 0).
      Parameters:
      status - the status to check
      Returns:
      true if successful, false if running, not started or failed
    • getMavenBinPath

      public static String getMavenBinPath()
      Returns the maven bin folder via PROP_MAVEN_BIN.
      Returns:
      the maven bin folder, may be null
    • getDescription

      public String getDescription()
      Returns the description of the unit.
      Returns:
      the description
    • getCheckRegEx

      public List<Pattern> getCheckRegEx()
      Returns the check regEx of this unit.
      Returns:
      the regEx, may be null
    • hasCheckRegEx

      public boolean hasCheckRegEx()
      Returns whether this unit has regEx to check.
      Returns:
      true if there are regEx, false else
    • isRunning

      public boolean isRunning()
      Returns whether the contained process is (still) running.
      Returns:
      true if the process is running, false else
    • waitFor

      public int waitFor()
      Waits for the process to end if it has been started.
      Returns:
      the process exit value
    • splitPath

      private static void splitPath(Consumer<String> pathEltConsumer)
      Splits the OS path into path elements.
      Parameters:
      pathEltConsumer - the element consumer
    • stop

      public int stop()
      Stops the process.
      Returns:
      the exit status