Search in sources :

Example 6 with WorkerExecutionContext

use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.

the class BLangFunctions method invokeNativeCallableAsync.

private static void invokeNativeCallableAsync(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs) {
    WorkerData caleeSF = BLangVMUtils.createWorkerDataForLocal(callableUnitInfo.getDefaultWorkerInfo(), parentCtx, argRegs, callableUnitInfo.getParamTypes());
    Context nativeCtx = new NativeCallContext(parentCtx, callableUnitInfo, caleeSF);
    NativeCallableUnit nativeCallable = callableUnitInfo.getNativeCallableUnit();
    if (nativeCallable == null) {
        return;
    }
    AsyncInvocableWorkerResponseContext respCtx;
    if (nativeCallable.isBlocking()) {
        respCtx = BLangScheduler.executeBlockingNativeAsync(nativeCallable, nativeCtx);
    } else {
        respCtx = BLangScheduler.executeNonBlockingNativeAsync(nativeCallable, nativeCtx);
    }
    BLangVMUtils.populateWorkerDataWithValues(parentCtx.workerLocal, retRegs, new BValue[] { new BCallableFuture(callableUnitInfo.getName(), respCtx) }, new BType[] { BTypes.typeFuture });
}
Also used : InitWorkerResponseContext(org.ballerinalang.bre.bvm.InitWorkerResponseContext) SyncCallableWorkerResponseContext(org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext) NativeCallContext(org.ballerinalang.bre.NativeCallContext) ForkJoinWorkerResponseContext(org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext) WorkerResponseContext(org.ballerinalang.bre.bvm.WorkerResponseContext) Context(org.ballerinalang.bre.Context) CallableWorkerResponseContext(org.ballerinalang.bre.bvm.CallableWorkerResponseContext) WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) AsyncInvocableWorkerResponseContext(org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext) AsyncInvocableWorkerResponseContext(org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext) NativeCallContext(org.ballerinalang.bre.NativeCallContext) NativeCallableUnit(org.ballerinalang.model.NativeCallableUnit) BCallableFuture(org.ballerinalang.model.values.BCallableFuture) WorkerData(org.ballerinalang.bre.bvm.WorkerData)

Example 7 with WorkerExecutionContext

use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.

the class BLangFunctions method executeWorker.

private static WorkerExecutionContext executeWorker(WorkerResponseContext respCtx, WorkerExecutionContext parentCtx, int[] argRegs, CallableUnitInfo callableUnitInfo, WorkerInfo workerInfo, WorkerDataIndex wdi, WorkerData initWorkerLocalData, CodeAttributeInfo initWorkerCAI, boolean runInCaller) {
    WorkerData workerLocal = BLangVMUtils.createWorkerDataForLocal(workerInfo, parentCtx, argRegs, callableUnitInfo.getParamTypes());
    if (initWorkerLocalData != null) {
        BLangVMUtils.mergeInitWorkertData(initWorkerLocalData, workerLocal, initWorkerCAI);
    }
    WorkerData workerResult = BLangVMUtils.createWorkerData(wdi);
    WorkerExecutionContext ctx = new WorkerExecutionContext(parentCtx, respCtx, callableUnitInfo, workerInfo, workerLocal, workerResult, wdi.retRegs, runInCaller);
    BLangScheduler.schedule(ctx);
    return ctx;
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) WorkerData(org.ballerinalang.bre.bvm.WorkerData)

Example 8 with WorkerExecutionContext

use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.

the class BLangFunctions method invokePackageInitFunction.

public static void invokePackageInitFunction(FunctionInfo initFuncInfo) {
    WorkerExecutionContext context = new WorkerExecutionContext(initFuncInfo.getPackageInfo().getProgramFile());
    invokePackageInitFunction(initFuncInfo, context);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext)

Example 9 with WorkerExecutionContext

use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.

the class BLangFunctions method invokeCallable.

public static WorkerExecutionContext invokeCallable(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs, boolean waitForResponse, int flags) {
    if (FunctionFlags.isObserved(flags)) {
        BLangVMUtils.initClientConnectorTrace(parentCtx, callableUnitInfo.attachedToType.toString(), callableUnitInfo.getName());
    }
    BLangScheduler.workerWaitForResponse(parentCtx);
    WorkerExecutionContext resultCtx;
    if (callableUnitInfo.isNative()) {
        if (FunctionFlags.isAsync(flags)) {
            invokeNativeCallableAsync(callableUnitInfo, parentCtx, argRegs, retRegs);
            resultCtx = parentCtx;
        } else {
            resultCtx = invokeNativeCallable(callableUnitInfo, parentCtx, argRegs, retRegs, flags);
        }
    } else {
        if (FunctionFlags.isAsync(flags)) {
            invokeNonNativeCallableAsync(callableUnitInfo, parentCtx, argRegs, retRegs);
            resultCtx = parentCtx;
        } else {
            resultCtx = invokeNonNativeCallable(callableUnitInfo, parentCtx, argRegs, retRegs, waitForResponse, flags);
        }
    }
    resultCtx = BLangScheduler.resume(resultCtx, true);
    return resultCtx;
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext)

Example 10 with WorkerExecutionContext

use of org.ballerinalang.bre.bvm.WorkerExecutionContext in project ballerina by ballerina-lang.

the class BLangFunctions method executeWorker.

private static WorkerExecutionContext executeWorker(WorkerResponseContext respCtx, WorkerExecutionContext parentCtx, int[] argRegs, WorkerInfo workerInfo, Map<String, Object> globalProps, boolean runInCaller) {
    WorkerData workerLocal = BLangVMUtils.createWorkerDataForLocal(workerInfo, parentCtx, argRegs);
    WorkerExecutionContext ctx = new WorkerExecutionContext(parentCtx, respCtx, parentCtx.callableUnitInfo, workerInfo, workerLocal, runInCaller);
    return BLangScheduler.schedule(ctx);
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) WorkerData(org.ballerinalang.bre.bvm.WorkerData)

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