Search in sources :

Example 11 with Attribute

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

the class ManagedStatisticsDisabledTest method testManageStatisticsDisabled.

public void testManageStatisticsDisabled() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    // use route to get the total time
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(2, completed.longValue());
    // disable statistics
    mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", false));
    // send in another message
    template.sendBody("direct:start", "Goodday World");
    // should stay at 2
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(2, completed.longValue());
    // enable statistics
    mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", true));
    // send in another message
    template.sendBody("direct:start", "Hi World");
    // should now be 3
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(3, completed.longValue());
    // now reset it
    mbeanServer.invoke(on, "reset", null, null);
    // send in another message
    template.sendBody("direct:start", "Hallo World");
    // should now be 1
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
}
Also used : Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 12 with Attribute

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

the class ManagedStatisticsLevelOffTest method testManageStatisticsLevelDisabled.

public void testManageStatisticsLevelDisabled() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    // use route to get the total time
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    // enable statistics
    mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", true));
    // send in another message
    template.sendBody("direct:start", "Goodday World");
    // should be 1
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
}
Also used : Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 13 with Attribute

use of javax.management.Attribute in project hadoop by apache.

the class MetricsSourceAdapter method setAttrCacheTag.

private void setAttrCacheTag(MetricsTag tag, int recNo) {
    String key = tagName(tag.name(), recNo);
    attrCache.put(key, new Attribute(key, tag.value()));
}
Also used : Attribute(javax.management.Attribute)

Example 14 with Attribute

use of javax.management.Attribute in project hadoop by apache.

the class MetricsSourceAdapter method getAttributes.

@Override
public AttributeList getAttributes(String[] attributes) {
    updateJmxCache();
    synchronized (this) {
        AttributeList ret = new AttributeList();
        for (String key : attributes) {
            Attribute attr = attrCache.get(key);
            if (LOG.isDebugEnabled()) {
                LOG.debug(key + ": " + attr);
            }
            ret.add(attr);
        }
        return ret;
    }
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList)

Example 15 with Attribute

use of javax.management.Attribute in project hive by apache.

the class TestLegacyMetrics method testMetricsMBean.

@Test
public void testMetricsMBean() throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ObjectName oname = new ObjectName("org.apache.hadoop.hive.common.metrics:type=MetricsMBean");
    MBeanInfo mBeanInfo = mbs.getMBeanInfo(oname);
    // check implementation class:
    assertEquals(MetricsMBeanImpl.class.getName(), mBeanInfo.getClassName());
    // check reset operation:
    MBeanOperationInfo[] oops = mBeanInfo.getOperations();
    boolean resetFound = false;
    for (MBeanOperationInfo op : oops) {
        if ("reset".equals(op.getName())) {
            resetFound = true;
            break;
        }
    }
    assertTrue(resetFound);
    // add metric with a non-null value:
    Attribute attr = new Attribute("fooMetric", Long.valueOf(-77));
    mbs.setAttribute(oname, attr);
    mBeanInfo = mbs.getMBeanInfo(oname);
    MBeanAttributeInfo[] attrinuteInfos = mBeanInfo.getAttributes();
    assertEquals(1, attrinuteInfos.length);
    boolean attrFound = false;
    for (MBeanAttributeInfo info : attrinuteInfos) {
        if ("fooMetric".equals(info.getName())) {
            assertEquals("java.lang.Long", info.getType());
            assertTrue(info.isReadable());
            assertTrue(info.isWritable());
            assertFalse(info.isIs());
            attrFound = true;
            break;
        }
    }
    assertTrue(attrFound);
    // check metric value:
    Object v = mbs.getAttribute(oname, "fooMetric");
    assertEquals(Long.valueOf(-77), v);
    // reset the bean:
    Object result = mbs.invoke(oname, "reset", new Object[0], new String[0]);
    assertNull(result);
    // the metric value must be zeroed:
    v = mbs.getAttribute(oname, "fooMetric");
    assertEquals(Long.valueOf(0), v);
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9