use of javax.management.InvalidAttributeValueException in project felix by apache.
the class AbstractDynamicMBean method setAttributes.
/**
* Sets the manageable attributes, as specified by the DynamicMBean interface.
*/
public AttributeList setAttributes(AttributeList attributes) {
AttributeList list = new AttributeList();
if (attributes != null) {
for (int i = 0; i < attributes.size(); ++i) {
Attribute attribute = (Attribute) attributes.get(i);
try {
setAttribute(attribute);
list.add(attribute);
} catch (AttributeNotFoundException ignored) {
} catch (InvalidAttributeValueException ignored) {
} catch (MBeanException ignored) {
} catch (ReflectionException ignored) {
}
}
}
return list;
}
use of javax.management.InvalidAttributeValueException in project felix by apache.
the class AbstractDynamicMBean method invoke.
/**
* Looks up the method to call on given resource and invokes it.
* The default implementation requires that the methods that implement attribute and operation behavior
* on the resource object are public, but it is possible to override this behavior, and call
* also private methods.
* @see #findMethod
* @see #invokeMethod
*/
protected Object invoke(Object resource, String name, Class[] params, Object[] args) throws InvalidAttributeValueException, MBeanException, ReflectionException {
try {
Class cls = resource.getClass();
Method method = findMethod(cls, name, params);
return invokeMethod(method, resource, args);
} catch (NoSuchMethodException x) {
throw new ReflectionException(x);
} catch (IllegalAccessException x) {
throw new ReflectionException(x);
} catch (IllegalArgumentException x) {
throw new InvalidAttributeValueException(x.toString());
} catch (InvocationTargetException x) {
Throwable t = x.getTargetException();
if (t instanceof RuntimeException)
throw new RuntimeMBeanException((RuntimeException) t);
else if (t instanceof Exception)
throw new MBeanException((Exception) t);
throw new RuntimeErrorException((Error) t);
}
}
use of javax.management.InvalidAttributeValueException in project felix by apache.
the class AbstractDynamicMBean method getAttribute.
/**
* Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
* @see #createMBeanAttributeInfo
*/
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
if (attribute == null)
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
Object resource = null;
MBeanInfo info = null;
synchronized (this) {
resource = getResourceOrThis();
info = getMBeanInfo();
}
MBeanAttributeInfo[] attrs = info.getAttributes();
if (attrs == null || attrs.length == 0)
throw new AttributeNotFoundException("No attributes defined for this MBean");
for (int i = 0; i < attrs.length; ++i) {
MBeanAttributeInfo attr = attrs[i];
if (attr == null)
continue;
if (attribute.equals(attr.getName())) {
if (!attr.isReadable())
throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));
// Found, invoke via reflection
String prefix = null;
if (attr.isIs())
prefix = "is";
else
prefix = "get";
try {
return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
} catch (InvalidAttributeValueException x) {
throw new ReflectionException(x);
}
}
}
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}
use of javax.management.InvalidAttributeValueException in project spf4j by zolyfarkas.
the class ExportedValuesMBean method setAttribute.
/**
* {@inheritDoc}
*/
@Override
public void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException {
String name = attribute.getName();
ExportedValue<Object> result = (ExportedValue<Object>) exportedValues.get(name);
if (result == null) {
throw new AttributeNotFoundException(name);
}
try {
result.set(attribute.getValue());
} catch (InvalidObjectException | RuntimeException ex) {
LOG.warn("Exception while setting attr {}", attribute, ex);
throw new InvalidAttributeValueException("Invalid value " + attribute + " detail:\n" + Throwables.toString(ex));
}
}
use of javax.management.InvalidAttributeValueException in project openj9 by eclipse.
the class AttributeData method testSetAttribute.
@Test
public final void testSetAttribute() {
Attribute attr = null;
try {
// The one writable attribute of ClassLoadingMXBean...
Boolean before = (Boolean) mbs.getAttribute(objName, "Verbose");
// Toggle the boolean state of "isVerbose"
boolean newVal = !before;
attr = new Attribute("Verbose", new Boolean(newVal));
mbs.setAttribute(objName, attr);
Boolean after = (Boolean) mbs.getAttribute(objName, "Verbose");
assert (newVal == after);
} catch (AttributeNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
} catch (InvalidAttributeValueException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InvalidAttributeValueException " + e.getMessage());
} catch (MBeanException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected MBeanException " + e.getCause().getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException " + e.getCause().getMessage());
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
}
// Let's try and set some non-writable attributes.
attr = new Attribute("LoadedClassCount", new Integer(25));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + e1.getMessage());
}
attr = new Attribute("TotalLoadedClassCount", new Long(3300));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + e1.getMessage());
}
attr = new Attribute("UnloadedClassCount", new Long(38));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e1) {
AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
logger.debug("Exception occurred, as expected: " + e1.getMessage());
}
// Try and set the Verbose attribute with an incorrect type.
attr = new Attribute("Verbose", new Long(42));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (Exception e2) {
AssertJUnit.assertTrue(e2 instanceof javax.management.InvalidAttributeValueException);
logger.debug("Exception occurred, as expected: " + e2.getMessage());
}
}
Aggregations