Search in sources :

Example 1 with Attribute

use of javax.management.Attribute 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 2 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 3 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 4 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 5 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)

Aggregations

Attribute (javax.management.Attribute)306 ObjectName (javax.management.ObjectName)133 AttributeList (javax.management.AttributeList)119 ReflectionException (javax.management.ReflectionException)83 MBeanServer (javax.management.MBeanServer)68 MBeanException (javax.management.MBeanException)66 InstanceNotFoundException (javax.management.InstanceNotFoundException)62 AttributeNotFoundException (javax.management.AttributeNotFoundException)60 Test (org.junit.Test)54 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)47 Test (org.testng.annotations.Test)36 HashMap (java.util.HashMap)34 MBeanInfo (javax.management.MBeanInfo)30 IntrospectionException (javax.management.IntrospectionException)27 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)25 MBeanServerConnection (javax.management.MBeanServerConnection)24 IOException (java.io.IOException)21 MalformedObjectNameException (javax.management.MalformedObjectNameException)21 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ListenerNotFoundException (javax.management.ListenerNotFoundException)17