use of org.apache.camel.management.DefaultManagementAgent in project camel by apache.
the class AbstractCamelContextFactoryBean method initJMXAgent.
protected void initJMXAgent() throws Exception {
CamelJMXAgentDefinition camelJMXAgent = getCamelJMXAgent();
boolean disabled = false;
if (camelJMXAgent != null) {
disabled = camelJMXAgent.getDisabled() != null && CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getDisabled());
}
if (disabled) {
LOG.info("JMXAgent disabled");
// clear the existing lifecycle strategies define by the DefaultCamelContext constructor
getContext().getLifecycleStrategies().clear();
// no need to add a lifecycle strategy as we do not need one as JMX is disabled
getContext().setManagementStrategy(new DefaultManagementStrategy());
} else if (camelJMXAgent != null) {
LOG.info("JMXAgent enabled: {}", camelJMXAgent);
DefaultManagementAgent agent = new DefaultManagementAgent(getContext());
if (camelJMXAgent.getConnectorPort() != null) {
agent.setConnectorPort(CamelContextHelper.parseInteger(getContext(), camelJMXAgent.getConnectorPort()));
}
if (camelJMXAgent.getCreateConnector() != null) {
agent.setCreateConnector(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getCreateConnector()));
}
if (camelJMXAgent.getMbeanObjectDomainName() != null) {
agent.setMBeanObjectDomainName(CamelContextHelper.parseText(getContext(), camelJMXAgent.getMbeanObjectDomainName()));
}
if (camelJMXAgent.getMbeanServerDefaultDomain() != null) {
agent.setMBeanServerDefaultDomain(CamelContextHelper.parseText(getContext(), camelJMXAgent.getMbeanServerDefaultDomain()));
}
if (camelJMXAgent.getRegistryPort() != null) {
agent.setRegistryPort(CamelContextHelper.parseInteger(getContext(), camelJMXAgent.getRegistryPort()));
}
if (camelJMXAgent.getServiceUrlPath() != null) {
agent.setServiceUrlPath(CamelContextHelper.parseText(getContext(), camelJMXAgent.getServiceUrlPath()));
}
if (camelJMXAgent.getUsePlatformMBeanServer() != null) {
agent.setUsePlatformMBeanServer(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getUsePlatformMBeanServer()));
}
if (camelJMXAgent.getOnlyRegisterProcessorWithCustomId() != null) {
agent.setOnlyRegisterProcessorWithCustomId(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getOnlyRegisterProcessorWithCustomId()));
}
if (camelJMXAgent.getRegisterAlways() != null) {
agent.setRegisterAlways(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getRegisterAlways()));
}
if (camelJMXAgent.getRegisterNewRoutes() != null) {
agent.setRegisterNewRoutes(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getRegisterNewRoutes()));
}
if (camelJMXAgent.getIncludeHostName() != null) {
agent.setIncludeHostName(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getIncludeHostName()));
}
if (camelJMXAgent.getUseHostIPAddress() != null) {
agent.setUseHostIPAddress(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getUseHostIPAddress()));
}
if (camelJMXAgent.getMask() != null) {
agent.setMask(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getMask()));
}
if (camelJMXAgent.getLoadStatisticsEnabled() != null) {
agent.setLoadStatisticsEnabled(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getLoadStatisticsEnabled()));
}
if (camelJMXAgent.getEndpointRuntimeStatisticsEnabled() != null) {
agent.setEndpointRuntimeStatisticsEnabled(CamelContextHelper.parseBoolean(getContext(), camelJMXAgent.getEndpointRuntimeStatisticsEnabled()));
}
if (camelJMXAgent.getStatisticsLevel() != null) {
String level = CamelContextHelper.parseText(getContext(), camelJMXAgent.getStatisticsLevel());
ManagementStatisticsLevel msLevel = getContext().getTypeConverter().mandatoryConvertTo(ManagementStatisticsLevel.class, level);
agent.setStatisticsLevel(msLevel);
}
ManagementStrategy managementStrategy = new ManagedManagementStrategy(getContext(), agent);
getContext().setManagementStrategy(managementStrategy);
// clear the existing lifecycle strategies define by the DefaultCamelContext constructor
getContext().getLifecycleStrategies().clear();
getContext().addLifecycleStrategy(new DefaultManagementLifecycleStrategy(getContext()));
}
}
use of org.apache.camel.management.DefaultManagementAgent in project camel by apache.
the class CamelServletContextListener method initJmx.
/**
* Initializes JMX on {@link ServletCamelContext} with the configuration from the given init parameters.
*/
private void initJmx(ServletCamelContext camelContext, Map<String, Object> parameters) throws Exception {
// setup jmx
Map<String, Object> properties = IntrospectionSupport.extractProperties(parameters, "jmx.");
if (properties != null && !properties.isEmpty()) {
String disabled = (String) properties.remove("disabled");
boolean disableJmx = CamelContextHelper.parseBoolean(camelContext, disabled != null ? disabled : "false");
if (disableJmx) {
// disable JMX which is a bit special to do
LOG.info("JMXAgent disabled");
// clear the existing lifecycle strategies define by the DefaultCamelContext constructor
camelContext.getLifecycleStrategies().clear();
// no need to add a lifecycle strategy as we do not need one as JMX is disabled
camelContext.setManagementStrategy(new DefaultManagementStrategy());
} else {
LOG.info("JMXAgent enabled");
DefaultManagementAgent agent = new DefaultManagementAgent(camelContext);
IntrospectionSupport.setProperties(agent, properties);
ManagementStrategy managementStrategy = new ManagedManagementStrategy(camelContext, agent);
camelContext.setManagementStrategy(managementStrategy);
// clear the existing lifecycle strategies defined by the DefaultCamelContext constructor
camelContext.getLifecycleStrategies().clear();
camelContext.addLifecycleStrategy(new DefaultManagementLifecycleStrategy(camelContext));
// set additional configuration from agent
boolean onlyId = agent.getOnlyRegisterProcessorWithCustomId() != null && agent.getOnlyRegisterProcessorWithCustomId();
camelContext.getManagementStrategy().onlyManageProcessorWithCustomId(onlyId);
String statisticsLevel = (String) properties.remove("statisticsLevel");
if (statisticsLevel != null) {
camelContext.getManagementStrategy().setStatisticsLevel(ManagementStatisticsLevel.valueOf(statisticsLevel));
}
String loadStatisticsEnabled = (String) properties.remove("loadStatisticsEnabled");
Boolean statisticsEnabled = CamelContextHelper.parseBoolean(camelContext, loadStatisticsEnabled != null ? loadStatisticsEnabled : "true");
if (statisticsEnabled != null) {
camelContext.getManagementStrategy().setLoadStatisticsEnabled(statisticsEnabled);
}
}
// validate we could set all parameters
if (!properties.isEmpty()) {
throw new IllegalArgumentException("Error setting jmx parameters on CamelContext." + " There are " + properties.size() + " unknown parameters. [" + properties + "]");
}
}
}
Aggregations