use of org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext 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);
}
use of org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext in project ballerina by ballerina-lang.
the class BLangFunctions method invokeCallable.
/**
* This method does not short circuit the execution of the first worker to execute in the
* same calling thread, but rather executes all the workers in their own separate threads.
* This is specifically useful in executing service resources, where the calling transport
* threads shouldn't be blocked, but rather the worker threads should be used.
*/
public static void invokeCallable(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs, CallableUnitCallback responseCallback) {
WorkerSet workerSet = callableUnitInfo.getWorkerSet();
SyncCallableWorkerResponseContext respCtx = new SyncCallableWorkerResponseContext(callableUnitInfo.getRetParamTypes(), workerSet.generalWorkers.length);
respCtx.registerResponseCallback(responseCallback);
if (TraceManagerWrapper.getInstance().isTraceEnabled()) {
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;
}
initWorkerCAI = workerSet.initWorker.getCodeAttributeInfo();
}
for (int i = 0; i < workerSet.generalWorkers.length; i++) {
executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[i], wdi, initWorkerLocalData, initWorkerCAI, false);
}
}
Aggregations