Search in sources :

Example 1 with AttributeList

use of javax.management.AttributeList 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 2 with AttributeList

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

the class MetricsMBeanImpl method setAttributes.

@Override
public AttributeList setAttributes(AttributeList arg0) {
    AttributeList attributesSet = new AttributeList();
    for (Attribute attr : arg0.asList()) {
        try {
            setAttribute(attr);
            attributesSet.add(attr);
        } catch (AttributeNotFoundException e) {
        // ignore exception - we simply don't add this attribute
        // back in to the resultant set.
        } catch (InvalidAttributeValueException e) {
        // ditto
        } catch (MBeanException e) {
        // likewise
        } catch (ReflectionException e) {
        // and again, one last time.
        }
    }
    return attributesSet;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 3 with AttributeList

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

the class BaseModelMBean method setAttributes.

/**
     * Set the values of several attributes of this MBean.
     *
     * @param attributes THe names and values to be set
     *
     * @return The list of attributes that were set and their new values
     */
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList response = new AttributeList();
    // Validate the input parameters
    if (attributes == null)
        return response;
    // Prepare and return our response, eating all exceptions
    String[] names = new String[attributes.size()];
    int n = 0;
    Iterator<?> items = attributes.iterator();
    while (items.hasNext()) {
        Attribute item = (Attribute) items.next();
        names[n++] = item.getName();
        try {
            setAttribute(item);
        } catch (Exception e) {
        // Ignore all exceptions
        }
    }
    return (getAttributes(names));
}
Also used : Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 4 with AttributeList

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

the class ObjectMBean method setAttributes.

/* ------------------------------------------------------------ */
public AttributeList setAttributes(AttributeList attrs) {
    if (LOG.isDebugEnabled())
        LOG.debug("setAttributes");
    AttributeList results = new AttributeList(attrs.size());
    Iterator<Object> iter = attrs.iterator();
    while (iter.hasNext()) {
        try {
            Attribute attr = (Attribute) iter.next();
            setAttribute(attr);
            results.add(new Attribute(attr.getName(), getAttribute(attr.getName())));
        } catch (Exception e) {
            LOG.warn(Log.EXCEPTION, e);
        }
    }
    return results;
}
Also used : ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException)

Example 5 with AttributeList

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

the class JmxResultProcessorTest method canReadFieldsOfTabularData.

@Test(timeout = 1000)
public void canReadFieldsOfTabularData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
    // Need to induce a GC for the attribute below to be populated
    Runtime.getRuntime().gc();
    ObjectInstance runtime = null;
    try {
        runtime = getG1YoungGen();
    } catch (InstanceNotFoundException e) {
        // ignore test if G1 not enabled
        assumeNoException("G1 GC in Java 7/8 needs to be enabled with -XX:+UseG1GC", e);
    }
    AttributeList attr;
    // but takes a non-deterministic amount of time for LastGcInfo to get populated
    while (true) {
        // but bounded by Test timeout
        attr = ManagementFactory.getPlatformMBeanServer().getAttributes(runtime.getObjectName(), new String[] { "LastGcInfo" });
        if (((Attribute) attr.get(0)).getValue() != null) {
            break;
        }
    }
    List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, attr.asList(), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
    assertThat(results.size()).isGreaterThan(2);
    Optional<Result> result = from(results).firstMatch(new ByAttributeName("LastGcInfo"));
    assertThat(result.isPresent()).isTrue();
    // Should have primitive typed fields
    assertThat(result.get().getValues().size()).isGreaterThan(0);
    assertThat(result.get().getValues().get("duration")).isNotNull();
    // assert tabular fields are excluded
    assertThat(result.get().getValues().get("memoryUsageBeforeGc")).isNull();
    assertThat(result.get().getValues().get("memoryUsageAfterGc")).isNull();
}
Also used : AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) JmxResultProcessor(com.googlecode.jmxtrans.model.JmxResultProcessor) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

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