Package org.jppf.process
Class ProcessLauncher
java.lang.Object
org.jppf.utils.concurrent.ThreadSynchronization
org.jppf.process.AbstractProcessLauncher
org.jppf.process.ProcessLauncher
- All Implemented Interfaces:
Runnable,EventListener,IdleStateListener,ProcessWrapperEventListener
public class ProcessLauncher
extends AbstractProcessLauncher
implements ProcessWrapperEventListener, IdleStateListener
This class is intended as a controller for a subprocess, to enable stopping and restarting it when requested.
It performs the following operations:
- open a server socket the driver will listen to (port number is dynamically attributed)
- Start the subprocess, sending the server socket port number as an argument
- Wait for the subprocess to exit
- If the subprocess exit code is equal to 2, the subprocess is restarted, otherwise this process exits as well
- Author:
- Laurent Cohen
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jppf.process.AbstractProcessLauncher
AbstractProcessLauncher.SlaveSocketWrapper -
Field Summary
Fields inherited from class org.jppf.process.AbstractProcessLauncher
end, listeners, name, process, processPort, processServer, slaveSocketWrapperFields inherited from class org.jppf.utils.concurrent.ThreadSynchronization
stopped -
Constructor Summary
ConstructorsConstructorDescriptionProcessLauncher(String mainClass, boolean idleModeSupported) Initialize this process launcher. -
Method Summary
Modifier and TypeMethodDescriptionprotected ProcessWrapperCreate a process wrapper around the specified process, to capture its console output and prevent it from blocking.voidNotification that the process has written to its error stream.Get the output of the driver process.voididleStateChanged(IdleStateEvent event) Called when the idle state of the system has changed.protected booleanonProcessExit(int n) Called when the subprocess has exited with exit value n.voidNotification that the process has written to its output stream.voidrun()Start the socket listener and the subprocess.voidStart the sub-process.Methods inherited from class org.jppf.process.AbstractProcessLauncher
addProcessLauncherListener, buildClasspath, computeJavaExecPath, createShutdownHook, fireProcessStarted, fireProcessStopped, getName, getProcess, parseJvmOptions, removeProcessLauncherListener, sendActionCommand, startSocketListener, tearDownMethods inherited from class org.jppf.utils.concurrent.ThreadSynchronization
goToSleep, goToSleep, goToSleep, isStopped, setStopped, wakeUp
-
Constructor Details
-
ProcessLauncher
Initialize this process launcher.- Parameters:
mainClass- the fully qualified name of the main class of the sub process to launch.idleModeSupported- whether idle mode can be used on the process.
-
-
Method Details
-
run
public void run()Start the socket listener and the subprocess. -
startProcess
Start the sub-process.- Throws:
Exception- if any error occurs.
-
createProcessWrapper
Create a process wrapper around the specified process, to capture its console output and prevent it from blocking.- Parameters:
p- the process whose output is to be captured.- Returns:
- a
ProcessWrapperinstance.
-
onProcessExit
protected 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.- Specified by:
onProcessExitin classAbstractProcessLauncher- 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.
-
getOutput
Get the output of the driver process.- Parameters:
process- the process to get the standard or error output from.streamType- determines whether to obtain the standard or error output.- Returns:
- the output as a string.
-
errorStreamAltered
Notification that the process has written to its error stream.- Specified by:
errorStreamAlteredin interfaceProcessWrapperEventListener- Parameters:
event- encapsulate the error stream's content.
-
outputStreamAltered
Notification that the process has written to its output stream.- Specified by:
outputStreamAlteredin interfaceProcessWrapperEventListener- Parameters:
event- encapsulate the output stream's content.
-
idleStateChanged
Description copied from interface:IdleStateListenerCalled when the idle state of the system has changed.- Specified by:
idleStateChangedin interfaceIdleStateListener- Parameters:
event- the event encapsulating the state change.
-