Futures.addCallback(processExitFuture, new FutureCallback<Integer>() {
// these code blocks must not throw exceptions since they are executed inside an executor. (or must be caught)
@Override
public void onSuccess(Integer exitCode) {
TaskState taskState = null;
String message = null;
if (task.wasKilled()) {
taskState = TaskState.TASK_KILLED;
if (!task.wasDestroyed()) {
message = "Task killed. Process exited gracefully with code " + exitCode;
} else {
final long millisWaited = task.getExecutorData().getSigKillProcessesAfterMillis().or(configuration.getHardKillAfterMillis());
message = String.format("Task killed forcibly after waiting at least %s", JavaUtils.durationFromMillis(millisWaited));
}
} else if (task.isSuccessExitCode(exitCode)) {
taskState = TaskState.TASK_FINISHED;
message = "Process exited normally with code " + exitCode;
} else {
taskState = TaskState.TASK_FAILED;
message = "Process failed with code " + exitCode;
}
sendStatusUpdate(task, taskState, message);
onFinish(task, taskState);
}
@Override
public void onFailure(Throwable t) {
task.getLog().error("Task {} failed while running process", task, t);
TaskState taskState = null;
String message = null;
if (task.wasKilled()) {
taskState = TaskState.TASK_KILLED;
message = String.format("Task killed, caught %s", t.getClass().getSimpleName());