Search in sources :

Example 1 with TaskType

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;
}
Also used : RunnableToBeExecuted(org.ak.trafficController.RunnableToBeExecuted) TaskExecutor(org.ak.trafficController.TaskExecutor) 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) TaskType(org.ak.trafficController.annotations.api.TaskType) AtomicReference(java.util.concurrent.atomic.AtomicReference) ParallelTask(org.ak.trafficController.ParallelTask) Around(org.aspectj.lang.annotation.Around)

Aggregations

AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ExecutableTask (org.ak.trafficController.ExecutableTask)1 ParallelExecutingTask (org.ak.trafficController.ParallelExecutingTask)1 ParallelTask (org.ak.trafficController.ParallelTask)1 RunnableToBeExecuted (org.ak.trafficController.RunnableToBeExecuted)1 Task (org.ak.trafficController.Task)1 TaskExecutor (org.ak.trafficController.TaskExecutor)1 UnlinkedTask (org.ak.trafficController.UnlinkedTask)1 TaskType (org.ak.trafficController.annotations.api.TaskType)1 Around (org.aspectj.lang.annotation.Around)1