use of javax.management.MBeanException in project jetty.project by eclipse.
the class ObjectMBean method setAttribute.
/* ------------------------------------------------------------ */
public void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
if (attr == null)
return;
if (LOG.isDebugEnabled())
LOG.debug("setAttribute " + _managed + ":" + attr.getName() + "=" + attr.getValue());
Method setter = (Method) _setters.get(attr.getName());
if (setter == null)
throw new AttributeNotFoundException(attr.getName());
try {
Object o = _managed;
if (setter.getDeclaringClass().isInstance(this))
o = this;
// get the value
Object value = attr.getValue();
// convert from ObjectName if need be
if (value != null && _convert.contains(attr.getName())) {
if (value.getClass().isArray()) {
Class<?> t = setter.getParameterTypes()[0].getComponentType();
Object na = Array.newInstance(t, Array.getLength(value));
for (int i = Array.getLength(value); i-- > 0; ) Array.set(na, i, _mbeanContainer.findBean((ObjectName) Array.get(value, i)));
value = na;
} else
value = _mbeanContainer.findBean((ObjectName) value);
}
// do the setting
setter.invoke(o, new Object[] { value });
} catch (IllegalAccessException e) {
LOG.warn(Log.EXCEPTION, e);
throw new AttributeNotFoundException(e.toString());
} catch (InvocationTargetException e) {
LOG.warn(Log.EXCEPTION, e);
throw new ReflectionException(new Exception(e.getCause()));
}
}
use of javax.management.MBeanException in project tomcat by apache.
the class BaseModelMBean method invoke.
/**
* Invoke a particular method on this MBean, and return any returned
* value.
*
* <p><strong>IMPLEMENTATION NOTE</strong> - This implementation will
* attempt to invoke this method on the MBean itself, or (if not
* available) on the managed resource object associated with this
* MBean.</p>
*
* @param name Name of the operation to be invoked
* @param params Array containing the method parameters of this operation
* @param signature Array containing the class names representing
* the signature of this operation
*
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking a method
*/
@Override
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException {
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).invoke(name, params, signature);
}
// Validate the input parameters
if (name == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Method name is null"), "Method name is null");
if (log.isDebugEnabled())
log.debug("Invoke " + name);
Method method = managedBean.getInvoke(name, params, signature, this, resource);
// Invoke the selected method on the appropriate object
Object result = null;
try {
if (method.getDeclaringClass().isAssignableFrom(this.getClass())) {
result = method.invoke(this, params);
} else {
result = method.invoke(resource, params);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
log.error("Exception invoking method " + name, t);
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((Exception) t, "Exception invoking method " + name);
} catch (Exception e) {
log.error("Exception invoking method " + name, e);
throw new MBeanException(e, "Exception invoking method " + name);
}
// FIXME - should we validate the return type?
return (result);
}
use of javax.management.MBeanException in project tomcat by apache.
the class ManagedBean method getInvoke.
public Method getInvoke(String aname, Object[] params, String[] signature, BaseModelMBean bean, Object resource) throws MBeanException, ReflectionException {
Method method = null;
if (params == null)
params = new Object[0];
if (signature == null)
signature = new String[0];
if (params.length != signature.length)
throw new RuntimeOperationsException(new IllegalArgumentException("Inconsistent arguments and signature"), "Inconsistent arguments and signature");
// Acquire the ModelMBeanOperationInfo information for
// the requested operation
OperationInfo opInfo = operations.get(createOperationKey(aname, signature));
if (opInfo == null)
throw new MBeanException(new ServiceNotFoundException("Cannot find operation " + aname), "Cannot find operation " + aname);
// Prepare the signature required by Java reflection APIs
// FIXME - should we use the signature from opInfo?
Class<?>[] types = new Class[signature.length];
for (int i = 0; i < signature.length; i++) {
types[i] = BaseModelMBean.getAttributeClass(signature[i]);
}
// Locate the method to be invoked, either in this MBean itself
// or in the corresponding managed resource
// FIXME - Accessible methods in superinterfaces?
Object object = null;
Exception exception = null;
try {
object = bean;
method = object.getClass().getMethod(aname, types);
} catch (NoSuchMethodException e) {
exception = e;
}
try {
if ((method == null) && (resource != null)) {
object = resource;
method = object.getClass().getMethod(aname, types);
}
} catch (NoSuchMethodException e) {
exception = e;
}
if (method == null) {
throw new ReflectionException(exception, "Cannot find method " + aname + " with this signature");
}
return method;
}
use of javax.management.MBeanException in project tomcat by apache.
the class BaseModelMBean method getAttribute.
// key: operation val: invoke method
//private Hashtable invokeAttMap=new Hashtable();
/**
* 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("Attribute name is null"), "Attribute name is null");
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).getAttribute(name);
}
Method m = managedBean.getGetter(name, this, resource);
Object result = null;
try {
Class<?> declaring = m.getDeclaringClass();
// but this is the catalina class.
if (declaring.isAssignableFrom(this.getClass())) {
result = m.invoke(this, NO_ARGS_PARAM);
} else {
result = m.invoke(resource, NO_ARGS_PARAM);
}
} 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) {
throw new MBeanException(e, "Exception invoking method " + name);
}
// FIXME - should we validate the return type?
return (result);
}
use of javax.management.MBeanException in project tomcat by apache.
the class ContainerMBean method removeValve.
/**
* Remove an existing Valve.
*
* @param valveName MBean Name of the Valve to remove
*
* @exception MBeanException if a component cannot be removed
*/
public void removeValve(String valveName) throws MBeanException {
Container container = doGetManagedResource();
ObjectName oname;
try {
oname = new ObjectName(valveName);
} catch (MalformedObjectNameException e) {
throw new MBeanException(e);
} catch (NullPointerException e) {
throw new MBeanException(e);
}
if (container != null) {
Valve[] valves = container.getPipeline().getValves();
for (int i = 0; i < valves.length; i++) {
if (valves[i] instanceof JmxEnabled) {
ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
if (voname.equals(oname)) {
container.getPipeline().removeValve(valves[i]);
}
}
}
}
}
Aggregations