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;
}
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;
}
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;
}
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());
}
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);
}
}
Aggregations