|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.aspectj.util.LangUtil.ProcessController
public static class LangUtil.ProcessController
Handle an external process asynchrously. start()
launches a main thread to wait for the process and pipes
streams (in child threads) through to the corresponding streams (e.g., the process System.err to this System.err). This can
complete normally, by exception, or on demand by a client. Clients can implement doCompleting(..)
to get notice
when the process completes.
The following sample code creates a process with a completion callback starts it, and some time later retries the process.
LangUtil.ProcessController controller = new LangUtil.ProcessController() { protected void doCompleting(LangUtil.ProcessController.Thrown thrown, int result) { // signal result } }; controller.init(new String[] { "java", "-version" }, "java version"); controller.start(); // some time later... // retry... if (!controller.completed()) { controller.stop(); controller.reinit(); controller.start(); }warning: Currently this does not close the input or output streams, since doing so prevents their use later.
Nested Class Summary | |
---|---|
static class |
LangUtil.ProcessController.Thrown
|
Constructor Summary | |
---|---|
LangUtil.ProcessController()
|
Method Summary | |
---|---|
boolean |
completed()
|
protected void |
doCompleting(LangUtil.ProcessController.Thrown thrown,
int result)
Subclasses implement this to get synchronous notice of completion. |
java.lang.String[] |
getCommand()
|
int |
getResult()
|
LangUtil.ProcessController.Thrown |
getThrown()
Get any Throwable thrown. |
void |
init(java.io.File java,
java.lang.String classpath,
java.lang.String mainClass,
java.lang.String[] args)
|
void |
init(java.lang.String[] command,
java.lang.String label)
|
void |
init(java.lang.String classpath,
java.lang.String mainClass,
java.lang.String[] args)
|
void |
reinit()
Permit re-running using the same command if this is not started or if completed. |
void |
setEnvp(java.lang.String[] envp)
|
void |
setErrSnoop(java.io.ByteArrayOutputStream snoop)
|
void |
setOutSnoop(java.io.ByteArrayOutputStream snoop)
|
java.lang.Thread |
start()
Start running the process and pipes asynchronously. |
boolean |
started()
|
void |
stop()
Destroy any process, stop any pipes. |
boolean |
userStopped()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LangUtil.ProcessController()
Method Detail |
---|
public final void reinit()
public final void init(java.lang.String classpath, java.lang.String mainClass, java.lang.String[] args)
public final void init(java.io.File java, java.lang.String classpath, java.lang.String mainClass, java.lang.String[] args)
public final void init(java.lang.String[] command, java.lang.String label)
public final void setEnvp(java.lang.String[] envp)
public final void setErrSnoop(java.io.ByteArrayOutputStream snoop)
public final void setOutSnoop(java.io.ByteArrayOutputStream snoop)
public final java.lang.Thread start()
getThrown()
, etc.)public final void stop()
public final java.lang.String[] getCommand()
public final boolean completed()
public final boolean started()
public final boolean userStopped()
public final LangUtil.ProcessController.Thrown getThrown()
public final int getResult()
protected void doCompleting(LangUtil.ProcessController.Thrown thrown, int result)
getThrown()
. If there is an exception, the process
completed abruptly (including side-effects of the user halting the process). If userStopped()
is true, then
some client asked that the process be destroyed using stop()
. Otherwise, the result code should be the
result value returned by the process.
thrown
- same as getThrown().fromProcess
.result
- same as getResult()
getThrown()
,
getResult()
,
stop()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |