Search in sources :

Example 1 with AttributeValueExp

use of javax.management.AttributeValueExp 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)

Example 2 with AttributeValueExp

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

the class ManagedResetIncludeProcessorsTest method testReset.

public void testReset() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    // send in 5 messages
    template.sendBody("direct:start", "A");
    template.sendBody("direct:start", "B");
    template.sendBody("direct:start", "C");
    template.sendBody("direct:start", "D");
    template.sendBody("direct:start", "E");
    // and 1 for the 2nd route
    template.sendBody("direct:baz", "F");
    assertMockEndpointsSatisfied();
    // should be 5 on the route
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(5, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(5, completed.longValue());
    }
    // reset which should reset all processors also
    mbeanServer.invoke(on, "reset", new Object[] { true }, new String[] { "boolean" });
    // should be 0 on the route
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(0, completed.longValue());
    }
    // test that the 2nd route is untouched, as we only reset the first route
    queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    on = set.iterator().next();
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(1, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(1, completed.longValue());
    }
}
Also used : QueryExp(javax.management.QueryExp) StringValueExp(javax.management.StringValueExp) AttributeValueExp(javax.management.AttributeValueExp) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 3 with AttributeValueExp

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

the class ManagedResetIncludeRoutesTest method testReset.

public void testReset() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    // send in 5 messages
    template.sendBody("direct:start", "A");
    template.sendBody("direct:start", "B");
    template.sendBody("direct:start", "C");
    template.sendBody("direct:start", "D");
    template.sendBody("direct:start", "E");
    // and 1 for the 2nd route
    template.sendBody("direct:baz", "F");
    assertMockEndpointsSatisfied();
    // should be 5 on the route
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(5, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(5, completed.longValue());
    }
    // reset which should reset all routes also
    ObjectName ctx = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
    mbeanServer.invoke(ctx, "reset", new Object[] { true }, new String[] { "boolean" });
    // should be 0 on the route
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(3, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(0, completed.longValue());
    }
    // test that the 2nd route is also reset
    queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
    assertEquals(1, set.size());
    on = set.iterator().next();
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // and on the processors as well
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
    assertEquals(1, set.size());
    for (ObjectName name : set) {
        completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
        assertEquals(0, completed.longValue());
    }
}
Also used : QueryExp(javax.management.QueryExp) StringValueExp(javax.management.StringValueExp) AttributeValueExp(javax.management.AttributeValueExp) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

AttributeValueExp (javax.management.AttributeValueExp)3 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 QueryExp (javax.management.QueryExp)3 StringValueExp (javax.management.StringValueExp)3