use of com.hortonworks.registries.schemaregistry.HAServersAware in project registry by hortonworks.
the class RegistryApplication method registerResources.
private void registerResources(Environment environment, RegistryConfiguration registryConfiguration) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
storageManager = getStorageManager(registryConfiguration.getStorageProviderConfiguration());
if (storageManager instanceof TransactionManager)
transactionManager = (TransactionManager) storageManager;
else
transactionManager = new NOOPTransactionManager();
FileStorage fileStorage = getJarStorage(registryConfiguration.getFileStorageConfiguration());
List<ModuleConfiguration> modules = registryConfiguration.getModules();
List<Object> resourcesToRegister = new ArrayList<>();
for (ModuleConfiguration moduleConfiguration : modules) {
String moduleName = moduleConfiguration.getName();
String moduleClassName = moduleConfiguration.getClassName();
LOG.info("Registering module [{}] with class [{}]", moduleName, moduleClassName);
ModuleRegistration moduleRegistration = (ModuleRegistration) Class.forName(moduleClassName).newInstance();
if (moduleConfiguration.getConfig() == null) {
moduleConfiguration.setConfig(new HashMap<String, Object>());
}
moduleRegistration.init(moduleConfiguration.getConfig(), fileStorage);
if (moduleRegistration instanceof StorageManagerAware) {
LOG.info("Module [{}] is StorageManagerAware and setting StorageManager.", moduleName);
StorageManagerAware storageManagerAware = (StorageManagerAware) moduleRegistration;
storageManagerAware.setStorageManager(storageManager);
}
if (moduleRegistration instanceof LeadershipAware) {
LOG.info("Module [{}] is registered for LeadershipParticipant registration.", moduleName);
LeadershipAware leadershipAware = (LeadershipAware) moduleRegistration;
leadershipAware.setLeadershipParticipant(leadershipParticipantRef);
}
if (moduleRegistration instanceof HAServersAware) {
LOG.info("Module [{}] is registered for HAServersAware registration.");
HAServersAware leadershipAware = (HAServersAware) moduleRegistration;
leadershipAware.setHAServerConfigManager(haServerNotificationManager);
}
resourcesToRegister.addAll(moduleRegistration.getResources());
}
LOG.info("Registering resources to Jersey environment: [{}]", resourcesToRegister);
for (Object resource : resourcesToRegister) {
environment.jersey().register(resource);
}
environment.jersey().register(MultiPartFeature.class);
environment.jersey().register(new TransactionEventListener(transactionManager));
}
Aggregations