executor/src/main/java/com/cognitree/kronos/executor/TaskExecutionService.java
/**
     * submit the task for execution to appropriate handler based on task type.
     *
     * @param task task to submit for execution
     */
submit the task for execution to appropriate handler based on task type.
@param task task to submit for execution
submit the task for execution to appropriate handler based on task type . @param task task to submit for execution
private void submit(Task task) {
        logger.info("Received request to submit task for execution: {}", task.getIdentity());
        final TaskHandler taskHandler;
        try {
            final TaskHandlerConfig taskHandlerConfig = taskTypeToHandlerConfigMap.get(task.getType());
            taskHandler = (TaskHandler) Class.forName(taskHandlerConfig.getHandlerClass())
                    .getConstructor()
                    .newInstance();
            taskHandler.init(task, taskHandlerConfig.getConfig());
        } catch (Exception e) {
            logger.error("Error initializing handler for task {}", task, e);
            sendTaskStatusUpdate(task, FAILED, MISSING_TASK_HANDLER_MESSAGE);
            return;
        }
        taskTypeToRunningTasksCount.put(task.getType(), taskTypeToRunningTasksCount.get(task.getType()) + 1);
        final Future<TaskResult> taskResultFuture = taskExecutorThreadPool.submit(() -> {
            logger.debug("Executing task {}", task.getIdentity());
            sendTaskStatusUpdate(task, RUNNING, null);
            return taskHandler.execute();
        });
        final TaskExecutionContext taskExecutionContext = new TaskExecutionContext(task, task.getRetryCount());
        taskHandlersMap.put(taskExecutionContext, taskHandler);
        taskFuturesMap.put(taskExecutionContext, taskResultFuture);
    }
private void submit ( Task task ) { logger . info ( "Received request to submit task for execution: {}" , task . getIdentity ( ) ) ; final TaskHandler taskHandler ; try { final TaskHandlerConfig taskHandlerConfig = taskTypeToHandlerConfigMap . get ( task . getType ( ) ) ; taskHandler = ( TaskHandler ) Class . forName ( taskHandlerConfig . getHandlerClass ( ) ) . getConstructor ( ) . newInstance ( ) ; taskHandler . init ( task , taskHandlerConfig . getConfig ( ) ) ; } catch ( Exception e ) { logger . error ( "Error initializing handler for task {}" , task , e ) ; sendTaskStatusUpdate ( task , FAILED , MISSING_TASK_HANDLER_MESSAGE ) ; return ; } taskTypeToRunningTasksCount . put ( task . getType ( ) , taskTypeToRunningTasksCount . get ( task . getType ( ) ) + 1 ) ; final Future < TaskResult > taskResultFuture = taskExecutorThreadPool . submit ( ( ) -> { logger . debug ( "Executing task {}" , task . getIdentity ( ) ) ; sendTaskStatusUpdate ( task , RUNNING , null ) ; return taskHandler . execute ( ) ; } ) ; final TaskExecutionContext taskExecutionContext = new TaskExecutionContext ( task , task . getRetryCount ( ) ) ; taskHandlersMap . put ( taskExecutionContext , taskHandler ) ; taskFuturesMap . put ( taskExecutionContext , taskResultFuture ) ; }
submit the task for execution to appropriate handler based on task type.
submit the task for execution to appropriate handler based on task type .