Class LangUtil.ProcessController

java.lang.Object
org.aspectj.util.LangUtil.ProcessController
Enclosing class:
LangUtil

public static class LangUtil.ProcessController extends Object
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.