Search in sources :

Example 1 with ForkJoinTimeoutCallback

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

the class BLangFunctions method invokeForkJoin.

public static WorkerExecutionContext invokeForkJoin(WorkerExecutionContext parentCtx, ForkjoinInfo forkjoinInfo, int joinTargetIp, int joinVarReg, int timeoutRegIndex, int timeoutTargetIp, int timeoutVarReg) {
    WorkerInfo[] workerInfos = forkjoinInfo.getWorkerInfos();
    Set<String> joinWorkerNames = new LinkedHashSet<>(Lists.of(forkjoinInfo.getJoinWorkerNames()));
    if (joinWorkerNames.isEmpty()) {
        /* if no join workers are specified, that means, all should be considered */
        joinWorkerNames.addAll(forkjoinInfo.getWorkerInfoMap().keySet());
    }
    Map<String, String> channels = getChannels(forkjoinInfo);
    int reqJoinCount;
    if (forkjoinInfo.getJoinType().equalsIgnoreCase(JOIN_TYPE_SOME)) {
        reqJoinCount = forkjoinInfo.getWorkerCount();
    } else {
        reqJoinCount = joinWorkerNames.size();
    }
    SyncCallableWorkerResponseContext respCtx = new ForkJoinWorkerResponseContext(parentCtx, joinTargetIp, joinVarReg, timeoutTargetIp, timeoutVarReg, workerInfos.length, reqJoinCount, joinWorkerNames, channels);
    if (forkjoinInfo.isTimeoutAvailable()) {
        long timeout = parentCtx.workerLocal.longRegs[timeoutRegIndex];
        // fork join timeout is in seconds, hence converting to milliseconds
        AsyncTimer.schedule(new ForkJoinTimeoutCallback(respCtx), timeout * 1000);
    }
    Map<String, Object> globalProps = parentCtx.globalProps;
    BLangScheduler.workerWaitForResponse(parentCtx);
    for (int i = 1; i < workerInfos.length; i++) {
        executeWorker(respCtx, parentCtx, forkjoinInfo.getArgRegs(), workerInfos[i], globalProps, false);
    }
    return executeWorker(respCtx, parentCtx, forkjoinInfo.getArgRegs(), workerInfos[0], globalProps, true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ForkJoinTimeoutCallback(org.ballerinalang.bre.bvm.ForkJoinTimeoutCallback) WorkerInfo(org.ballerinalang.util.codegen.WorkerInfo) ForkJoinWorkerResponseContext(org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext) SyncCallableWorkerResponseContext(org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 ForkJoinTimeoutCallback (org.ballerinalang.bre.bvm.ForkJoinTimeoutCallback)1 ForkJoinWorkerResponseContext (org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext)1 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)1 WorkerInfo (org.ballerinalang.util.codegen.WorkerInfo)1