/** * Evaluates the body but grow the {@link FlowNode}s on the same head as the current thread. * * The net effect is as if the body evaluation happens in the same thread as in the caller thread. */ @CpsVmThreadOnly /*package*/ void launch(CpsThread currentThread) { launch(currentThread, currentThread.head); }
@Override public void onSuccess(CpsThreadGroup g) { CpsThread thread = owner.getThread(g); if (thread != null) { launch(thread); } }
private void invokeBody(CpsThread cur) { // prepare enough heads for all the bodies // the first one can reuse the current thread, but other ones need to create new heads // we want to do this first before starting body so that the order of heads preserve // natural ordering. // TODO give this javadocs worth a darn, because this is how we create parallel branches and the docs are cryptic as can be! // Also we need to double-check this logic because this might cause a failure of persistence FlowHead[] heads = new FlowHead[context.bodyInvokers.size()]; for (int i = 0; i < heads.length; i++) { heads[i] = i==0 ? cur.head : cur.head.fork(); } int idx=0; for (CpsBodyInvoker b : context.bodyInvokers) { // don't collect the first head, which is what we borrowed from our parent. FlowHead h = heads[idx]; b.launch(cur, h); context.bodyHeads.add(h.getId()); idx++; } context.bodyInvokers.clear(); }