Search in sources :

Example 21 with Attribute

use of javax.management.Attribute in project jetty.project by eclipse.

the class ObjectMBeanTest method testDerivedAttributes.

/*
     * this test uses the com.acme.Derived test classes
     */
@Test
public void testDerivedAttributes() throws Exception {
    Derived derived = new Derived();
    ObjectMBean mbean = (ObjectMBean) ObjectMBean.mbeanFor(derived);
    ObjectMBean managed = (ObjectMBean) ObjectMBean.mbeanFor(derived.getManagedInstance());
    mbean.setMBeanContainer(container);
    managed.setMBeanContainer(container);
    container.beanAdded(null, derived);
    container.beanAdded(null, derived.getManagedInstance());
    MBeanInfo toss = managed.getMBeanInfo();
    Assert.assertNotNull(mbean.getMBeanInfo());
    MBeanInfo info = mbean.getMBeanInfo();
    Assert.assertEquals("name does not match", "com.acme.Derived", info.getClassName());
    Assert.assertEquals("description does not match", "Test the mbean stuff", info.getDescription());
    // for ( MBeanAttributeInfo i : info.getAttributes())
    // {
    // LOG.debug(i.toString());
    // }
    /*
         * 2 attributes from lifecycle and 2 from Derived and 1 from MBean
         */
    Assert.assertEquals("attribute count does not match", 6, info.getAttributes().length);
    Assert.assertEquals("attribute values does not match", "Full Name", mbean.getAttribute("fname"));
    mbean.setAttribute(new Attribute("fname", "Fuller Name"));
    Assert.assertEquals("set attribute value does not match", "Fuller Name", mbean.getAttribute("fname"));
    Assert.assertEquals("proxy attribute values do not match", "goop", mbean.getAttribute("goop"));
// Thread.sleep(100000);
}
Also used : Derived(com.acme.Derived) MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) Test(org.junit.Test)

Example 22 with Attribute

use of javax.management.Attribute in project jetty.project by eclipse.

the class ObjectMBeanUtilTest method testSetAttributeAttributeWithWrongAttrName.

@Test(expected = AttributeNotFoundException.class)
public void testSetAttributeAttributeWithWrongAttrName() throws Exception {
    // given
    attribute = new Attribute("fnameee", "charu");
    // when
    objectMBean.setAttribute(attribute);
    // then
    fail("An AttributeNotFoundException must have occured by now as there is no attribute " + "with the name ffname in bean");
}
Also used : Attribute(javax.management.Attribute) Test(org.junit.Test)

Example 23 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadMapData.

@Test
public void canReadMapData() throws MalformedObjectNameException {
    Attribute mapAttribute = new Attribute("map", ImmutableMap.of("key1", "value1", "key2", "value2"));
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), new ObjectInstance("java.lang:type=Memory", "java.lang.SomeClass"), ImmutableList.of(mapAttribute), "java.lang.SomeClass", TEST_DOMAIN_NAME).getResults();
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getValues()).hasSize(2);
    assertThat(result.getValues()).isEqualTo(ImmutableMap.of("key1", "value1", "key2", "value2"));
}
Also used : Attribute(javax.management.Attribute) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) ObjectInstance(javax.management.ObjectInstance) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 24 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class JmxResultProcessorTest method canReadMapDataWithNonStringKeys.

@Test
public void canReadMapDataWithNonStringKeys() throws MalformedObjectNameException {
    Attribute mapAttribute = new Attribute("map", ImmutableMap.of(1, "value1", 2, "value2"));
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), new ObjectInstance("java.lang:type=Memory", "java.lang.SomeClass"), ImmutableList.of(mapAttribute), "java.lang.SomeClass", TEST_DOMAIN_NAME).getResults();
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getValues()).hasSize(2);
    assertThat(result.getValues()).isEqualTo(ImmutableMap.of("1", "value1", "2", "value2"));
}
Also used : Attribute(javax.management.Attribute) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) ObjectInstance(javax.management.ObjectInstance) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 25 with Attribute

use of javax.management.Attribute in project jmxtrans by jmxtrans.

the class TreeWalker method walkTree.

public void walkTree(MBeanServerConnection connection) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        String[] attrNames = new String[attrs.length];
        for (int i = 0; i < attrs.length; i++) {
            attrNames[i] = attrs[i].getName();
        }
        try {
            AttributeList attributes = connection.getAttributes(name, attrNames);
            for (Attribute attribute : attributes.asList()) {
                output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue());
            }
        } catch (Exception e) {
            log.error("error getting " + name + ":" + e.getMessage(), e);
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

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