Example usage for org.apache.commons.exec DefaultExecutor getWatchdog

List of usage examples for org.apache.commons.exec DefaultExecutor getWatchdog

Introduction

In this page you can find the example usage for org.apache.commons.exec DefaultExecutor getWatchdog.

Prototype

public ExecuteWatchdog getWatchdog() 

Source Link

Usage

From source file:com.nts.alphamale.util.Utils.java

/***
 *  executor  .//w  w w . ja  v  a  2 s  . c o m
 * @param executor
 */
public static void destoryExecutor(Object executor) {
    DefaultExecutor exec = (DefaultExecutor) executor;
    exec.getWatchdog().destroyProcess();
}

From source file:com.boulmier.machinelearning.jobexecutor.job.Job.java

public void start() throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final DefaultExecutor exec = new DefaultExecutor();
    final ExecuteWatchdog wd = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
    final PumpStreamHandler output = new PumpStreamHandler(out);
    final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();

    exec.setWatchdog(wd);/* ww w.  j  a  v  a  2  s  .  co m*/
    exec.setStreamHandler(output);
    exec.execute(cl, handler);
    JobExecutor.logger.info("Running job " + jobid);

    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                handler.waitFor();
                Computer.ComputeProperties properties = Computer.ComputeProperties.buildFromRequest(req);
                new SenderComputer(new StorageComputer(out.toString(), properties)).compute();
                JobExecutor.logger.info("Job complete " + jobid);
            } catch (InterruptedException ex) {
                exec.getWatchdog().destroyProcess();
                JobExecutor.logger.error(
                        "Job (" + jobid + ") has been destroyed due to internal error " + ex.getMessage());
            }
        }

    }).start();

}