Search in sources :

Example 1 with WorkerExecutionContext

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);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) Debugger(org.ballerinalang.util.debugger.Debugger)

Example 2 with WorkerExecutionContext

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);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) ResourceInfo(org.ballerinalang.util.codegen.ResourceInfo) BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) LocalTransactionInfo(org.ballerinalang.util.transactions.LocalTransactionInfo)

Example 3 with WorkerExecutionContext

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);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 4 with WorkerExecutionContext

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;
    }
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) InitWorkerResponseContext(org.ballerinalang.bre.bvm.InitWorkerResponseContext) WorkerData(org.ballerinalang.bre.bvm.WorkerData)

Example 5 with WorkerExecutionContext

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;
    }
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) WorkerSet(org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet) BStruct(org.ballerinalang.model.values.BStruct) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) WorkerData(org.ballerinalang.bre.bvm.WorkerData) TraceableCallback(org.ballerinalang.util.tracer.TraceableCallback) SyncCallableWorkerResponseContext(org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext) CallableWorkerResponseContext(org.ballerinalang.bre.bvm.CallableWorkerResponseContext)

Aggregations

WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)19 WorkerData (org.ballerinalang.bre.bvm.WorkerData)7 AsyncInvocableWorkerResponseContext (org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext)3 CallableWorkerResponseContext (org.ballerinalang.bre.bvm.CallableWorkerResponseContext)3 InitWorkerResponseContext (org.ballerinalang.bre.bvm.InitWorkerResponseContext)3 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)3 Context (org.ballerinalang.bre.Context)2 NativeCallContext (org.ballerinalang.bre.NativeCallContext)2 ForkJoinWorkerResponseContext (org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext)2 WorkerResponseContext (org.ballerinalang.bre.bvm.WorkerResponseContext)2 NativeCallableUnit (org.ballerinalang.model.NativeCallableUnit)2 BCallableFuture (org.ballerinalang.model.values.BCallableFuture)2 WorkerSet (org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet)2 CodeAttributeInfo (org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)2 Debugger (org.ballerinalang.util.debugger.Debugger)2 BLangRuntimeException (org.ballerinalang.util.exceptions.BLangRuntimeException)2 ArrayList (java.util.ArrayList)1 BLangCallableUnitCallback (org.ballerinalang.bre.BLangCallableUnitCallback)1 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1