Search in sources :

Example 1 with NotificationSenderAdapter

use of org.apache.camel.management.NotificationSenderAdapter in project camel by apache.

the class SpringManagementMBeanAssembler method assemble.

public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;
    // prefer to use the managed instance if it has been annotated with Spring JMX annotations
    if (obj instanceof ManagedInstance) {
        Object custom = ((ManagedInstance) obj).getInstance();
        if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
            LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom);
            // get the mbean info from the custom managed object
            mbi = springAssembler.getMBeanInfo(custom, name.toString());
            // and let the custom object be registered in JMX
            obj = custom;
        }
    }
    if (mbi == null) {
        if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class)) {
            // the object has a Spring ManagedResource annotations so assemble the MBeanInfo
            LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
            mbi = springAssembler.getMBeanInfo(obj, name.toString());
        } else {
            // fallback and let the default mbean assembler handle this instead
            return super.assemble(mBeanServer, obj, name);
        }
    }
    LOG.trace("Assembled MBeanInfo {}", mbi);
    RequiredModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
    mbean.setModelMBeanInfo(mbi);
    try {
        mbean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException e) {
        throw new JMException(e.getMessage());
    }
    // Allows the managed object to send notifications
    if (obj instanceof NotificationSenderAware) {
        ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
    }
    return mbean;
}
Also used : JMException(javax.management.JMException) NotificationSenderAware(org.apache.camel.api.management.NotificationSenderAware) ManagedInstance(org.apache.camel.api.management.ManagedInstance) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) NotificationSenderAdapter(org.apache.camel.management.NotificationSenderAdapter) ManagedResource(org.springframework.jmx.export.annotation.ManagedResource) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Aggregations

JMException (javax.management.JMException)1 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)1 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)1 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)1 ManagedInstance (org.apache.camel.api.management.ManagedInstance)1 NotificationSenderAware (org.apache.camel.api.management.NotificationSenderAware)1 NotificationSenderAdapter (org.apache.camel.management.NotificationSenderAdapter)1 ManagedResource (org.springframework.jmx.export.annotation.ManagedResource)1