protected ManagementStrategy createManagementStrategy() {
ManagementStrategy answer;
if (disableJMX || Boolean.getBoolean(JmxSystemPropertyKeys.DISABLED)) {
log.info("JMX is disabled. Using DefaultManagementStrategy.");
answer = new DefaultManagementStrategy();
} else {
try {
log.info("JMX enabled. Using ManagedManagementStrategy.");
answer = new ManagedManagementStrategy(new DefaultManagementAgent(this));
// must start it to ensure JMX works and can load needed Spring JARs
startServices(answer);
// prefer to have it at first strategy
lifecycleStrategies.add(0, new DefaultManagementLifecycleStrategy(this));
} catch (NoClassDefFoundError e) {
answer = null;
// if we can't instantiate the JMX enabled strategy then fallback to default
// could be because of missing .jars on the classpath
log.warn("Cannot find needed classes for JMX lifecycle strategy."
+ " Needed class is in spring-context.jar using Spring 2.5 or newer"
+ " (spring-jmx.jar using Spring 2.0.x)."
+ " NoClassDefFoundError: " + e.getMessage());
} catch (Exception e) {
answer = null;
log.warn("Cannot create JMX lifecycle strategy. Fallback to using DefaultManagementStrategy (non JMX).", e);
}
}
if (answer == null) {
log.warn("Cannot use JMX. Fallback to using DefaultManagementStrategy (non JMX).");
answer = new DefaultManagementStrategy();
}
// inject CamelContext
if (answer instanceof CamelContextAware) {
CamelContextAware aware = (CamelContextAware) answer;