use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.
the class TesterinaFunction method invoke.
/**
* Invokes a ballerina test function, in blocking mode.
*
* @param args function arguments
*/
public BValue[] invoke(BValue[] args) {
WorkerExecutionContext ctx = new WorkerExecutionContext(programFile);
Debugger debugger = new Debugger(programFile);
initDebugger(programFile, debugger);
return BLangFunctions.invokeCallable(bFunction, ctx, args);
}
use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.
the class ResourceExecutor method execute.
/**
* This method will execute the resource, given required details.
* And it will use the callback to notify interested parties about the
* outcome of the execution.
*
* @param resource to be executed.
* @param responseCallback to notify.
* @param properties to be passed to context.
* @param tracer to be passed to context.
* @param bValues for parameters.
*/
public static void execute(Resource resource, CallableUnitCallback responseCallback, Map<String, Object> properties, Tracer tracer, BValue... bValues) throws BallerinaConnectorException {
if (resource == null || responseCallback == null) {
throw new BallerinaConnectorException("invalid arguments provided");
}
ResourceInfo resourceInfo = resource.getResourceInfo();
WorkerExecutionContext context = new WorkerExecutionContext(resourceInfo.getPackageInfo().getProgramFile());
if (properties != null) {
context.globalProps.putAll(properties);
if (properties.get(Constants.GLOBAL_TRANSACTION_ID) != null) {
context.setLocalTransactionInfo(new LocalTransactionInfo(properties.get(Constants.GLOBAL_TRANSACTION_ID).toString(), properties.get(Constants.TRANSACTION_URL).toString(), "2pc"));
}
}
BLangVMUtils.initServerConnectorTrace(context, resource, tracer);
BLangVMUtils.setServiceInfo(context, resourceInfo.getServiceInfo());
BLangFunctions.invokeCallable(resourceInfo, context, bValues, responseCallback);
}
use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.
the class BRunUtil method invokePackageInit.
/**
* Invoke package init function.
*
* @param compileResult CompileResult instance
* @param packageName Name of the package to invoke
*/
protected static void invokePackageInit(CompileResult compileResult, String packageName) {
if (compileResult.getErrorCount() > 0) {
throw new IllegalStateException(compileResult.toString());
}
ProgramFile programFile = compileResult.getProgFile();
PackageInfo packageInfo = programFile.getPackageInfo(packageName);
WorkerExecutionContext context = new WorkerExecutionContext(programFile);
Debugger debugger = new Debugger(programFile);
programFile.setDebugger(debugger);
compileResult.setContext(context);
BLangFunctions.invokePackageInitFunction(packageInfo.getInitFunctionInfo(), context);
}
use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.
the class BLangFunctions method executeInitWorker.
private static WorkerData executeInitWorker(WorkerExecutionContext parentCtx, int[] argRegs, CallableUnitInfo callableUnitInfo, WorkerInfo workerInfo, WorkerDataIndex wdi) {
InitWorkerResponseContext respCtx = new InitWorkerResponseContext(parentCtx);
WorkerExecutionContext ctx = executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerInfo, wdi, null, null, true);
BLangScheduler.executeNow(ctx);
WorkerData workerLocal = ctx.workerLocal;
if (respCtx.isErrored()) {
return null;
} else {
return workerLocal;
}
}
use of org.ballerinalang.bre.bvm.WorkerExecutionContext 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