|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.jini.start.process.ProcessHelper
public class ProcessHelper
Helper object for a running Process that DOES NOT require any input.
The output of the process will be logged, but not otherwise processed.
| Field Summary | |
|---|---|
protected static org.apache.log4j.Logger |
log
|
String |
name
A useful name for the process. |
| Constructor Summary | |
|---|---|
ProcessHelper(String name,
ProcessBuilder processBuilder,
IServiceListener listener)
Starts the Process, starts a Thread to consume its
output, and registers the Process with the
IServiceListener. |
|
| Method Summary | |
|---|---|
protected void |
consumeOutput()
Consumes the output of the process, writing each line onto a Logger. |
boolean |
equals(Object o)
Only accept reference tests for equality. |
int |
exitValue()
Await the exit value and return it when it becomes available. |
int |
exitValue(long timeout,
TimeUnit unit)
Waits up to timeout units for the Process to terminate and then
returns its exit value. |
static String |
getCommandString(ProcessBuilder processBuilder)
Return the command line that would be executed. |
static String |
getEnvironment(ProcessBuilder processBuilder)
Return a String containing commands to set the environment for
the processs. |
Future |
interruptWhenProcessDies(long timeout,
TimeUnit unit)
Interrupts the caller's Thread if the process dies within the
specified timeout. |
int |
kill(boolean immediateShutdown)
Kill the process, blocking until it has terminated. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
public final String name
| Constructor Detail |
|---|
public ProcessHelper(String name,
ProcessBuilder processBuilder,
IServiceListener listener)
throws IOException
Process, starts a Thread to consume its
output, and registers the Process with the
IServiceListener.
name - A useful name for the process.processBuilder - The object used to start the Process.running - A Queue of the running Processes.
IOException| Method Detail |
|---|
public String toString()
toString in class Object
public int exitValue()
throws InterruptedException
InterruptedException - if the caller's thread is interrupted while awaiting the
process exit value.
public int exitValue(long timeout,
TimeUnit unit)
throws TimeoutException,
InterruptedException
Process to terminate and then
returns its exit value.
timeout - unit -
TimeoutException - if the Process is still running when the specified
timeout elapsed.
InterruptedException - if the caller's thread was interrupted awaiting the exit
value.
public int kill(boolean immediateShutdown)
throws InterruptedException
Note: processes with child processes (including any bigdata services since they start children to report OS performance counters) MUST exit normally (at least under windows) or the parent process will not be able to exit. Therefore it is very important to extend this method and send proper notice to the process requesting that it terminate itself.
immediateShutdown - processes with APIs that differentiate immediate shutdown and
normal shutdown will use the appropriate behavior as selected
by this parameter.
InterruptedException - if interrupted - the process may or may not have been killed
and the listener will not have been notified.public boolean equals(Object o)
equals in class Objectprotected void consumeOutput()
Logger.
Note: Normally you will see the child process output by configuring logging for the child process. However, if you want to see the output of the child process within the logging of this process, then you have to raise the log level to INFO for this class.
public Future interruptWhenProcessDies(long timeout,
TimeUnit unit)
Thread if the process dies within the
specified timeout.
This thread can still be running after call() has returned and it can
cause a spurious interrupt. To avoid that you MUST cancel the thread
monitoring for the process death using the returned Future.
timeout - The timeout.unit - The timeout unit.
Future for the Thread awaiting the task
death.exitValue(long, TimeUnit) with a small timeout to verify
that the process is in fact dead. That is weird. I am even forcing
the wait for the exit value in this method but to no avail.public static String getEnvironment(ProcessBuilder processBuilder)
String containing commands to set the environment for
the processs.
public static String getCommandString(ProcessBuilder processBuilder)
processBuilder -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||