use of org.fagu.fmv.soft.exec.PIDProcessOperator in project fmv by f-agu.
the class SoftExecutor method execute.
/**
* @return Executed time in milliseconds
* @throws IOException
*/
public SoftExecutor.Executed execute() throws IOException {
return execute((fmvExecutor, commandLine, execListener, readLineList) -> {
final String cmdLineStr = CommandLineUtils.toLine(commandLine);
long startTime = System.currentTimeMillis();
long time = 0;
int exitValue = 0;
PIDProcessOperator pidProcessOperator = new PIDProcessOperator();
fmvExecutor.addProcessOperator(pidProcessOperator);
try {
execListener.eventExecuting(cmdLineStr);
exitValue = geExecuteDelegate().execute(fmvExecutor, commandLine);
time = System.currentTimeMillis() - startTime;
execListener.eventExecuted(cmdLineStr, exitValue, time);
} catch (ExecuteException e) {
FMVExecuteException fmvExecuteException = new FMVExecuteException(softProvider.getExceptionKnownAnalyzerClass(), e, cmdLineStr, readLineList);
execListener.eventException(fmvExecuteException);
ExceptionKnownAnalyzers.doOrThrows(softProvider.getExceptionKnownAnalyzerClass(), fmvExecuteException, exceptionKnowConsumer, exceptionConsumer);
}
return new Executed(pidProcessOperator.getPID(), exitValue, time);
});
}
use of org.fagu.fmv.soft.exec.PIDProcessOperator in project fmv by f-agu.
the class SoftExecutor method executeInBackground.
/**
* @param executorService
* @return
* @throws IOException
*/
public Future<SoftExecutor.Executed> executeInBackground(ExecutorService executorService) throws IOException {
return execute((fmvExecutor, commandLine, execListener, readLineList) -> {
final String cmdLineStr = CommandLineUtils.toLine(commandLine);
final AtomicLong startTime = new AtomicLong();
final AtomicLong time = new AtomicLong();
final PIDProcessOperator pidProcessOperator = new PIDProcessOperator();
fmvExecutor.addProcessOperator(pidProcessOperator);
return new WrapFuture<>(fmvExecutor.executeAsynchronous(geExecuteDelegate(), commandLine, executorService, // before
() -> {
startTime.set(System.currentTimeMillis());
execListener.eventExecuting(cmdLineStr);
}, // after
exitValue -> {
time.set(System.currentTimeMillis() - startTime.get());
execListener.eventExecuted(cmdLineStr, exitValue, time.get());
}, // exception
exception -> {
if (exception instanceof ExecuteException) {
ExecuteException e = (ExecuteException) exception;
FMVExecuteException fmvExecuteException = new FMVExecuteException(softProvider.getExceptionKnownAnalyzerClass(), e, cmdLineStr, readLineList);
execListener.eventException(fmvExecuteException);
ExceptionKnownAnalyzers.doOrThrows(softProvider.getExceptionKnownAnalyzerClass(), fmvExecuteException, exceptionKnowConsumer, exceptionConsumer);
}
}), exitValue -> new Executed(pidProcessOperator.getPID(), exitValue, time.get()));
});
}
Aggregations