Package org.jppf.process
Class AbstractProcessLauncher
java.lang.Object
org.jppf.utils.concurrent.ThreadSynchronization
org.jppf.process.AbstractProcessLauncher
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
ProcessLauncher
This class wraps a single slave node process and provides an API to start, stop and monitor it.
- Since:
- 5.0
- Author:
- Laurent Cohen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAccepts a connection from the child process and sends process commands as int values via the connection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIffalsethen process is to be restarted.protected final List<ProcessLauncherListener>The registered listeners.protected StringName given to this process, also used as root installation directory.protected ProcessA reference to the JPPF subprocess, used to kill it when tis launcher exits.protected intThe port number the server socket listens to.protected ServerSocketThe server socket the node listens to.Wraps the socket accepted from the node process.Fields inherited from class org.jppf.utils.concurrent.ThreadSynchronization
stopped -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a listener to the list of listeners.protected StringbuildClasspath(List<String> cpElements) Build the ful classpath based onthe current process's classpath and the provided classpath elements.protected StringcomputeJavaExecPath(TypedProperties config) Compute the path to the Java executable, based on the JPPF configuration.protected ThreadCreate a shutdown hook that is run when this JVM terminates.
This is normally used to ensure the subprocess is terminated as well.protected voidNotify all listeners that the process has started.protected voidfireProcessStopped(boolean clearListeners) Notify all listeners that the process has stopped.getName()Get the name given to this process.protected abstract booleanonProcessExit(int n) Called when the subprocess has exited with exit value n.parseJvmOptions(String source) Parse the specified String as a list of JVM options.voidRemove a listener from the list of listeners.voidsendActionCommand(int action) Send an action command to the slave node.protected intStart 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 constructornew 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 theServerSocket.accept()and theSocket.getInputStream().read()in the same thread.voidtearDown()Forcibly terminate the process.Methods inherited from class org.jppf.utils.concurrent.ThreadSynchronization
goToSleep, goToSleep, goToSleep, isStopped, setStopped, wakeUp
-
Field Details
-
process
A reference to the JPPF subprocess, used to kill it when tis launcher exits. -
processServer
The server socket the node listens to. -
processPort
protected int processPortThe port number the server socket listens to. -
slaveSocketWrapper
Wraps the socket accepted from the node process.- Since:
- 5.0
-
listeners
The registered listeners. -
name
Name given to this process, also used as root installation directory. -
end
protected boolean endIffalsethen process is to be restarted.
-
-
Constructor Details
-
AbstractProcessLauncher
public AbstractProcessLauncher()
-
-
Method Details
-
parseJvmOptions
Parse the specified String as a list of JVM options.- Parameters:
source- the string to parse.- Returns:
- A list of jvm options.
-
buildClasspath
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 constructornew 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 theServerSocket.accept()and theSocket.getInputStream().read()in the same thread.- Returns:
- the port number on which the server socket is listening.
-
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
Get the name given to this process.- Returns:
- the name as a string.
-
addProcessLauncherListener
Add a listener to the list of listeners.- Parameters:
listener- the listener to add.
-
removeProcessLauncherListener
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-trueto remove all listeners,falseto 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
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
- Returns:
- a reference to the JPPF subprocess, used to kill it when tis launcher exits.
-