use of org.apache.camel.spi.ManagementAgent in project camel by apache.
the class DefaultManagementLifecycleStrategy method shouldRegister.
/**
* Whether or not to register the mbean.
* <p/>
* The {@link ManagementAgent} has options which controls when to register.
* This allows us to only register mbeans accordingly. For example by default any
* dynamic endpoints is not registered. This avoids to register excessive mbeans, which
* most often is not desired.
*
* @param service the object to register
* @param route an optional route the mbean is associated with, can be <tt>null</tt>
* @return <tt>true</tt> to register, <tt>false</tt> to skip registering
*/
protected boolean shouldRegister(Object service, Route route) {
// the agent hasn't been started
if (!initialized) {
return false;
}
LOG.trace("Checking whether to register {} from route: {}", service, route);
ManagementAgent agent = getManagementStrategy().getManagementAgent();
if (agent == null) {
// do not register if no agent
return false;
}
// always register if we are starting CamelContext
if (getCamelContext().getStatus().isStarting()) {
return true;
}
// always register if we are setting up routes
if (getCamelContext().isSetupRoutes()) {
return true;
}
// register if always is enabled
if (agent.getRegisterAlways()) {
return true;
}
// is it a known route then always accept
if (route != null && knowRouteIds.contains(route.getId())) {
return true;
}
// only register if we are starting a new route, and current thread is in starting routes mode
if (agent.getRegisterNewRoutes()) {
// which is kept as state on the camel context
return getCamelContext().isStartingRoutes();
}
return false;
}
use of org.apache.camel.spi.ManagementAgent in project camel by apache.
the class DefaultManagementAgentMockTest method testObjectNameModification.
@Test
public void testObjectNameModification() throws JMException {
MBeanServer mbeanServer = createStrictMock(MBeanServer.class);
ObjectInstance instance = createStrictMock(ObjectInstance.class);
ManagementAgent agent = new DefaultManagementAgent();
agent.setMBeanServer(mbeanServer);
Object object = "object";
ObjectName sourceObjectName = new ObjectName("domain", "key", "value");
ObjectName registeredObjectName = new ObjectName("domain", "key", "otherValue");
// Register MBean and return different ObjectName
expect(mbeanServer.isRegistered(sourceObjectName)).andReturn(false);
expect(mbeanServer.registerMBean(object, sourceObjectName)).andReturn(instance);
expect(instance.getObjectName()).andReturn(registeredObjectName);
expect(mbeanServer.isRegistered(registeredObjectName)).andReturn(true);
replay(mbeanServer, instance);
agent.register(object, sourceObjectName);
assertTrue(agent.isRegistered(sourceObjectName));
verify(mbeanServer, instance);
reset(mbeanServer, instance);
// ... and unregister it again
expect(mbeanServer.isRegistered(registeredObjectName)).andReturn(true);
mbeanServer.unregisterMBean(registeredObjectName);
expect(mbeanServer.isRegistered(sourceObjectName)).andReturn(false);
replay(mbeanServer);
agent.unregister(sourceObjectName);
assertFalse(agent.isRegistered(sourceObjectName));
verify(mbeanServer);
}
use of org.apache.camel.spi.ManagementAgent in project camel by apache.
the class DefaultManagementAgentMockTest method shouldUseHostNameWhenFlagisFalse.
@Test
public void shouldUseHostNameWhenFlagisFalse() throws Exception {
System.setProperty(JmxSystemPropertyKeys.USE_HOST_IP_ADDRESS, "false");
System.setProperty(JmxSystemPropertyKeys.CREATE_CONNECTOR, "true");
CamelContext ctx = new DefaultCamelContext();
ManagementAgent agent = new DefaultManagementAgent(ctx);
agent.start();
assertFalse(agent.getUseHostIPAddress());
}
use of org.apache.camel.spi.ManagementAgent in project camel by apache.
the class DefaultManagementAgentMockTest method testShouldUseHostIPAddressWhenFlagisTrue.
@Test
public void testShouldUseHostIPAddressWhenFlagisTrue() throws Exception {
System.setProperty(JmxSystemPropertyKeys.USE_HOST_IP_ADDRESS, "true");
System.setProperty(JmxSystemPropertyKeys.CREATE_CONNECTOR, "true");
CamelContext ctx = new DefaultCamelContext();
ManagementAgent agent = new DefaultManagementAgent(ctx);
agent.start();
assertTrue(agent.getUseHostIPAddress());
}
Aggregations