@Override public String toString() { return "BackgroundLoop '" + getName() + "': " + getExecutionInfo(); }
/** * Calls {@code doWork()} with proper error handling and then {@code loop()} again to schedule the next call. */ private void executeWork() { try { if (orchestration == null || orchestration.tryExecuteBackgroundLoop(getName())) { try { Watch w = Watch.start(); LocalDateTime now = LocalDateTime.now(); String executedWork = doWork(); buildAndLogExecutionInfo(w, now, executedWork); } finally { if (orchestration != null) { orchestration.backgroundLoopCompleted(getName(), executionInfo); } } } } catch (Exception e) { Exceptions.handle(Tasks.LOG, e); } loop(); }
private void buildAndLogExecutionInfo(Watch watch, LocalDateTime startedAt, String executedWorkDescription) { if (executedWorkDescription != null) { executionInfo = NLS.toUserString(startedAt) + " (" + watch.duration() + "): " + executedWorkDescription; Log.BACKGROUND.FINE(getName() + ": " + executionInfo); } else { executionInfo = NLS.toUserString(startedAt) + " (" + watch.duration() + ") - no work executed..."; } }
output.separator(); for (BackgroundLoop loop : loops) { output.apply("%-60s %s", loop.getName(), loop.getExecutionInfo());