List of usage examples for javax.management.modelmbean ModelMBeanAttributeInfo getName
public String getName()
From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java
/** Define an attribute. * Explicit definition of an attribute. Reflection is used to * locate the actual getter and setter methods. * @param attrInfo ModelMBeanAttributeInfo. *///from w w w .j a va 2 s . co m public synchronized void defineAttribute(ModelMBeanAttributeInfo attrInfo) { if (_object == null) throw new IllegalStateException("No Object"); _dirty = true; String name = attrInfo.getName(); String uName = name.substring(0, 1).toUpperCase() + name.substring(1); Class oClass = _object.getClass(); try { Class type = TypeUtil.fromName(attrInfo.getType()); if (type == null) type = Thread.currentThread().getContextClassLoader().loadClass(attrInfo.getType()); Method getter = null; Method setter = null; if (attrInfo.isReadable()) getter = oClass.getMethod((attrInfo.isIs() ? "is" : "get") + uName, (java.lang.Class[]) null); if (attrInfo.isWritable()) setter = oClass.getMethod("set" + uName, new Class[] { type }); _getter.put(name, getter); _setter.put(name, setter); _attributes.add(attrInfo); } catch (Exception e) { log.warn(LogSupport.EXCEPTION, e); throw new IllegalArgumentException(e.toString()); } }
From source file:org.hyperic.hq.product.jmx.ServiceTypeFactory.java
private MeasurementInfo createMeasurementInfo(final ServiceType serviceType, final ProductPlugin productPlugin, ModelMBeanAttributeInfo attribute) { Properties measurementProperties = new Properties(); Descriptor descriptor = attribute.getDescriptor(); String units = (String) descriptor.getFieldValue(MeasurementInfo.ATTR_UNITS); if ("s".equals(units)) { units = MeasurementConstants.UNITS_SECONDS; }// w w w . j a va 2 s . c om if (!VALID_UNITS.contains(units)) { measurementProperties.put(MeasurementInfo.ATTR_UNITS, "none"); } else { measurementProperties.put(MeasurementInfo.ATTR_UNITS, units); } final String displayName = (String) descriptor.getFieldValue("displayName"); // Not likely to be null, as JMX impl currently populates it with // attribute name if not set if (displayName == null) { measurementProperties.put(MeasurementInfo.ATTR_NAME, attribute.getName()); } else { measurementProperties.put(MeasurementInfo.ATTR_NAME, displayName); } measurementProperties.put(MeasurementInfo.ATTR_ALIAS, attribute.getName()); String metricType = (String) descriptor.getFieldValue("metricType"); if (metricType == null || !("COUNTER".equals(metricType.toUpperCase()))) { //GAUGE measurementProperties.put(MeasurementInfo.ATTR_COLLECTION_TYPE, "dynamic"); measurementProperties.put(MeasurementInfo.ATTR_INTERVAL, "300000"); } else { //COUNTER measurementProperties.put(MeasurementInfo.ATTR_COLLECTION_TYPE, "trendsup"); String rate = (String) descriptor.getFieldValue("rate"); if (rate != null) { measurementProperties.put(MeasurementInfo.ATTR_RATE, rate); } else { measurementProperties.put(MeasurementInfo.ATTR_RATE, "none"); } measurementProperties.put(MeasurementInfo.ATTR_INTERVAL, "600000"); } String collectionInterval = (String) descriptor.getFieldValue("collectionInterval"); if (collectionInterval != null) { try { Long.valueOf(collectionInterval); measurementProperties.put(MeasurementInfo.ATTR_INTERVAL, collectionInterval); } catch (NumberFormatException e) { log.warn("Specified collection interval " + collectionInterval + " is not numeric. Default value will be used instead."); } } String category = (String) descriptor.getFieldValue("metricCategory"); if (category == null || !VALID_CATEGORIES.contains(category.toUpperCase())) { measurementProperties.put(MeasurementInfo.ATTR_CATEGORY, MeasurementConstants.CAT_UTILIZATION); } else { measurementProperties.put(MeasurementInfo.ATTR_CATEGORY, category.toUpperCase()); } String indicator = (String) descriptor.getFieldValue("indicator"); if (indicator == null || "true".equals(indicator.toLowerCase())) { //indicator is not in Spring 3.0 @ManagedMetric. Turn measurement on and make indicator by default measurementProperties.put(MeasurementInfo.ATTR_INDICATOR, "true"); measurementProperties.put(MeasurementInfo.ATTR_DEFAULTON, "true"); } else { measurementProperties.put(MeasurementInfo.ATTR_INDICATOR, "false"); measurementProperties.put(MeasurementInfo.ATTR_DEFAULTON, "false"); } String defaultOn = (String) descriptor.getFieldValue("defaultOn"); if (defaultOn != null) { if ("true".equals(defaultOn.toLowerCase()) || "false".equals(defaultOn.toLowerCase())) { measurementProperties.put(MeasurementInfo.ATTR_DEFAULTON, defaultOn.toLowerCase()); } else { log.warn("Invalid value of " + defaultOn + " specified for defaultOn. Default value will be used instead."); } } addMeasurementTemplate(measurementProperties, productPlugin, serviceType); return createMeasurementInfo(measurementProperties); }