Search in sources :

Example 6 with DynamicMBean

use of javax.management.DynamicMBean 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("Attribute is null"), "Attribute is null");
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    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, "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) {
        log.error("Exception invoking method " + name, e);
        throw new MBeanException(e, "Exception invoking method " + name);
    }
    try {
        sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
    } catch (Exception ex) {
        log.error("Error sending notification " + 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);
//        }
}
Also used : DynamicMBean(javax.management.DynamicMBean) RuntimeErrorException(javax.management.RuntimeErrorException) Attribute(javax.management.Attribute) Method(java.lang.reflect.Method) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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 7 with DynamicMBean

use of javax.management.DynamicMBean in project spring-framework by spring-projects.

the class JmxUtilsTests method testIsMBeanWithDynamicMBean.

@Test
public void testIsMBeanWithDynamicMBean() throws Exception {
    DynamicMBean mbean = new TestDynamicMBean();
    assertTrue("Dynamic MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
}
Also used : DynamicMBean(javax.management.DynamicMBean) TestDynamicMBean(org.springframework.jmx.export.TestDynamicMBean) TestDynamicMBean(org.springframework.jmx.export.TestDynamicMBean) Test(org.junit.Test)

Example 8 with DynamicMBean

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

the class MBeanHolder method create.

static <T> MBeanHolder create(final T mbean, final ObjectName requestedObjectName) {
    if (mbean instanceof DynamicMBean) {
        return new MBeanHolder(mbean, requestedObjectName);
    } else if (mbean == null) {
        return null;
    }
    Class<?> mbeanClass = mbean.getClass();
    // This is all in aid of getting new StandardMBean to work.
    @SuppressWarnings("unchecked") Class<T> mbeanInterface = (Class<T>) getMBeanInterface(mbeanClass);
    if (mbeanInterface == null) {
        return null;
    }
    if (mbeanInterface.getName().equals(mbeanClass.getName().concat("MBean")) || mbeanInterface.getName().equals(mbeanClass.getName().concat("MXBean"))) {
        return new MBeanHolder(mbean, requestedObjectName);
    }
    try {
        StandardMBean stdMbean = new RegistrableStandardEmitterMBean(mbean, mbeanInterface);
        return new MBeanHolder(stdMbean, requestedObjectName);
    } catch (NotCompliantMBeanException e) {
        LoggerFactory.getLogger(MBeanHolder.class).error("create: Cannot create StandardMBean for " + mbean + " of type " + mbeanClass + " for interface " + mbeanInterface, e);
        return null;
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RegistrableStandardEmitterMBean(org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean)

Example 9 with DynamicMBean

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

the class IgniteUtils method registerMBean.

/**
     * Registers MBean with the server.
     *
     * @param <T> Type of mbean.
     * @param mbeanSrv MBean server.
     * @param igniteInstanceName Ignite instance name.
     * @param grp Name of the group.
     * @param name Name of mbean.
     * @param impl MBean implementation.
     * @param itf MBean interface.
     * @return JMX object name.
     * @throws JMException If MBean creation failed.
     */
public static <T> ObjectName registerMBean(MBeanServer mbeanSrv, @Nullable String igniteInstanceName, @Nullable String grp, String name, T impl, @Nullable Class<T> itf) throws JMException {
    assert mbeanSrv != null;
    assert name != null;
    assert itf != null;
    DynamicMBean mbean = new IgniteStandardMXBean(impl, itf);
    mbean.getMBeanInfo();
    return mbeanSrv.registerMBean(mbean, makeMBeanName(igniteInstanceName, grp, name)).getObjectName();
}
Also used : DynamicMBean(javax.management.DynamicMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean)

Example 10 with DynamicMBean

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

the class IgniteUtils method registerCacheMBean.

/**
     * Registers MBean with the server.
     *
     * @param <T> Type of mbean.
     * @param mbeanSrv MBean server.
     * @param igniteInstanceName Ignite instance name.
     * @param cacheName Name of the cache.
     * @param name Name of mbean.
     * @param impl MBean implementation.
     * @param itf MBean interface.
     * @return JMX object name.
     * @throws JMException If MBean creation failed.
     */
public static <T> ObjectName registerCacheMBean(MBeanServer mbeanSrv, @Nullable String igniteInstanceName, @Nullable String cacheName, String name, T impl, Class<T> itf) throws JMException {
    assert mbeanSrv != null;
    assert name != null;
    assert itf != null;
    DynamicMBean mbean = new IgniteStandardMXBean(impl, itf);
    mbean.getMBeanInfo();
    return mbeanSrv.registerMBean(mbean, makeCacheMBeanName(igniteInstanceName, cacheName, name)).getObjectName();
}
Also used : DynamicMBean(javax.management.DynamicMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean)

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