Search in sources :

Example 41 with Descriptor

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

the class MBeanIntrospector method getClassMBeanInfo.

/**
     * Return the basic MBeanInfo for resources of the given class and
     * per-interface data.  This MBeanInfo might not be the final MBeanInfo
     * for instances of the class, because if the class is a
     * NotificationBroadcaster then each instance gets to decide what
     * MBeanNotificationInfo[] to put in its own MBeanInfo.
     */
final MBeanInfo getClassMBeanInfo(Class<?> resourceClass, PerInterface<M> perInterface) {
    MBeanInfoMap map = getMBeanInfoMap();
    synchronized (map) {
        WeakHashMap<Class<?>, MBeanInfo> intfMap = map.get(resourceClass);
        if (intfMap == null) {
            intfMap = new WeakHashMap<Class<?>, MBeanInfo>();
            map.put(resourceClass, intfMap);
        }
        Class<?> intfClass = perInterface.getMBeanInterface();
        MBeanInfo mbi = intfMap.get(intfClass);
        if (mbi == null) {
            MBeanInfo imbi = perInterface.getMBeanInfo();
            Descriptor descriptor = ImmutableDescriptor.union(imbi.getDescriptor(), getMBeanDescriptor(resourceClass));
            mbi = new MBeanInfo(resourceClass.getName(), imbi.getDescription(), imbi.getAttributes(), findConstructors(resourceClass), imbi.getOperations(), (MBeanNotificationInfo[]) null, descriptor);
            intfMap.put(intfClass, mbi);
        }
        return mbi;
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor)

Example 42 with Descriptor

use of javax.management.Descriptor in project tomee by apache.

the class DynamicMBeanWrapper method parameters.

static MBeanParameterInfo[] parameters(final MBeanOperationInfo jvmInfo, final Class<?>[] classes, final Annotation[][] annots) {
    final MBeanParameterInfo[] params = new MBeanParameterInfo[classes.length];
    assert classes.length == annots.length;
    String desc = "";
    for (int i = 0; i < classes.length; i++) {
        final Descriptor d = jvmInfo.getSignature()[i].getDescriptor();
        final String pn = "arg" + i;
        for (final Annotation a : annots[i]) {
            final Class<? extends Annotation> type = a.annotationType();
            if (type.equals(Description.class) || type.equals(OPENEJB_API_TO_JAVAX.get(Description.class))) {
                desc = getDescription(annotationProxy(a, Description.class), desc);
                break;
            }
        }
        params[i] = new MBeanParameterInfo(pn, classes[i].getName(), desc, d);
    }
    return params;
}
Also used : Description(org.apache.openejb.api.jmx.Description) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) Annotation(java.lang.annotation.Annotation) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 43 with Descriptor

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

the class AbstractReflectiveMBeanInfoAssembler method getAttributeInfo.

/**
	 * Iterate through all properties on the MBean class and gives subclasses
	 * the chance to vote on the inclusion of both the accessor and mutator.
	 * If a particular accessor or mutator is voted for inclusion, the appropriate
	 * metadata is assembled and passed to the subclass for descriptor population.
	 * @param managedBean the bean instance (might be an AOP proxy)
	 * @param beanKey the key associated with the MBean in the beans map
	 * of the {@code MBeanExporter}
	 * @return the attribute metadata
	 * @throws JMException in case of errors
	 * @see #populateAttributeDescriptor
	 */
@Override
protected ModelMBeanAttributeInfo[] getAttributeInfo(Object managedBean, String beanKey) throws JMException {
    PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean));
    List<ModelMBeanAttributeInfo> infos = new ArrayList<>();
    for (PropertyDescriptor prop : props) {
        Method getter = prop.getReadMethod();
        if (getter != null && getter.getDeclaringClass() == Object.class) {
            continue;
        }
        if (getter != null && !includeReadAttribute(getter, beanKey)) {
            getter = null;
        }
        Method setter = prop.getWriteMethod();
        if (setter != null && !includeWriteAttribute(setter, beanKey)) {
            setter = null;
        }
        if (getter != null || setter != null) {
            // If both getter and setter are null, then this does not need exposing.
            String attrName = JmxUtils.getAttributeName(prop, isUseStrictCasing());
            String description = getAttributeDescription(prop, beanKey);
            ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter);
            Descriptor desc = info.getDescriptor();
            if (getter != null) {
                desc.setField(FIELD_GET_METHOD, getter.getName());
            }
            if (setter != null) {
                desc.setField(FIELD_SET_METHOD, setter.getName());
            }
            populateAttributeDescriptor(desc, getter, setter, beanKey);
            info.setDescriptor(desc);
            infos.add(info);
        }
    }
    return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}
Also used : ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) Descriptor(javax.management.Descriptor) PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method)

Example 44 with Descriptor

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

the class AbstractMetadataAssemblerTests method testMetricDescriptorDefaults.

@Test
public void testMetricDescriptorDefaults() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    Descriptor desc = info.getAttribute(CACHE_ENTRIES_METRIC).getDescriptor();
    assertNull("Currency Time Limit should not be populated", desc.getFieldValue("currencyTimeLimit"));
    assertNull("Persist Policy should not be populated", desc.getFieldValue("persistPolicy"));
    assertNull("Persist Period should not be populated", desc.getFieldValue("persistPeriod"));
    assertNull("Unit should not be populated", desc.getFieldValue("units"));
    assertEquals("Display Name should be populated by default via JMX", CACHE_ENTRIES_METRIC, desc.getFieldValue("displayName"));
    assertEquals("Metric Type should be GAUGE", "GAUGE", desc.getFieldValue("metricType"));
    assertNull("Metric Category should not be populated", desc.getFieldValue("metricCategory"));
}
Also used : Descriptor(javax.management.Descriptor) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Example 45 with Descriptor

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

the class AbstractMetadataAssemblerTests method testOperationDescriptor.

@Test
public void testOperationDescriptor() throws Exception {
    ModelMBeanInfo info = getMBeanInfoFromAssembler();
    Descriptor desc = info.getOperation("myOperation").getDescriptor();
    assertEquals("Currency Time Limit should be 30", "30", desc.getFieldValue("currencyTimeLimit"));
    assertEquals("Role should be \"operation\"", "operation", desc.getFieldValue("role"));
}
Also used : Descriptor(javax.management.Descriptor) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) Test(org.junit.Test)

Aggregations

Descriptor (javax.management.Descriptor)73 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)16 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)16 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)11 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)11 Method (java.lang.reflect.Method)10 ImmutableDescriptor (javax.management.ImmutableDescriptor)9 MBeanException (javax.management.MBeanException)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)8 MBeanInfo (javax.management.MBeanInfo)8 MBeanServer (javax.management.MBeanServer)8 ObjectName (javax.management.ObjectName)8 ServiceNotFoundException (javax.management.ServiceNotFoundException)8 ArrayList (java.util.ArrayList)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 MBeanOperationInfo (javax.management.MBeanOperationInfo)7 MBeanParameterInfo (javax.management.MBeanParameterInfo)7