Search in sources :

Example 76 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class RemoveRouteDefinitionTest method testStopAndRemoveRoute.

public void testStopAndRemoveRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);
    RouteDefinition definition = context.getRouteDefinition("route1");
    List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
    routeDefinitions.add(definition);
    // must stop before we can remove
    context.stopRoute("route1");
    context.removeRoute("route1");
    // route is removed, so its not longer in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(0, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 77 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class TwoManagedCamelContextAutoAssignedNameClashTest method testTwoManagedCamelContextClash.

public void testTwoManagedCamelContextClash() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    camel1 = createCamelContext();
    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());
    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + camel1.getManagementName() + ",type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    // now cheat and reset the counter so we can test for a clash
    DefaultCamelContextNameStrategy.setCounter(0);
    camel2 = createCamelContext();
    camel2.start();
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=" + camel2.getManagementName() + ",type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 78 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class TwoManagedCamelContextClashTest method testTwoManagedCamelContextNoClashCustomPattern.

public void testTwoManagedCamelContextNoClashCustomPattern() throws Exception {
    camel1 = createCamelContext("foo", "killer-#counter#");
    camel2 = createCamelContext("foo", "killer-#counter#");
    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());
    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + camel1.getManagementName() + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    // the pattern has a counter so no clash
    camel2.start();
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=" + camel2.getManagementName() + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 79 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class TwoManagedCamelContextTest method testTwoManagedCamelContext.

public void testTwoManagedCamelContext() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    camel1 = createCamelContext("foo");
    camel2 = createCamelContext("bar");
    camel1.start();
    camel2.start();
    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=foo,type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=bar,type=context,name=\"bar\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));
    camel1.stop();
    camel2.stop();
    assertFalse("Should be unregistered", mbeanServer.isRegistered(on));
    assertFalse("Should be unregistered", mbeanServer.isRegistered(on2));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 80 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedRoute method reset.

public void reset(boolean includeProcessors) throws Exception {
    reset();
    // and now reset all processors for this route
    if (includeProcessors) {
        MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
        if (server != null) {
            // get all the processor mbeans and sort them accordingly to their index
            String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
            ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
            QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp(getRouteId()));
            Set<ObjectName> names = server.queryNames(query, queryExp);
            for (ObjectName name : names) {
                server.invoke(name, "reset", null, null);
            }
        }
    }
}
Also used : QueryExp(javax.management.QueryExp) StringValueExp(javax.management.StringValueExp) AttributeValueExp(javax.management.AttributeValueExp) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

ObjectName (javax.management.ObjectName)1515 MBeanServer (javax.management.MBeanServer)691 Test (org.junit.Test)258 MalformedObjectNameException (javax.management.MalformedObjectNameException)168 IOException (java.io.IOException)101 HashMap (java.util.HashMap)99 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)97 Attribute (javax.management.Attribute)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)94 ArrayList (java.util.ArrayList)91 MBeanServerConnection (javax.management.MBeanServerConnection)72 Map (java.util.Map)66 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)66 MBeanInfo (javax.management.MBeanInfo)64 TabularData (javax.management.openmbean.TabularData)55 JMXServiceURL (javax.management.remote.JMXServiceURL)55 MBeanRegistrationException (javax.management.MBeanRegistrationException)53 JMXConnector (javax.management.remote.JMXConnector)53 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)48 Notification (javax.management.Notification)47