use of org.ak.trafficController.Task in project trafficController by amitkhosla.
the class AnnotationSupportImpl method subProcessHandling.
/**
* Sub process handling. This method will be called while handling Parallel in case where parallel is being called inside another parallel flow.
* @param currentParallelId Current parallel id
* @param taskId Task id
* @param earlierParallelTaskId Earlier parallel task id
* @param originalTask Original task
* @param thisParallelTask Current parallel task
*/
protected void subProcessHandling(int currentParallelId, AtomicInteger taskId, AtomicInteger earlierParallelTaskId, Task originalTask, ExecutableTask thisParallelTask) {
Task task = parallelJoinHelper.getTask().then(() -> {
Object result = performCleanup(currentParallelId);
if (Objects.nonNull(result)) {
ParallelJoinHelper.putObject(earlierParallelTaskId.get(), taskId.get(), result);
}
});
((ParallelTask) originalTask).addTask(thisParallelTask);
parallelJoinHelper.setTask(originalTask);
ParallelJoinHelper.removeParallelId(currentParallelId);
ParallelJoinHelper.setParallelTaskId(earlierParallelTaskId.get());
}
use of org.ak.trafficController.Task in project trafficController by amitkhosla.
the class AnnotationSupportImpl method runJoin.
/**
* Handles Join operation.
* Annotated method will be called with exactly same number of attributes for which non null data was returned by controlled methods.
* If we have 4 methods defined and out of which 2 methods returned some value, join annotated method is expected to expect only these two methods in the same sequence as they would have called sequentially.
* @param joinPoint Join point
* @param join Join
* @return This method will return null but will set output against its id in parallel map
* @throws Throwable In case there is issue in processing
*/
@Around("execution(@org.ak.trafficController.annotations.api.Join * *(..)) && @annotation(join)")
public Object runJoin(ProceedingJoinPoint joinPoint, Join join) throws Throwable {
int taskId = parallelJoinHelper.getObjectKeyForParalleldTask();
int parallelTaskId = ParallelJoinHelper.getParallelId();
AtomicReference<Object> output = new AtomicReference<Object>(null);
Task joinerTask = parallelJoinHelper.getTask().then(() -> {
List<Object> list = new ArrayList<>();
addAllResultObjectsTillNowInList(list, parallelTaskId, taskId);
if (!list.isEmpty()) {
output.set(joinPoint.proceed(getObjectArrayFromList(list)));
} else {
output.set(joinPoint.proceed());
}
JoinResult jr = new JoinResult();
jr.result = output.get();
ParallelJoinHelper.map.get(parallelTaskId).put(taskId, jr);
});
joinerTask.setName("joiner ParallelId:" + parallelTaskId + " taskId : " + taskId + getTaskNameFromJoinPoint(joinPoint));
parallelJoinHelper.setTask(joinerTask);
setThreadingDetailsIfAny(joinerTask, join.threadDetailsDataExtractClass(), join.threadDetailsDataExtractMethodName(), join.threadDetailsProcessorClass(), join.threadDetailsProcessorMethodName(), join.threadDetailsCleanerClass(), join.threadDetailsCleanerMethodName());
return null;
}
Aggregations