Search in sources :

Example 6 with Task

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());
}
Also used : ParallelTask(org.ak.trafficController.ParallelTask) ParallelExecutingTask(org.ak.trafficController.ParallelExecutingTask) ExecutableTask(org.ak.trafficController.ExecutableTask) Task(org.ak.trafficController.Task) UnlinkedTask(org.ak.trafficController.UnlinkedTask) ParallelTask(org.ak.trafficController.ParallelTask)

Example 7 with Task

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;
}
Also used : ParallelTask(org.ak.trafficController.ParallelTask) ParallelExecutingTask(org.ak.trafficController.ParallelExecutingTask) ExecutableTask(org.ak.trafficController.ExecutableTask) Task(org.ak.trafficController.Task) UnlinkedTask(org.ak.trafficController.UnlinkedTask) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Aggregations

ExecutableTask (org.ak.trafficController.ExecutableTask)7 ParallelExecutingTask (org.ak.trafficController.ParallelExecutingTask)7 ParallelTask (org.ak.trafficController.ParallelTask)7 Task (org.ak.trafficController.Task)7 UnlinkedTask (org.ak.trafficController.UnlinkedTask)7 Around (org.aspectj.lang.annotation.Around)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)3 RunnableToBeExecuted (org.ak.trafficController.RunnableToBeExecuted)2 TaskExecutor (org.ak.trafficController.TaskExecutor)2 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TaskType (org.ak.trafficController.annotations.api.TaskType)1