|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
com.bea.adapter.util.CommandRunner
Helper class for executing a command via a Process obtained by the Runtime object in a thread. The main value-add of this class is to allow for setting a maximum time to wait for the process to return and if the max is exceeded, handle the error reporting gracefully. Here's how to use the CommandRunner to compile a Java file using "javac":
CommandRunner runner = new CommandRunner("javac HelloWorld.java"); runner.start(); if (!CommandRunner.SUCCESS.equals(runner.getExitValue())) { throw new IllegalStateException(runner.getErrorMessage()); }
Field Summary | |
static long |
DEFAULT_MAX_WAIT
The default max wait period for waiting for a process to complete. |
static String |
EXCEPTION
Possible return value from getExitValue ; indicates that an
exception was encountered while executing the command, such as the
executable was not in the user's path. |
static String |
SUCCESS
Possible return value from getExitValue ; indicates that the
external process returned 0 as an exit value. |
static String |
TIMEOUT
Possible return value from getExitValue ; indicates the process
did NOT return an exit value in the maximum allowable time period, perhaps
the external process is hung. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
CommandRunner(String strCommand)
Constructs an instance to execute a command and wait a maximum of 10 seconds for it to finish. |
|
CommandRunner(String strCommand,
long lMaxWait)
Constructs an instance to execute a command and wait a maximum of lMaxWait milliseconds for it to finish. |
Method Summary | |
String |
getCommand()
|
String |
getErrorMessage()
|
String |
getExitValue()
Returns the exit value from executing the command: CommandRunner.TIMEOUT indicates that the process timed-out, CommandRunner.SUCCESS indicates the process returned 0, CommandRunner.EXCEPTION indicates an exception was encountered while executing the command. |
void |
run()
Executes the command established in the constructor. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final String EXCEPTION
getExitValue
; indicates that an
exception was encountered while executing the command, such as the
executable was not in the user's path.
public static final String TIMEOUT
getExitValue
; indicates the process
did NOT return an exit value in the maximum allowable time period, perhaps
the external process is hung.
public static final String SUCCESS
getExitValue
; indicates that the
external process returned 0 as an exit value.
public static final long DEFAULT_MAX_WAIT
Constructor Detail |
public CommandRunner(String strCommand)
strCommand
- - command to executepublic CommandRunner(String strCommand, long lMaxWait)
lMaxWait
milliseconds for it to finish.
strCommand
- - command to executelMaxWait
- - maximum number of milliseconds to wait until the command
returns a value.Method Detail |
public String getExitValue()
public String getCommand()
public String getErrorMessage()
public void run()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |