use of javax.management.AttributeNotFoundException in project tomcat by apache.
the class ManagedBean method getGetter.
Method getGetter(String aname, BaseModelMBean mbean, Object resource) throws AttributeNotFoundException, ReflectionException {
Method m = null;
AttributeInfo attrInfo = attributes.get(aname);
// Look up the actual operation to be used
if (attrInfo == null) {
throw new AttributeNotFoundException(sm.getString("managedMBean.noAttribute", aname, resource));
}
String getMethod = attrInfo.getGetMethod();
Object object = null;
NoSuchMethodException exception = null;
try {
object = mbean;
m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
} catch (NoSuchMethodException e) {
exception = e;
}
if (m == null && resource != null) {
try {
object = resource;
m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
exception = null;
} catch (NoSuchMethodException e) {
exception = e;
}
}
if (exception != null) {
throw new ReflectionException(exception, sm.getString("managedMBean.noGet", getMethod, resource));
}
return m;
}
use of javax.management.AttributeNotFoundException in project tomcat 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(sm.getString("baseModelMBean.nullAttribute")), sm.getString("baseModelMBean.nullAttribute"));
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("baseModelMBean.nullAttributeName")), sm.getString("baseModelMBean.nullAttributeName"));
}
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, sm.getString("baseModelMBean.invokeError", name));
} else if (t instanceof Error) {
throw new RuntimeErrorException((Error) t, sm.getString("baseModelMBean.invokeError", name));
} else {
throw new MBeanException(e, sm.getString("baseModelMBean.invokeError", name));
}
} catch (Exception e) {
log.error(sm.getString("baseModelMBean.invokeError", name), e);
throw new MBeanException(e, sm.getString("baseModelMBean.invokeError", name));
}
try {
sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
} catch (Exception ex) {
log.error(sm.getString("baseModelMBean.notificationError", 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);
// }
}
use of javax.management.AttributeNotFoundException in project tomcat by apache.
the class ContextResourceMBean method getAttribute.
/**
* Obtain and return the value of a specific attribute of this MBean.
*
* @param name Name of the requested attribute
*
* @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 Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
// Validate the input parameters
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("mBean.nullName")), sm.getString("mBean.nullName"));
}
ContextResource cr = doGetManagedResource();
String value = null;
if ("auth".equals(name)) {
return cr.getAuth();
} else if ("description".equals(name)) {
return cr.getDescription();
} else if ("name".equals(name)) {
return cr.getName();
} else if ("scope".equals(name)) {
return cr.getScope();
} else if ("type".equals(name)) {
return cr.getType();
} else {
value = (String) cr.getProperty(name);
if (value == null) {
throw new AttributeNotFoundException(sm.getString("mBean.attributeNotFound", name));
}
}
return value;
}
use of javax.management.AttributeNotFoundException in project jmxtrans by jmxtrans.
the class TreeWalker3 method walkTree.
public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
// key here is null, null returns everything!
Set<ObjectName> mbeans = connection.queryNames(null, null);
Map<String, String> output = newHashMap();
for (ObjectName name : mbeans) {
MBeanInfo info = connection.getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName());
ResultCapture resultCapture = new ResultCapture();
queryBuilder.addOutputWriterFactory(resultCapture);
for (MBeanAttributeInfo attrInfo : attrs) {
queryBuilder.addAttr(attrInfo.getName());
}
Query query = queryBuilder.build();
try {
Iterable<Result> results = server.execute(query);
query.runOutputWritersForQuery(server, results);
} catch (AttributeNotFoundException anfe) {
log.error("Error", anfe);
}
for (Result result : resultCapture.results) {
output.put(result.getTypeName(), query.getAttr().toString());
}
}
for (Entry<String, String> entry : output.entrySet()) {
log.debug(entry.getKey());
log.debug(entry.getValue());
log.debug("-----------------------------------------");
}
}
use of javax.management.AttributeNotFoundException in project Payara by payara.
the class AbstractDynamicMBeanImpl method getAttributes.
public final AttributeList getAttributes(String[] attributes) {
AttributeList r = new AttributeList(attributes.length);
for (String name : attributes) {
Object value = null;
try {
value = getAttribute(name);
} catch (AttributeNotFoundException e) {
// error is reported as the lack of value
} catch (MBeanException e) {
// error is reported as the lack of value
} catch (ReflectionException e) {
// error is reported as the lack of value
}
r.add(new Attribute(name, value));
}
return r;
}
Aggregations