Skip to content

Commit

Permalink
Replace anonymous Runnable with lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Aug 15, 2020
1 parent d7e3c01 commit f06bd78
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,21 +494,19 @@ private static final class NewlineSafeTaskListener implements TaskListener {
if (workspace != null) {
listener().getLogger().println("Sending interrupt signal to process");
LOGGER.log(Level.FINE, "stopping process", cause);
stopTask = Timer.get().schedule(new Runnable() {
@Override public void run() {
stopTask = null;
if (recurrencePeriod > 0) {
recurrencePeriod = 0;
listener().getLogger().println("After " + REMOTE_TIMEOUT + "s process did not stop");
getContext().onFailure(cause);
try {
FilePath workspace = getWorkspace();
if (workspace != null) {
controller.cleanup(workspace);
}
} catch (IOException | InterruptedException x) {
Functions.printStackTrace(x, listener().getLogger());
stopTask = Timer.get().schedule(() -> {
stopTask = null;
if (recurrencePeriod > 0) {
recurrencePeriod = 0;
listener().getLogger().println("After " + REMOTE_TIMEOUT + "s process did not stop");
getContext().onFailure(cause);
try {
FilePath taskWorkspace = getWorkspace();
if (taskWorkspace != null) {
controller.cleanup(taskWorkspace);
}
} catch (IOException | InterruptedException x) {
Functions.printStackTrace(x, listener().getLogger());
}
}
}, REMOTE_TIMEOUT, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,20 @@ public boolean start() throws Exception {
}
getContext().get(FlowNode.class).addAction(new QueueItemActionImpl(waitingItem.getId()));

Timer.get().schedule(new Runnable() {
@Override public void run() {
Queue.Item item = Queue.getInstance().getItem(task);
if (item != null) {
TaskListener listener;
try {
listener = getContext().get(TaskListener.class);
} catch (Exception x) { // IOException, InterruptedException
LOGGER.log(FINE, "could not print message to build about " + item + "; perhaps it is already completed", x);
return;
}
listener.getLogger().println("Still waiting to schedule task");
CauseOfBlockage cob = item.getCauseOfBlockage();
if (cob != null) {
cob.print(listener);
}
Timer.get().schedule(() -> {
Queue.Item item = Queue.getInstance().getItem(task);
if (item != null) {
TaskListener listener;
try {
listener = getContext().get(TaskListener.class);
} catch (Exception x) { // IOException, InterruptedException
LOGGER.log(FINE, "could not print message to build about " + item + "; perhaps it is already completed", x);
return;
}
listener.getLogger().println("Still waiting to schedule task");
CauseOfBlockage cob = item.getCauseOfBlockage();
if (cob != null) {
cob.print(listener);
}
}
}, 15, TimeUnit.SECONDS);
Expand Down Expand Up @@ -732,23 +730,16 @@ private static void finish(@CheckForNull final String cookie) {
return;
}
assert runningTask.launcher != null;
Timer.get().submit(new Runnable() { // JENKINS-31614
@Override public void run() {
execution.completed(null);
}
});
Computer.threadPoolForRemoting.submit(new Runnable() { // JENKINS-34542, JENKINS-45553
@Override
public void run() {
try {
runningTask.launcher.kill(Collections.singletonMap(COOKIE_VAR, cookie));
} catch (ChannelClosedException x) {
// fine, Jenkins was shutting down
} catch (RequestAbortedException x) {
// slave was exiting; too late to kill subprocesses
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to shut down " + cookie, x);
}
Timer.get().submit(() -> execution.completed(null)); // JENKINS-31614
Computer.threadPoolForRemoting.submit(() -> { // JENKINS-34542, JENKINS-45553
try {
runningTask.launcher.kill(Collections.singletonMap(COOKIE_VAR, cookie));
} catch (ChannelClosedException x) {
// fine, Jenkins was shutting down
} catch (RequestAbortedException x) {
// slave was exiting; too late to kill subprocesses
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to shut down " + cookie, x);
}
});
}
Expand Down Expand Up @@ -889,18 +880,16 @@ private final class PlaceholderExecutable implements ContinuableExecutable, Acce
}
LOGGER.log(FINE, "interrupted {0}", cookie);
// TODO save the BodyExecution somehow and call .cancel() here; currently we just interrupt the build as a whole:
Timer.get().submit(new Runnable() { // JENKINS-46738
@Override public void run() {
Executor masterExecutor = r.getExecutor();
if (masterExecutor != null) {
masterExecutor.interrupt();
} else { // anomalous state; perhaps build already aborted but this was left behind; let user manually cancel executor slot
Executor thisExecutor = /* AsynchronousExecution. */getExecutor();
if (thisExecutor != null) {
thisExecutor.recordCauseOfInterruption(r, _listener);
}
completed(null);
Timer.get().submit(() -> { // JENKINS-46738
Executor masterExecutor = r.getExecutor();
if (masterExecutor != null) {
masterExecutor.interrupt();
} else { // anomalous state; perhaps build already aborted but this was left behind; let user manually cancel executor slot
Executor thisExecutor = /* AsynchronousExecution. */getExecutor();
if (thisExecutor != null) {
thisExecutor.recordCauseOfInterruption(r, _listener);
}
completed(null);
}
});
}
Expand Down

0 comments on commit f06bd78

Please sign in to comment.