Search in sources :

Example 31 with AttributeList

use of javax.management.AttributeList in project sling by apache.

the class MBeanResource method getAttributes.

public AttributeList getAttributes() {
    if (this.attributeList == null) {
        final MBeanAttributeInfo[] infos = info.getAttributes();
        final String[] names = new String[infos.length];
        int index = 0;
        for (final MBeanAttributeInfo i : infos) {
            names[index] = i.getName();
            index++;
        }
        try {
            this.attributeList = mbeanServer.getAttributes(objectName, names);
        } catch (InstanceNotFoundException e) {
            // ignore
            this.attributeList = new AttributeList();
        } catch (ReflectionException e) {
            // ignore
            this.attributeList = new AttributeList();
        }
    }
    return this.attributeList;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 32 with AttributeList

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

the class ObjectMBeanUtilTest method getAttributes.

private AttributeList getAttributes(String name, String value) {
    Attribute attribute = new Attribute(name, value);
    AttributeList attributes = new AttributeList();
    attributes.add(attribute);
    return attributes;
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList)

Example 33 with AttributeList

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

the class JmxResultProcessorTest method canReadCompositeData.

@Test
public void canReadCompositeData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
    ObjectInstance memory = getMemory();
    AttributeList attr = ManagementFactory.getPlatformMBeanServer().getAttributes(memory.getObjectName(), new String[] { "HeapMemoryUsage" });
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), memory, attr.asList(), memory.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getAttributeName()).isEqualTo("HeapMemoryUsage");
    assertThat(result.getTypeName()).isEqualTo("type=Memory");
    Map<String, Object> values = result.getValues();
    assertThat(values).hasSize(4);
    Object objectValue = result.getValues().get("init");
    assertThat(objectValue).isInstanceOf(Long.class);
}
Also used : AttributeList(javax.management.AttributeList) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Example 34 with AttributeList

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

the class Query method fetchResults.

public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
    MBeanInfo info = mbeanServer.getMBeanInfo(queryName);
    ObjectInstance oi = mbeanServer.getObjectInstance(queryName);
    List<String> attributes;
    if (attr.isEmpty()) {
        attributes = new ArrayList<>();
        for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
            attributes.add(attrInfo.getName());
        }
    } else {
        attributes = attr;
    }
    try {
        if (!attributes.isEmpty()) {
            logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this);
            AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()]));
            return new JmxResultProcessor(this, oi, al.asList(), info.getClassName(), queryName.getDomain()).getResults();
        }
    } catch (UnmarshalException ue) {
        if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) {
            logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage());
        } else {
            throw ue;
        }
    }
    return ImmutableList.of();
}
Also used : MBeanInfo(javax.management.MBeanInfo) AttributeList(javax.management.AttributeList) UnmarshalException(java.rmi.UnmarshalException) ObjectInstance(javax.management.ObjectInstance) ToString(lombok.ToString) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 35 with AttributeList

use of javax.management.AttributeList in project graphdb by neo4j-attic.

the class Neo4jManager method getConfiguration.

public Map<String, Object> getConfiguration() {
    final String[] keys;
    final AttributeList attributes;
    try {
        MBeanAttributeInfo[] keyInfo = server.getMBeanInfo(config).getAttributes();
        keys = new String[keyInfo.length];
        for (int i = 0; i < keys.length; i++) {
            keys[i] = keyInfo[i].getName();
        }
        attributes = server.getAttributes(config, keys);
    } catch (Exception e) {
        throw new IllegalStateException("Could not access the configuration bean", e);
    }
    Map<String, Object> configuration = new HashMap<String, Object>();
    for (int i = 0; i < keys.length; i++) {
        configuration.put(keys[i], attributes.get(i));
    }
    return configuration;
}
Also used : HashMap(java.util.HashMap) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Aggregations

AttributeList (javax.management.AttributeList)56 Attribute (javax.management.Attribute)46 ReflectionException (javax.management.ReflectionException)22 AttributeNotFoundException (javax.management.AttributeNotFoundException)16 InstanceNotFoundException (javax.management.InstanceNotFoundException)16 MBeanException (javax.management.MBeanException)15 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)14 ObjectName (javax.management.ObjectName)14 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)10 MBeanServer (javax.management.MBeanServer)8 IOException (java.io.IOException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 MBeanInfo (javax.management.MBeanInfo)7 RuntimeOperationsException (javax.management.RuntimeOperationsException)7 HashMap (java.util.HashMap)6 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4