use of org.ak.trafficController.annotations.api.TaskType in project trafficController by amitkhosla.
the class AnnotationSupportImpl method runAsync.
/**
* Handles Async operation where user is looking to submit something to get processed but calling thread should not wait for it.
* If called in Parallel flow, will be added as a async task/
* @param joinPoint Join point
* @param async Async
* @return Returns null if no exception
* @throws Throwable In case of exception in execution of annotated method
*/
@Around("execution(@org.ak.trafficController.annotations.api.Submit * *(..)) && @annotation(async)")
public Object runAsync(ProceedingJoinPoint joinPoint, Submit async) throws Throwable {
RunnableToBeExecuted taskToWorkOn = () -> {
try {
joinPoint.proceed();
} catch (Throwable e) {
logger.log(java.util.logging.Level.WARNING, "exception occured while running a submit request", e);
}
};
TaskExecutor taskExecutor = taskHelper.getTaskExecutor(async, joinPoint);
Task task = null;
TaskType taskType = async.taskType();
switch(taskType) {
case NORMAL:
task = taskExecutor.of(taskToWorkOn);
break;
case SLOW:
task = taskExecutor.slowOf(taskToWorkOn);
}
setThreadingDetailsIfAny(task, async.threadDetailsDataExtractClass(), async.threadDetailsDataExtractMethodName(), async.threadDetailsProcessorClass(), async.threadDetailsProcessorMethodName(), async.threadDetailsCleanerClass(), async.threadDetailsCleanerMethodName());
Task taskInThread = ParallelJoinHelper.getTask();
if (taskInThread == null) {
task.submit();
} else {
AtomicReference<Task> taskReference = new AtomicReference<Task>(task);
((ParallelTask) taskInThread).addRunnables(convertAnnotationTaskTypeToFrameworkTaskType(taskType), taskExecutor, () -> taskExecutor.enque(taskReference.get()));
}
return null;
}
Aggregations