use of javax.management.InvalidAttributeValueException in project jspwiki by apache.
the class SimpleMBean method setAttributes.
public AttributeList setAttributes(AttributeList arg0) {
AttributeList result = new AttributeList();
for (Iterator<Object> i = arg0.iterator(); i.hasNext(); ) {
Attribute attr = (Attribute) i.next();
//
try {
setAttribute(attr);
result.add(attr);
} catch (AttributeNotFoundException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
} catch (InvalidAttributeValueException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
} catch (MBeanException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
} catch (ReflectionException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
}
}
return result;
}
use of javax.management.InvalidAttributeValueException 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.InvalidAttributeValueException 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);
}
}
use of javax.management.InvalidAttributeValueException in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testSetUsageThresholdAttribute.
@Test
public void testSetUsageThresholdAttribute() {
MemoryPoolMXBean testImpl = testBean;
if (testImpl.isUsageThresholdSupported()) {
try {
long originalUT = (Long) mbs.getAttribute(objName, "UsageThreshold");
long newUT = originalUT + 1024;
Attribute newUTAttr = new Attribute("UsageThreshold", new Long(newUT));
mbs.setAttribute(objName, newUTAttr);
AssertJUnit.assertEquals(new Long(newUT), (Long) mbs.getAttribute(objName, "UsageThreshold"));
} catch (AttributeNotFoundException e) {
e.printStackTrace();
Assert.fail("Unexpected AttributeNotFoundException occurred: " + e.getMessage());
} catch (InstanceNotFoundException e) {
e.printStackTrace();
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (MBeanException e) {
e.printStackTrace();
Assert.fail("Unexpected MBeanException occurred: " + e.getMessage());
} catch (ReflectionException e) {
e.printStackTrace();
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (InvalidAttributeValueException e) {
e.printStackTrace();
Assert.fail("Unexpected InvalidAttributeValueException occurred: " + e.getMessage());
}
} else {
try {
Attribute newUTAttr = new Attribute("UsageThreshold", new Long(100 * 1024));
mbs.setAttribute(objName, newUTAttr);
Assert.fail("Unreacheable code: should have thrown exception!");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred, as expected: cannot set attribute (UsageThreshold).");
}
}
// end else usage threshold is not supported
}
use of javax.management.InvalidAttributeValueException in project tomcat70 by apache.
the class BaseModelMBean method setAttribute.
/**
* Set the value of a specific attribute of this MBean.
*
* @param attribute The identification of the attribute to be set
* and the new value
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
if (log.isDebugEnabled())
log.debug("Setting attribute " + this + " " + attribute);
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
try {
((DynamicMBean) resource).setAttribute(attribute);
} catch (InvalidAttributeValueException e) {
throw new MBeanException(e);
}
return;
}
// Validate the input parameters
if (attribute == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
Object oldValue = null;
// if( getAttMap.get(name) != null )
// oldValue=getAttribute( name );
Method m = managedBean.getSetter(name, this, resource);
try {
if (m.getDeclaringClass().isAssignableFrom(this.getClass())) {
m.invoke(this, new Object[] { value });
} else {
m.invoke(resource, new Object[] { value });
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
else
throw new MBeanException(e, "Exception invoking method " + name);
} catch (Exception e) {
log.error("Exception invoking method " + name, e);
throw new MBeanException(e, "Exception invoking method " + name);
}
try {
sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
} catch (Exception ex) {
log.error("Error sending notification " + name, ex);
}
// attributes.put( name, value );
// if( source != null ) {
// // this mbean is associated with a source - maybe we want to persist
// source.updateField(oname, name, value);
// }
}
Aggregations