private @Nonnull CpsThreadGroup getThreadGroupSynchronously() throws InterruptedException, IOException { if (threadGroup == null) { ListenableFuture<CpsThreadGroup> pp; CpsFlowExecution flowExecution = getFlowExecution(); while ((pp = flowExecution.programPromise) == null) { Thread.sleep(100); // TODO does JENKINS-33005 remove the need for this? } try { threadGroup = pp.get(); } catch (ExecutionException e) { throw new IOException(e); } } return threadGroup; }
@Override protected FlowNode getNode() throws IOException { if (node == null) { node = getFlowExecution().getNode(id); if (node == null) { throw new IOException("no node found for " + id); } } return node; }
@Override public void setResult(Result r) { try { getFlowExecution().setResult(r); } catch (IOException x) { LOGGER.log(Level.FINE, null, x); } }
@Override public ListenableFuture<Void> saveState() { try { final SettableFuture<Void> f = SettableFuture.create(); CpsFlowExecution exec = getFlowExecution(); if (!exec.getDurabilityHint().isPersistWithEveryStep()) { f.set(null); return f; } exec.runInCpsVmThread(new FutureCallback<CpsThreadGroup>() { @Override public void onSuccess(CpsThreadGroup result) { try { // TODO keep track of whether the program was saved anyway after saveState was called but before now, and do not bother resaving it in that case if (result.getExecution().getDurabilityHint().isPersistWithEveryStep()) { result.getExecution().getStorage().flush(); result.saveProgram(); } f.set(null); } catch (Exception x) { f.setException(x); } } @Override public void onFailure(Throwable t) { f.setException(t); } }); return f; } catch (IOException x) { return Futures.immediateFailedFuture(x); } }
final CpsFlowExecution flow = getFlowExecution();