use of org.apache.airavata.datalake.orchestrator.workflow.engine.task.BlockingTask in project airavata-data-lake by apache.
the class Participant method getTaskFactory.
private Map<String, TaskFactory> getTaskFactory() throws Exception {
Map<String, TaskFactory> taskMap = new HashMap<>();
for (String className : blockingTaskClasses) {
try {
logger.info("Loading blocking task {}", className);
Class<?> taskClz = Class.forName(className);
Object taskObj = taskClz.getConstructor().newInstance();
BlockingTask blockingTask = (BlockingTask) taskObj;
TaskFactory taskFactory = context -> {
blockingTask.setCallbackContext(context);
return blockingTask;
};
BlockingTaskDef btDef = blockingTask.getClass().getAnnotation(BlockingTaskDef.class);
taskMap.put(btDef.name(), taskFactory);
} catch (ClassNotFoundException e) {
logger.error("Couldn't find a class with name {}", className);
throw e;
}
}
for (String className : nonBlockingTaskClasses) {
try {
logger.info("Loading non blocking task {}", className);
Class<?> taskClz = Class.forName(className);
Object taskObj = taskClz.getConstructor().newInstance();
NonBlockingTask nonBlockingTask = (NonBlockingTask) taskObj;
TaskFactory taskFactory = context -> {
nonBlockingTask.setCallbackContext(context);
return nonBlockingTask;
};
NonBlockingTaskDef nbtDef = nonBlockingTask.getClass().getAnnotation(NonBlockingTaskDef.class);
taskMap.put(nbtDef.name(), taskFactory);
} catch (ClassNotFoundException e) {
logger.error("Couldn't find a class with name {}", className);
throw e;
}
}
return taskMap;
}
Aggregations