use of org.ballerinalang.bre.bvm.CallableWorkerResponseContext in project ballerina by ballerina-lang.
the class BLangFunctions method invokeNonNativeCallable.
public static WorkerExecutionContext invokeNonNativeCallable(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs, boolean waitForResponse, int flags) {
WorkerSet workerSet = callableUnitInfo.getWorkerSet();
int generalWorkersCount = workerSet.generalWorkers.length;
CallableWorkerResponseContext respCtx = createWorkerResponseContext(callableUnitInfo.getRetParamTypes(), generalWorkersCount);
WaitForResponseCallback respCallback = null;
if (waitForResponse) {
respCallback = new WaitForResponseCallback();
respCtx.registerResponseCallback(respCallback);
}
if (TraceManagerWrapper.getInstance().isTraceEnabled() && FunctionFlags.isObserved(flags)) {
respCtx.registerResponseCallback(new TraceableCallback(parentCtx));
}
respCtx.joinTargetContextInfo(parentCtx, retRegs);
WorkerDataIndex wdi = callableUnitInfo.retWorkerIndex;
/* execute the init worker and extract the local variables created by it */
WorkerData initWorkerLocalData = null;
CodeAttributeInfo initWorkerCAI = null;
if (workerSet.initWorker != null) {
initWorkerLocalData = executeInitWorker(parentCtx, argRegs, callableUnitInfo, workerSet.initWorker, wdi);
if (initWorkerLocalData == null) {
handleError(parentCtx);
return null;
}
initWorkerCAI = workerSet.initWorker.getCodeAttributeInfo();
}
for (int i = 1; i < generalWorkersCount; i++) {
executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[i], wdi, initWorkerLocalData, initWorkerCAI, false);
}
WorkerExecutionContext runInCallerCtx = executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[0], wdi, initWorkerLocalData, initWorkerCAI, true);
if (waitForResponse) {
BLangScheduler.executeNow(runInCallerCtx);
respCallback.waitForResponse();
// An error in the context at this point means an unhandled runtime error has propagated
// all the way up to the entry point. Hence throw a {@link BLangRuntimeException} and
// terminate the execution.
BStruct error = parentCtx.getError();
if (error != null) {
handleError(parentCtx);
}
return null;
} else {
return runInCallerCtx;
}
}
Aggregations