use of org.apache.myriad.scheduler.TaskFactory in project incubator-myriad by apache.
the class MyriadTestModule method configure.
@SuppressWarnings("unchecked")
@Override
protected void configure() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
cfg = mapper.readValue(Thread.currentThread().getContextClassLoader().getResource("myriad-config-test-default.yml"), MyriadConfiguration.class);
} catch (IOException e1) {
LOGGER.error("IOException", e1);
return;
}
if (cfg == null) {
return;
}
bind(MyriadConfiguration.class).toInstance(cfg);
MapBinder<String, TaskFactory> mapBinder = MapBinder.newMapBinder(binder(), String.class, TaskFactory.class);
mapBinder.addBinding(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX).to(NMTaskFactory.class).in(Scopes.SINGLETON);
Map<String, ServiceConfiguration> auxServicesConfigs = cfg.getServiceConfigurations();
for (Map.Entry<String, ServiceConfiguration> entry : auxServicesConfigs.entrySet()) {
String taskFactoryClass = entry.getValue().getTaskFactoryImplName().orNull();
if (taskFactoryClass != null) {
try {
Class<? extends TaskFactory> implClass = (Class<? extends TaskFactory>) Class.forName(taskFactoryClass);
mapBinder.addBinding(entry.getKey()).to(implClass).in(Scopes.SINGLETON);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} else {
mapBinder.addBinding(entry.getKey()).to(ServiceTaskFactory.class).in(Scopes.SINGLETON);
}
}
}
Aggregations