Source:
protected void execute(TaskListener listener) { final ImmutableList.Builder<ListenableFuture<?>> deletedNodesBuilder = ImmutableList.<ListenableFuture<?>>builder(); ListeningExecutorService executor = MoreExecutors.listeningDecorator(Computer.threadPoolForRemoting); final ImmutableList.Builder<MesosComputer> computersToDeleteBuilder = ImmutableList.<MesosComputer>builder(); for (final Computer c : Jenkins.getInstance().getComputers()) { if (MesosComputer.class.isInstance(c)) { if (((MesosComputer) c).getNode().isPendingDelete()) { final MesosComputer comp = (MesosComputer) c; computersToDeleteBuilder.add(comp); logger.log(Level.INFO, "Marked " + comp.getName() + " for deletion"); ListenableFuture<?> f = executor.submit(new Runnable() { public void run() { logger.log(Level.INFO, "Deleting pending node " + comp.getName()); try { comp.getNode().terminate(); } catch (RuntimeException e) { logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage()); throw e; } } }); deletedNodesBuilder.add(f); } else { logger.log(Level.INFO, c.getName() + " is not pending deletion"); } } else { logger.log(Level.INFO, c.getName() + " is not a mesos computer, it is a " + c.getClass().getName()); } } Futures.getUnchecked(Futures.successfulAsList(deletedNodesBuilder.build())); for (MesosComputer c : computersToDeleteBuilder.build()) { try { c.deleteSlave(); } catch (IOException e) { logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage()); } catch (InterruptedException e) { logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage()); } } }

Target:
protected void execute(TaskListener listener) { final ImmutableList.Builder<ListenableFuture<?>> deletedNodesBuilder = ImmutableList.<ListenableFuture<?>>builder(); ListeningExecutorService executor = MoreExecutors.listeningDecorator(Computer.threadPoolForRemoting); final ImmutableList.Builder<MesosComputer> computersToDeleteBuilder = ImmutableList.<MesosComputer>builder(); for (final Computer c : Jenkins.getInstance().getComputers()) { if (MesosComputer.class.isInstance(c)) { MesosSlave mesosSlave = (MesosSlave) c.getNode(); if (mesosSlave != null && mesosSlave.isPendingDelete()) { final MesosComputer comp = (MesosComputer) c; computersToDeleteBuilder.add(comp); logger.log(Level.INFO, "Marked " + comp.getName() + " for deletion"); ListenableFuture<?> f = executor.submit(new Runnable() { public void run() { logger.log(Level.INFO, "Deleting pending node " + comp.getName()); try { comp.getNode().terminate(); } catch (RuntimeException e) { logger.log(Level.WARNING, "Failed to disconnect and delete " + comp.getName() + ": " + e.getMessage()); throw e; } } }); deletedNodesBuilder.add(f); } else { logger.log(Level.FINE, c.getName() + " with slave " + mesosSlave + " is not pending deletion or the slave is null"); } } else { logger.log(Level.FINER, c.getName() + " is not a mesos computer, it is a " + c.getClass().getName()); } } Futures.getUnchecked(Futures.successfulAsList(deletedNodesBuilder.build())); for (MesosComputer c : computersToDeleteBuilder.build()) { try { c.deleteSlave(); } catch (IOException e) { logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage()); } catch (InterruptedException e) { logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage()); } } }