Search in sources :

Example 61 with MBeanException

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()));
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException)

Example 62 with MBeanException

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);
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 63 with MBeanException

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;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ReflectionException(javax.management.ReflectionException) Method(java.lang.reflect.Method) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 64 with MBeanException

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);
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 65 with MBeanException

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]);
                }
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Aggregations

MBeanException (javax.management.MBeanException)105 ReflectionException (javax.management.ReflectionException)50 InstanceNotFoundException (javax.management.InstanceNotFoundException)41 AttributeNotFoundException (javax.management.AttributeNotFoundException)35 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)26 MalformedObjectNameException (javax.management.MalformedObjectNameException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ServiceNotFoundException (javax.management.ServiceNotFoundException)17 Attribute (javax.management.Attribute)14 RuntimeErrorException (javax.management.RuntimeErrorException)14 Method (java.lang.reflect.Method)10 DynamicMBean (javax.management.DynamicMBean)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)10 Descriptor (javax.management.Descriptor)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 MalformedURLException (java.net.MalformedURLException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7