Search in sources :

Example 11 with ModelMBeanOperationInfo

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

the class JmxUtils method extractOperationInfo.

/**
     * Extract all operations and attributes from the given object that have
     * been annotated with the Jmx annotation. Operations are all methods that
     * are marked with the JmxOperation annotation.
     * 
     * @param object The object to process
     * @return An array of operations taken from the object
     */
public static ModelMBeanOperationInfo[] extractOperationInfo(Object object) {
    ArrayList<ModelMBeanOperationInfo> infos = new ArrayList<ModelMBeanOperationInfo>();
    for (Method m : object.getClass().getMethods()) {
        JmxOperation jmxOperation = m.getAnnotation(JmxOperation.class);
        JmxGetter jmxGetter = m.getAnnotation(JmxGetter.class);
        JmxSetter jmxSetter = m.getAnnotation(JmxSetter.class);
        if (jmxOperation != null || jmxGetter != null || jmxSetter != null) {
            String description = "";
            int visibility = 1;
            int impact = MBeanOperationInfo.UNKNOWN;
            if (jmxOperation != null) {
                description = jmxOperation.description();
                impact = jmxOperation.impact();
            } else if (jmxGetter != null) {
                description = jmxGetter.description();
                impact = MBeanOperationInfo.INFO;
                visibility = 4;
            } else if (jmxSetter != null) {
                description = jmxSetter.description();
                impact = MBeanOperationInfo.ACTION;
                visibility = 4;
            }
            ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(), description, extractParameterInfo(m), m.getReturnType().getName(), impact);
            info.getDescriptor().setField("visibility", Integer.toString(visibility));
            infos.add(info);
        }
    }
    return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) JmxOperation(voldemort.annotations.jmx.JmxOperation) JmxGetter(voldemort.annotations.jmx.JmxGetter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) JmxSetter(voldemort.annotations.jmx.JmxSetter)

Example 12 with ModelMBeanOperationInfo

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

the class MBeanInfoAssembler method extractMbeanAttributes.

private void extractMbeanAttributes(Object managedBean, Map<String, ManagedAttributeInfo> attributes, Set<ModelMBeanAttributeInfo> mBeanAttributes, Set<ModelMBeanOperationInfo> mBeanOperations) throws IntrospectionException {
    for (ManagedAttributeInfo info : attributes.values()) {
        ModelMBeanAttributeInfo mbeanAttribute = new ModelMBeanAttributeInfo(info.getKey(), info.getDescription(), info.getGetter(), info.getSetter());
        // add missing attribute descriptors, this is needed to have attributes accessible
        Descriptor desc = mbeanAttribute.getDescriptor();
        desc.setField("mask", info.isMask() ? "true" : "false");
        if (info.getGetter() != null) {
            desc.setField("getMethod", info.getGetter().getName());
            // attribute must also be added as mbean operation
            ModelMBeanOperationInfo mbeanOperation = new ModelMBeanOperationInfo(info.getKey(), info.getGetter());
            Descriptor opDesc = mbeanOperation.getDescriptor();
            opDesc.setField("mask", info.isMask() ? "true" : "false");
            mbeanOperation.setDescriptor(opDesc);
            mBeanOperations.add(mbeanOperation);
        }
        if (info.getSetter() != null) {
            desc.setField("setMethod", info.getSetter().getName());
            // attribute must also be added as mbean operation
            ModelMBeanOperationInfo mbeanOperation = new ModelMBeanOperationInfo(info.getKey(), info.getSetter());
            mBeanOperations.add(mbeanOperation);
        }
        mbeanAttribute.setDescriptor(desc);
        mBeanAttributes.add(mbeanAttribute);
        LOG.trace("Assembled attribute: {}", mbeanAttribute);
    }
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) Descriptor(javax.management.Descriptor)

Example 13 with ModelMBeanOperationInfo

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

the class MBeanInfoAssembler method extractMbeanOperations.

private void extractMbeanOperations(Object managedBean, Set<ManagedOperationInfo> operations, Set<ModelMBeanOperationInfo> mBeanOperations) {
    for (ManagedOperationInfo info : operations) {
        ModelMBeanOperationInfo mbean = new ModelMBeanOperationInfo(info.getDescription(), info.getOperation());
        Descriptor opDesc = mbean.getDescriptor();
        opDesc.setField("mask", info.isMask() ? "true" : "false");
        mbean.setDescriptor(opDesc);
        mBeanOperations.add(mbean);
        LOG.trace("Assembled operation: {}", mbean);
    }
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) Descriptor(javax.management.Descriptor)

Example 14 with ModelMBeanOperationInfo

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

the class AnnotationMetadataAssemblerTests method testOperationOnGetter.

@Test
public void testOperationOnGetter() throws Exception {
    ModelMBeanInfo inf = getMBeanInfoFromAssembler();
    ModelMBeanOperationInfo op = inf.getOperation("getExpensiveToCalculate");
    assertNotNull(op);
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 15 with ModelMBeanOperationInfo

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

the class AbstractJmxAssemblerTests method testAttributeHasCorrespondingOperations.

@Test
public void testAttributeHasCorrespondingOperations() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    ModelMBeanOperationInfo get = info.getOperation("getName");
    assertNotNull("get operation should not be null", get);
    assertEquals("get operation should have visibility of four", get.getDescriptor().getFieldValue("visibility"), new Integer(4));
    assertEquals("get operation should have role \"getter\"", "getter", get.getDescriptor().getFieldValue("role"));
    ModelMBeanOperationInfo set = info.getOperation("setName");
    assertNotNull("set operation should not be null", set);
    assertEquals("set operation should have visibility of four", set.getDescriptor().getFieldValue("visibility"), new Integer(4));
    assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role"));
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Aggregations

ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)18 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)11 Descriptor (javax.management.Descriptor)9 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)9 Test (org.junit.Test)6 ModelMBeanInfoSupport (javax.management.modelmbean.ModelMBeanInfoSupport)5 Method (java.lang.reflect.Method)4 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 ModelMBeanNotificationInfo (javax.management.modelmbean.ModelMBeanNotificationInfo)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 MBeanParameterInfo (javax.management.MBeanParameterInfo)2 MBeanServer (javax.management.MBeanServer)2 ObjectName (javax.management.ObjectName)2 ModelMBean (javax.management.modelmbean.ModelMBean)2 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)2 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Hashtable (java.util.Hashtable)1