use of com.cloud.utils.mgmt.ManagementBean in project cloudstack by apache.
the class ComponentContext method initComponentsLifeCycle.
public static void initComponentsLifeCycle() {
if (!s_initializeBeans)
return;
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(ComponentMethodInterceptable.class);
for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
Object bean = getTargetObject(entry.getValue());
beanFactory.configureBean(bean, entry.getKey());
}
Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
Map<String, ComponentLifecycle>[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
classifiedComponents[i] = new HashMap<String, ComponentLifecycle>();
}
for (Map.Entry<String, ComponentLifecycle> entry : lifecycleComponents.entrySet()) {
classifiedComponents[entry.getValue().getRunLevel()].put(entry.getKey(), entry.getValue());
}
// Run the SystemIntegrityCheckers first
Map<String, SystemIntegrityChecker> integrityCheckers = getApplicationContext().getBeansOfType(SystemIntegrityChecker.class);
for (Entry<String, SystemIntegrityChecker> entry : integrityCheckers.entrySet()) {
s_logger.info("Running SystemIntegrityChecker " + entry.getKey());
try {
entry.getValue().check();
} catch (Throwable e) {
s_logger.error("System integrity check failed. Refuse to startup", e);
System.exit(1);
}
}
// configuration phase
Map<String, String> avoidMap = new HashMap<String, String>();
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
ComponentLifecycle component = entry.getValue();
String implClassName = ComponentContext.getTargetClass(component).getName();
s_logger.info("Configuring " + implClassName);
if (avoidMap.containsKey(implClassName)) {
s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
continue;
}
try {
component.configure(component.getName(), component.getConfigParams());
} catch (ConfigurationException e) {
s_logger.error("Unhandled exception", e);
throw new RuntimeException("Unable to configure " + implClassName, e);
}
avoidMap.put(implClassName, implClassName);
}
}
// starting phase
avoidMap.clear();
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
ComponentLifecycle component = entry.getValue();
String implClassName = ComponentContext.getTargetClass(component).getName();
s_logger.info("Starting " + implClassName);
if (avoidMap.containsKey(implClassName)) {
s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
continue;
}
try {
component.start();
if (getTargetObject(component) instanceof ManagementBean)
registerMBean((ManagementBean) getTargetObject(component));
} catch (Exception e) {
s_logger.error("Unhandled exception", e);
throw new RuntimeException("Unable to start " + implClassName, e);
}
avoidMap.put(implClassName, implClassName);
}
}
}
Aggregations