Class AbstractProcessLauncher

java.lang.Object
org.jppf.utils.concurrent.ThreadSynchronization
org.jppf.process.AbstractProcessLauncher
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ProcessLauncher

public abstract class AbstractProcessLauncher extends ThreadSynchronization implements Runnable
This class wraps a single slave node process and provides an API to start, stop and monitor it.
Since:
5.0
Author:
Laurent Cohen
  • Field Details

    • process

      protected Process process
      A reference to the JPPF subprocess, used to kill it when tis launcher exits.
    • processServer

      protected ServerSocket processServer
      The server socket the node listens to.
    • processPort

      protected int processPort
      The port number the server socket listens to.
    • slaveSocketWrapper

      protected AbstractProcessLauncher.SlaveSocketWrapper slaveSocketWrapper
      Wraps the socket accepted from the node process.
      Since:
      5.0
    • listeners

      protected final List<ProcessLauncherListener> listeners
      The registered listeners.
    • name

      protected String name
      Name given to this process, also used as root installation directory.
    • end

      protected boolean end
      If false then process is to be restarted.
  • Constructor Details

    • AbstractProcessLauncher

      public AbstractProcessLauncher()
  • Method Details

    • parseJvmOptions

      protected Pair<List<String>,List<String>> parseJvmOptions(String source)
      Parse the specified String as a list of JVM options.
      Parameters:
      source - the string to parse.
      Returns:
      A list of jvm options.
    • buildClasspath

      protected String buildClasspath(List<String> cpElements)
      Build the ful classpath based onthe current process's classpath and the provided classpath elements.
      Parameters:
      cpElements - the classpath elements to add to the classpath of the current process
      Returns:
      a classpath string using the platform's path separator, eventually anclosed within double quotes if any class path element contains one or more spaces.
    • tearDown

      public void tearDown()
      Forcibly terminate the process.
    • onProcessExit

      protected abstract boolean onProcessExit(int n)
      Called when the subprocess has exited with exit value n. This allows for printing the residual output (both standard and error) to this pJVM's console and log file, in order to get additional information if a problem occurred.
      Parameters:
      n - the exit value of the subprocess.
      Returns:
      true if this launcher is to be terminated, false if it should re-launch the subprocess.
    • startSocketListener

      protected int startSocketListener()
      Start a server socket that will accept one connection at a time with the JPPF driver, so the server can shutdown properly, when this driver is killed, by a way other than the API (ie CTRL-C or killing the process through the OS shell).
      The port the server socket listens to is dynamically attributed, which is obtained by using the constructor new ServerSocket(0).
      The driver will connect and listen to this port, and exit when the connection is broken.
      The single connection at a time is obtained by doing the ServerSocket.accept() and the Socket.getInputStream().read() in the same thread.
      Returns:
      the port number on which the server socket is listening.
    • createShutdownHook

      protected Thread createShutdownHook()
      Create a shutdown hook that is run when this JVM terminates.
      This is normally used to ensure the subprocess is terminated as well.
      Returns:
      the created shutdown hook.
    • getName

      public String getName()
      Get the name given to this process.
      Returns:
      the name as a string.
    • addProcessLauncherListener

      public void addProcessLauncherListener(ProcessLauncherListener listener)
      Add a listener to the list of listeners.
      Parameters:
      listener - the listener to add.
    • removeProcessLauncherListener

      public void removeProcessLauncherListener(ProcessLauncherListener listener)
      Remove a listener from the list of listeners.
      Parameters:
      listener - the listener to remove.
    • fireProcessStarted

      protected void fireProcessStarted()
      Notify all listeners that the process has started.
    • fireProcessStopped

      protected void fireProcessStopped(boolean clearListeners)
      Notify all listeners that the process has stopped.
      Parameters:
      clearListeners - true to remove all listeners, false to keep them.
    • sendActionCommand

      public void sendActionCommand(int action)
      Send an action command to the slave node.
      Parameters:
      action - the code of the action command to send.
    • computeJavaExecPath

      protected String computeJavaExecPath(TypedProperties config)
      Compute the path to the Java executable, based on the JPPF configuration.

      if the property "jppf.java.path" is defined, then it will be used, otherwise the value of the system property "java.home" will be used with a "/bin/java" suffix.

      Parameters:
      config - the configuration to use.
      Returns:
      the full path to the java executable.
    • getProcess

      public Process getProcess()
      Returns:
      a reference to the JPPF subprocess, used to kill it when tis launcher exits.