Search in sources :

Example 21 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project jspwiki by apache.

the class SimpleMBean method getAttribute.

/**
 *  Gets an attribute using reflection from the MBean.
 *
 *  @param name Name of the attribute to find.
 *  @return The value returned by the corresponding getXXX() call
 *  @throws AttributeNotFoundException If there is not such attribute
 *  @throws MBeanException
 *  @throws ReflectionException
 */
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    Method m;
    Object res = null;
    try {
        String mname = "get" + StringUtils.capitalize(name);
        m = findGetterSetter(getClass(), mname, null);
        if (m == null)
            throw new AttributeNotFoundException(name);
        res = m.invoke(this, (Object[]) null);
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        LOG.error(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        LOG.error(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        LOG.error(e.getMessage(), e);
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        LOG.error(e.getMessage(), e);
    }
    return res;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project controller by opendaylight.

the class AbstractDynamicWrapper method getAttributes.

@Override
public AttributeList getAttributes(final String[] attributes) {
    AttributeList result = new AttributeList();
    for (String attributeName : attributes) {
        Object value;
        try {
            value = getAttribute(attributeName);
            result.add(new Attribute(attributeName, value));
        } catch (AttributeNotFoundException | MBeanException | ReflectionException e) {
            LOG.debug("Getting attribute {} failed", attributeName, e);
        }
    }
    return result;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException)

Example 23 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project controller by opendaylight.

the class DynamicWritableWrapper method setAttributes.

@Override
public AttributeList setAttributes(final AttributeList attributes) {
    AttributeList result = new AttributeList();
    for (Object attributeObject : attributes) {
        Attribute attribute = (Attribute) attributeObject;
        try {
            setAttribute(attribute);
            result.add(attribute);
        } catch (final InvalidAttributeValueException | AttributeNotFoundException | MBeanException | ReflectionException e) {
            LOG.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e);
            throw new IllegalArgumentException("Setting attribute failed - " + attribute.getName() + " on " + moduleIdentifier, e);
        }
    }
    return result;
}
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 24 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project controller by opendaylight.

the class TestingParallelAPSPModule method validate.

@Override
public void validate() {
    checkNotNull(threadPoolON, "Parameter 'threadPool' must be set");
    dependencyResolver.validateDependency(TestingThreadPoolServiceInterface.class, threadPoolON, threadPoolOnJMXAttribute);
    checkState(Strings.isNullOrEmpty(someParam) == false, "Parameter 'SomeParam' is blank");
    // check that calling resolveInstance fails
    try {
        dependencyResolver.resolveInstance(TestingThreadPoolIfc.class, threadPoolON, threadPoolOnJMXAttribute);
        throw new RuntimeException("fail");
    } catch (final IllegalStateException e) {
        checkState("Commit was not triggered".equals(e.getMessage()), e.getMessage());
    }
    // test retrieving dependent module's attribute
    int threadCount;
    try {
        threadCount = (Integer) dependencyResolver.getAttribute(threadPoolON, "ThreadCount");
    } catch (final ReflectionException | InstanceNotFoundException | AttributeNotFoundException | MBeanException e) {
        throw new IllegalStateException(e);
    }
    checkState(threadCount > 0);
    TestingThreadPoolConfigMXBean proxy = dependencyResolver.newMXBeanProxy(threadPoolON, TestingThreadPoolConfigMXBean.class);
    checkState(threadCount == proxy.getThreadCount());
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) TestingThreadPoolConfigMXBean(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolConfigMXBean) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 25 with AttributeNotFoundException

use of javax.management.AttributeNotFoundException in project openj9 by eclipse.

the class TestMemoryPoolMXBean method testBadSetAttribute.

@Test
public final void testBadSetAttribute() {
    MemoryPoolMXBean testImpl = testBean;
    // Let's try and set some non-writable attributes.
    Attribute attr = new Attribute("UsageThresholdCount", new Long(25));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (Exception e) {
        logger.debug("testBadSetAttribute exception:" + e.getClass().getName() + ", errMessage=" + e.getMessage());
        AssertJUnit.assertTrue(e instanceof AttributeNotFoundException);
    }
    // Try and set the UsageThreshold attribute with an incorrect
    // type.
    attr = new Attribute("UsageThreshold", "rubbish");
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception");
    } catch (Exception e) {
        AssertJUnit.assertTrue(e instanceof InvalidAttributeValueException);
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)78 ReflectionException (javax.management.ReflectionException)57 MBeanException (javax.management.MBeanException)53 InstanceNotFoundException (javax.management.InstanceNotFoundException)40 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)31 Attribute (javax.management.Attribute)25 ObjectName (javax.management.ObjectName)24 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)13 Method (java.lang.reflect.Method)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 AttributeList (javax.management.AttributeList)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Test (org.testng.annotations.Test)9 MBeanInfo (javax.management.MBeanInfo)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 RuntimeMBeanException (javax.management.RuntimeMBeanException)7 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)7