Search in sources :

Example 6 with CodeAttributeInfo

use of org.ballerinalang.util.codegen.attributes.CodeAttributeInfo in project ballerina by ballerina-lang.

the class BLangFunctions method invokeNonNativeCallableAsync.

public static void invokeNonNativeCallableAsync(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs) {
    WorkerSet workerSet = callableUnitInfo.getWorkerSet();
    int generalWorkersCount = workerSet.generalWorkers.length;
    AsyncInvocableWorkerResponseContext respCtx = new AsyncInvocableWorkerResponseContext(callableUnitInfo, generalWorkersCount);
    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;
        }
        initWorkerCAI = workerSet.initWorker.getCodeAttributeInfo();
    }
    List<WorkerExecutionContext> workerExecutionContexts = new ArrayList<>();
    /* execute all the workers in their own threads */
    for (int i = 0; i < generalWorkersCount; i++) {
        workerExecutionContexts.add(executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[i], wdi, initWorkerLocalData, initWorkerCAI, false));
    }
    /* set the worker execution contexts in the response context, so it can use them to do later
         * operations such as cancel */
    respCtx.setWorkerExecutionContexts(workerExecutionContexts);
    /* create the future encapsulating the worker response context, and set it as the return value
         * to the parent */
    BLangVMUtils.populateWorkerDataWithValues(parentCtx.workerLocal, retRegs, new BValue[] { new BCallableFuture(callableUnitInfo.getName(), respCtx) }, new BType[] { BTypes.typeFuture });
    return;
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) WorkerSet(org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet) AsyncInvocableWorkerResponseContext(org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) ArrayList(java.util.ArrayList) BCallableFuture(org.ballerinalang.model.values.BCallableFuture) WorkerData(org.ballerinalang.bre.bvm.WorkerData)

Aggregations

CodeAttributeInfo (org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)6 WorkerData (org.ballerinalang.bre.bvm.WorkerData)3 WorkerSet (org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet)3 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)2 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)2 UTF8CPEntry (org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)2 TraceableCallback (org.ballerinalang.util.tracer.TraceableCallback)2 ArrayList (java.util.ArrayList)1 AsyncInvocableWorkerResponseContext (org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext)1 CallableWorkerResponseContext (org.ballerinalang.bre.bvm.CallableWorkerResponseContext)1 BCallableFuture (org.ballerinalang.model.values.BCallableFuture)1 BStruct (org.ballerinalang.model.values.BStruct)1 AttributeInfo (org.ballerinalang.util.codegen.attributes.AttributeInfo)1 DefaultValueAttributeInfo (org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo)1 ErrorTableAttributeInfo (org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo)1 LineNumberTableAttributeInfo (org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo)1 LocalVariableAttributeInfo (org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo)1 ParamDefaultValueAttributeInfo (org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo)1 VarTypeCountAttributeInfo (org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo)1 StructureRefCPEntry (org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)1