use of com.cloudbees.groovy.cps.impl.ThrowBlock in project groovy-cps by cloudbees.
the class GreenThread method start.
/**
* Creates a new green thread that executes the given closure.
*/
public void start() {
Block b;
try {
run();
// closure had run synchronously.
b = Block.NOOP;
} catch (CpsCallableInvocation inv) {
// this will create a thread, and resume with the newly created thread
b = inv.asBlock();
} catch (Throwable t) {
// closure had run synchronously and failed
b = new ThrowBlock(new ConstantBlock(t));
}
final Block bb = b;
invoke(new ThreadTask() {
public Result eval(GreenWorld w) {
w = w.withNewThread(new GreenThreadState(GreenThread.this, bb));
return new Result(w, new Outcome(GreenThread.this, null), false);
}
});
// thus the code will never reach here
throw new AssertionError();
}
use of com.cloudbees.groovy.cps.impl.ThrowBlock in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method loadProgramFailed.
/**
* Used by {@link #loadProgramAsync(File)} to propagate a failure to load the persisted execution state.
* <p>
* Let the workflow interrupt by throwing an exception that indicates how it failed.
* @param promise same as {@link #programPromise} but more strongly typed
*/
private void loadProgramFailed(final Throwable problem, SettableFuture<CpsThreadGroup> promise) {
FlowHead head;
synchronized (this) {
if (heads == null || heads.isEmpty()) {
head = null;
} else {
head = getFirstHead();
}
}
if (head == null) {
// something went catastrophically wrong and there's no live head. fake one
head = new FlowHead(this);
try {
head.newStartNode(new FlowStartNode(this, iotaStr()));
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to persist", e);
}
}
CpsThreadGroup g = new CpsThreadGroup(this);
final FlowHead head_ = head;
promise.set(g);
runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {
@Override
public void onSuccess(CpsThreadGroup g) {
CpsThread t = g.addThread(new Continuable(new ThrowBlock(new ConstantBlock(problem instanceof AbortException ? problem : new IOException("Failed to load build state", problem)))), head_, null);
t.resume(new Outcome(null, null));
}
@Override
public void onFailure(Throwable t) {
LOGGER.log(Level.WARNING, "Failed to set program failure on " + owner, t);
croak(t);
}
});
}
Aggregations