@Override public void run() { long sleepTime = endTime - System.currentTimeMillis(); while (sleepTime > 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException ignored) { } sleepTime = endTime - System.currentTimeMillis(); } switch (target.getState()) { case NOT_STARTED: case RUNNING: log.warn("Interrupting task " + target + " that timed out after " + (endTime - startTime) + " millis."); target.timeout(); break; case TIMED_OUT: case INTERRUPTED: case FAILED: case SUCCEEDED: log.info("Interrupter has no work to do, " + target + " already completed."); break; } try { Thread.sleep(DELETE_TASK_INFO_WINDOW); } catch (InterruptedException ignored) { } deleteTaskInfo(target.getUuid()); } }
<P> DaemonResponse<P> reapChild(DaemonTask task) throws InterruptedException { DaemonTask childTask = children.stream() .filter(c -> c.getUuid().equals(task.getUuid())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Child " + task + " does not belong to this task " + this + "")); // Spin due to spurious wakeups while (!childTask.getState().isTerminal()) { try { synchronized (childTask) { childTask.wait(); } } catch (InterruptedException e) { throw e; } } TaskRepository.getTask(childTask.getUuid()); log.info(this + "Collected child task " + childTask + " with state " + childTask.getState()); if (childTask.getResponse() == null) { throw new RuntimeException("Child response may not be null."); } return childTask.getResponse(); }
ShallowTaskInfo(DaemonTask task) { this.uuid = task.getUuid(); this.name = task.getName(); this.state = task.getState(); this.fatalException = task.getFatalError(); this.jobs = task.getRunningJobs(); if (!task.getEvents().isEmpty()) { this.lastEvent = task.getEvents().get(task.getEvents().size() - 1).toString(); } this.children = (List<String>) task.getChildren() .stream() .map(c -> c.toString()) .collect(Collectors.toList()); } }
DaemonTask.State state = child.getState(); if (!state.isTerminal()) { throw new IllegalStateException("Child task " + child + " reaped but non-terminal.");
State state = task.getState(); String taskName = task.getName();
State state = task.getState(); String taskName = task.getName();