Search in sources :

Example 21 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class ManagementFactoryHelper method getPlatformDynamicMBeans.

public static HashMap<ObjectName, DynamicMBean> getPlatformDynamicMBeans() {
    HashMap<ObjectName, DynamicMBean> map = new HashMap<>();
    DiagnosticCommandMBean diagMBean = getDiagnosticCommandMBean();
    if (diagMBean != null) {
        map.put(Util.newObjectName(HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME), diagMBean);
    }
    return map;
}
Also used : DynamicMBean(javax.management.DynamicMBean) HashMap(java.util.HashMap) DiagnosticCommandMBean(com.sun.management.DiagnosticCommandMBean) ObjectName(javax.management.ObjectName)

Example 22 with DynamicMBean

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

the class Registry method registerComponent.

/**
     * Register a component
     *
     * @param bean The bean
     * @param oname The object name
     * @param type The registry type
     * @throws Exception Error registering component
     */
public void registerComponent(Object bean, ObjectName oname, String type) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Managed= " + oname);
    }
    if (bean == null) {
        log.error("Null component " + oname);
        return;
    }
    try {
        if (type == null) {
            type = bean.getClass().getName();
        }
        ManagedBean managed = findManagedBean(null, bean.getClass(), type);
        // The real mbean is created and registered
        DynamicMBean mbean = managed.createMBean(bean);
        if (getMBeanServer().isRegistered(oname)) {
            if (log.isDebugEnabled()) {
                log.debug("Unregistering existing component " + oname);
            }
            getMBeanServer().unregisterMBean(oname);
        }
        getMBeanServer().registerMBean(mbean, oname);
    } catch (Exception ex) {
        log.error("Error registering " + oname, ex);
        throw ex;
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 23 with DynamicMBean

use of javax.management.DynamicMBean 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 24 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("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 25 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("ManagedBean is not found with " + 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)37 MBeanException (javax.management.MBeanException)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)13 ObjectName (javax.management.ObjectName)10 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 InstanceNotFoundException (javax.management.InstanceNotFoundException)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)8 MalformedObjectNameException (javax.management.MalformedObjectNameException)8 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)7 NamedObject (com.sun.jmx.mbeanserver.NamedObject)6 ReflectionException (javax.management.ReflectionException)6 JMRuntimeException (javax.management.JMRuntimeException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)4 NotificationListener (javax.management.NotificationListener)4 RuntimeMBeanException (javax.management.RuntimeMBeanException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3