List of usage examples for javax.management.modelmbean ModelMBeanAttributeInfo setDescriptor
public void setDescriptor(Descriptor inDescriptor)
From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java
private static ModelMBeanAttributeInfo[] extractAttributeInfo(Object object) { Map<String, Method> getters = new HashMap<String, Method>(); Map<String, Method> setters = new HashMap<String, Method>(); Map<String, String> descriptions = new HashMap<String, String>(); for (Method m : object.getClass().getMethods()) { JmxGetter getter = m.getAnnotation(JmxGetter.class); if (getter != null) { getters.put(getter.name(), m); descriptions.put(getter.name(), getter.description()); }/*from w w w .j a v a 2 s . co m*/ JmxSetter setter = m.getAnnotation(JmxSetter.class); if (setter != null) { setters.put(setter.name(), m); descriptions.put(setter.name(), setter.description()); } } Set<String> attributes = new HashSet<String>(getters.keySet()); attributes.addAll(setters.keySet()); List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>(); for (String name : attributes) { try { Method getter = getters.get(name); Method setter = setters.get(name); ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(name, descriptions.get(name), getter, setter); Descriptor descriptor = info.getDescriptor(); if (getter != null) descriptor.setField("getMethod", getter.getName()); if (setter != null) descriptor.setField("setMethod", setter.getName()); info.setDescriptor(descriptor); infos.add(info); } catch (IntrospectionException e) { throw new RuntimeException(e); } } return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]); }