Search in sources :

Example 76 with DynamicMBean

use of javax.management.DynamicMBean 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(sm.getString("baseModelMBean.nullAttributeName")), sm.getString("baseModelMBean.nullAttributeName"));
    }
    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, 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) {
        throw new MBeanException(e, sm.getString("baseModelMBean.invokeError", 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 77 with DynamicMBean

use of javax.management.DynamicMBean in project tomcat by apache.

the class MBeanUtils method createMBean.

/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 * @return a new MBean
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment) throws Exception {
    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception(sm.getString("mBeanUtils.noManagedBean", mname));
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null) {
        domain = mserver.getDefaultDomain();
    }
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return mbean;
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 78 with DynamicMBean

use of javax.management.DynamicMBean in project tomcat by apache.

the class MBeanUtils method createMBean.

/**
 * Create, register, and return an MBean for this
 * <code>Group</code> object.
 *
 * @param group The Group to be managed
 * @return a new MBean
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Group group) throws Exception {
    String mname = createManagedName(group);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception(sm.getString("mBeanUtils.noManagedBean", mname));
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null) {
        domain = mserver.getDefaultDomain();
    }
    DynamicMBean mbean = managed.createMBean(group);
    ObjectName oname = createObjectName(domain, group);
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return mbean;
}
Also used : DynamicMBean(javax.management.DynamicMBean) MBeanException(javax.management.MBeanException) ManagedBean(org.apache.tomcat.util.modeler.ManagedBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Aggregations

DynamicMBean (javax.management.DynamicMBean)78 MBeanException (javax.management.MBeanException)29 ObjectName (javax.management.ObjectName)24 MalformedObjectNameException (javax.management.MalformedObjectNameException)20 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)18 RuntimeOperationsException (javax.management.RuntimeOperationsException)16 Test (org.junit.Test)15 AttributeNotFoundException (javax.management.AttributeNotFoundException)14 InstanceNotFoundException (javax.management.InstanceNotFoundException)13 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)13 ListenerNotFoundException (javax.management.ListenerNotFoundException)13 ReflectionException (javax.management.ReflectionException)12 RuntimeErrorException (javax.management.RuntimeErrorException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Attribute (javax.management.Attribute)8 JMRuntimeException (javax.management.JMRuntimeException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7 NamedObject (com.sun.jmx.mbeanserver.NamedObject)6 Method (java.lang.reflect.Method)6 RuntimeMBeanException (javax.management.RuntimeMBeanException)6