Search in sources :

Example 1 with InvalidTargetObjectTypeException

use of javax.management.modelmbean.InvalidTargetObjectTypeException in project camel by apache.

the class DefaultManagementMBeanAssembler method assemble.

public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;
    ModelMBeanInfo standardMbi = null;
    Object custom = null;
    // prefer to use the managed instance if it has been annotated with JMX annotations
    if (obj instanceof ManagedInstance) {
        // there may be a custom embedded instance which have additional methods
        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 into different groups (mbi = both, standard = standard out of the box mbi)
            mbi = assembler.getMBeanInfo(obj, custom, name.toString());
            standardMbi = assembler.getMBeanInfo(obj, null, name.toString());
        }
    }
    if (mbi == null) {
        // use the default provided mbean which has been annotated with JMX annotations
        LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
        mbi = assembler.getMBeanInfo(obj, null, name.toString());
    }
    if (mbi == null) {
        return null;
    }
    RequiredModelMBean mbean;
    RequiredModelMBean mixinMBean = null;
    boolean sanitize = camelContext.getManagementStrategy().getManagementAgent().getMask() != null && camelContext.getManagementStrategy().getManagementAgent().getMask();
    // as we want a combined mbean that has both the custom and the standard
    if (standardMbi != null) {
        mixinMBean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
        mixinMBean.setModelMBeanInfo(standardMbi);
        try {
            mixinMBean.setManagedResource(obj, "ObjectReference");
        } catch (InvalidTargetObjectTypeException e) {
            throw new JMException(e.getMessage());
        }
        // use custom as the object to call
        obj = custom;
    }
    // use a mixin mbean model to combine the custom and standard (custom is optional)
    mbean = new MixinRequiredModelMBean(mbi, sanitize, standardMbi, mixinMBean);
    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) ManagedResource(org.apache.camel.api.management.ManagedResource) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Example 2 with InvalidTargetObjectTypeException

use of javax.management.modelmbean.InvalidTargetObjectTypeException 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)

Example 3 with InvalidTargetObjectTypeException

use of javax.management.modelmbean.InvalidTargetObjectTypeException in project geode by apache.

the class MX4JModelMBean method setManagedResource.

public void setManagedResource(Object resource, String resourceType) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException {
    if (resource == null)
        throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_MANAGED_RESOURCE_CANNOT_BE_NULL.toLocalizedString()));
    if (!isResourceTypeSupported(resourceType))
        throw new InvalidTargetObjectTypeException(resourceType);
    Logger logger = getLogger();
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Setting managed resource to be: " + resource);
    m_managedResource = resource;
}
Also used : InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 4 with InvalidTargetObjectTypeException

use of javax.management.modelmbean.InvalidTargetObjectTypeException in project geode by apache.

the class MX4JModelMBean method resolveTargetObject.

private Object resolveTargetObject(Descriptor descriptor) throws MBeanException {
    Logger logger = getLogger();
    Object target = descriptor.getFieldValue("targetObject");
    if (logger.isEnabledFor(Logger.TRACE))
        logger.trace("targetObject is: " + target);
    if (target == null) {
        target = getManagedResource();
    } else {
        String targetObjectType = (String) descriptor.getFieldValue("targetObjectType");
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("targetObjectType is: " + targetObjectType);
        if (targetObjectType == null) {
            // Not defined, assume object reference
            targetObjectType = OBJECT_RESOURCE_TYPE;
        }
        if (!isResourceTypeSupported(targetObjectType))
            throw new MBeanException(new InvalidTargetObjectTypeException(targetObjectType));
    }
    return target;
}
Also used : MBeanException(javax.management.MBeanException) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException)

Example 5 with InvalidTargetObjectTypeException

use of javax.management.modelmbean.InvalidTargetObjectTypeException in project voldemort by voldemort.

the class JmxUtils method createModelMBean.

/**
     * Create a model mbean from an object using the description given in the
     * Jmx annotation if present. Only operations are supported so far, no
     * attributes, constructors, or notifications
     * 
     * @param o The object to create an MBean for
     * @return The ModelMBean for the given object
     */
public static ModelMBean createModelMBean(Object o) {
    try {
        ModelMBean mbean = new RequiredModelMBean();
        JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
        String description = annotation == null ? "" : annotation.description();
        ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]);
        mbean.setModelMBeanInfo(info);
        mbean.setManagedResource(o, "ObjectReference");
        return mbean;
    } catch (MBeanException e) {
        throw new VoldemortException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new VoldemortException(e);
    } catch (InstanceNotFoundException e) {
        throw new VoldemortException(e);
    }
}
Also used : RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ModelMBean(javax.management.modelmbean.ModelMBean) JmxManaged(voldemort.annotations.jmx.JmxManaged) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) VoldemortException(voldemort.VoldemortException) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Aggregations

InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)6 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)4 JMException (javax.management.JMException)3 MBeanException (javax.management.MBeanException)2 FileLogger (mx4j.log.FileLogger)2 Logger (mx4j.log.Logger)2 MBeanLogger (mx4j.log.MBeanLogger)2 ManagedInstance (org.apache.camel.api.management.ManagedInstance)2 NotificationSenderAware (org.apache.camel.api.management.NotificationSenderAware)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 RuntimeOperationsException (javax.management.RuntimeOperationsException)1 ModelMBean (javax.management.modelmbean.ModelMBean)1 ModelMBeanInfoSupport (javax.management.modelmbean.ModelMBeanInfoSupport)1 NotificationSenderAware (org.activiti.management.jmx.annotations.NotificationSenderAware)1 ManagedResource (org.apache.camel.api.management.ManagedResource)1 NotificationSenderAdapter (org.apache.camel.management.NotificationSenderAdapter)1 ManagedResource (org.springframework.jmx.export.annotation.ManagedResource)1 VoldemortException (voldemort.VoldemortException)1 JmxManaged (voldemort.annotations.jmx.JmxManaged)1