Search in sources :

Example 1 with WorkerData

use of org.ballerinalang.bre.bvm.WorkerData 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 2 with WorkerData

use of org.ballerinalang.bre.bvm.WorkerData 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)

Example 3 with WorkerData

use of org.ballerinalang.bre.bvm.WorkerData 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 4 with WorkerData

use of org.ballerinalang.bre.bvm.WorkerData 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 5 with WorkerData

use of org.ballerinalang.bre.bvm.WorkerData 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

WorkerData (org.ballerinalang.bre.bvm.WorkerData)12 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)7 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)4 AsyncInvocableWorkerResponseContext (org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext)3 CallableWorkerResponseContext (org.ballerinalang.bre.bvm.CallableWorkerResponseContext)3 InitWorkerResponseContext (org.ballerinalang.bre.bvm.InitWorkerResponseContext)3 BType (org.ballerinalang.model.types.BType)3 WorkerSet (org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet)3 CodeAttributeInfo (org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)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 BBoolean (org.ballerinalang.model.values.BBoolean)2 BCallableFuture (org.ballerinalang.model.values.BCallableFuture)2 BString (org.ballerinalang.model.values.BString)2 TraceableCallback (org.ballerinalang.util.tracer.TraceableCallback)2 ArrayList (java.util.ArrayList)1 BLangCallableUnitCallback (org.ballerinalang.bre.BLangCallableUnitCallback)1