use of org.ballerinalang.util.codegen.WorkerInfo 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);
}
Aggregations