List of usage examples for javax.management Descriptor getFieldValue
public Object getFieldValue(String fieldName) throws RuntimeOperationsException;
From source file:com.proofpoint.jmx.MBeanRepresentation.java
private static Map<String, Object> toMap(Descriptor descriptor) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (String fieldName : descriptor.getFieldNames()) { Object fieldValue = descriptor.getFieldValue(fieldName); if (fieldValue != null) { if (fieldValue instanceof Descriptor) { fieldValue = toMap((Descriptor) fieldValue); }/*from www. j a v a 2 s . co m*/ builder.put(fieldName, fieldValue); } } ImmutableMap<String, Object> map = builder.build(); if (!map.isEmpty()) { return map; } else { return null; } }
From source file:com.oracle.weblogic.examples.spring.jmx.WLDFAwareReflectiveMBeanInfoAssembler.java
@Override protected void populateMBeanDescriptor(Descriptor descriptor, Object managedBean, String beanKey) { super.populateMBeanDescriptor(descriptor, managedBean, beanKey); descriptor.setField(WLDF_MBEAN_TYPE_DESCPTR_KEY, descriptor.getFieldValue(NAME_MBEAN_DESCPTR_KEY) + MBEAN_KEYNAME_SUFFIX); }
From source file:org.apache.geode.management.internal.security.MBeanServerWrapper.java
private ResourcePermission getOperationContext(Descriptor descriptor, ResourcePermission defaultValue) { String resource = (String) descriptor.getFieldValue("resource"); String operationCode = (String) descriptor.getFieldValue("operation"); String targetCode = (String) descriptor.getFieldValue("target"); if (resource != null && operationCode != null) { if (StringUtils.isBlank(targetCode)) { return new ResourcePermission(Resource.valueOf(resource), Operation.valueOf(operationCode)); } else {/*w w w .jav a2 s.c o m*/ return new ResourcePermission(Resource.valueOf(resource), Operation.valueOf(operationCode), Target.valueOf(targetCode).getName()); } } return defaultValue; }
From source file:org.echocat.jemoni.carbon.jmx.Jmx2CarbonBridge.java
@Nullable protected AttributeDefinition findDefinitionFor(@Nonnull ObjectName objectName, @Nonnull MBeanAttributeInfo info) { final Descriptor descriptor = info.getDescriptor(); final OpenType<?> openType = (OpenType<?>) descriptor.getFieldValue("openType"); return findDefinitionFor(objectName, info, info.getName(), openType); }
From source file:org.eclipse.smila.management.jmx.AgentMBean.java
/** * {@inheritDoc}//from w w w . j a va2 s.com * * @see javax.management.DynamicMBean#getAttribute(java.lang.String) */ public Object getAttribute(final String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { final ModelMBeanAttributeInfo info = _beanInfo.getAttribute(attribute); final Descriptor descriptor = info.getDescriptor(); final String getterMethod = (String) (descriptor.getFieldValue("getMethod")); return invoke(getterMethod, ClassHelper.EMPTY_PARAMS, ClassHelper.EMPTY_SIGNATURE); }
From source file:org.eclipse.smila.management.jmx.AgentMBean.java
/** * {@inheritDoc}/*from w w w. j av a2s. c om*/ * * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute) */ public void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { final ModelMBeanAttributeInfo info = _beanInfo.getAttribute(attribute.getName()); if (info == null) { final String msg = "MBean " + _beanInfo.getClassName() + " doesnt contain attribute Information for method " + attribute.getName() + ", please check if you have defined a gettter and setter for this Attriubute!"; _log.error(msg); throw new AttributeNotFoundException(msg); } final Descriptor descriptor = info.getDescriptor(); final String setterMethod = (String) (descriptor.getFieldValue("setMethod")); final String setterSignatureClass = (String) (descriptor.getFieldValue("setterSignatureClass")); invoke(setterMethod, new Object[] { attribute.getValue() }, new String[] { setterSignatureClass }); }
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 av a 2 s . c o m 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); }
From source file:org.hyperic.hq.product.jmx.ServiceTypeFactory.java
/** * Returns a ServiceType containing ONLY the properties needed at construction time (the ones that guarantee uniqueness) * @param productName The name of the product containing the service * @param serverType The name of the server containing the service * @param serviceInfo Info about the service * @param objectName The {@link ObjectName} of the discovered MBean representing the service instance * @return A ServiceType containing ONLY the properties needed at construction time (the ones that guarantee uniqueness) *//* w ww.j ava2 s . com*/ public ServiceType getServiceType(String productName, ServerTypeInfo serverType, ModelMBeanInfo serviceInfo, ObjectName objectName) { String serviceTypeName = objectName.getKeyProperty("type"); final String subType = objectName.getKeyProperty("subtype"); if (subType != null) { serviceTypeName = serviceTypeName + " " + subType; } try { Descriptor serviceDescriptor = serviceInfo.getMBeanDescriptor(); if ("false".equals(serviceDescriptor.getFieldValue("export"))) { return null; } String serviceType = (String) serviceDescriptor.getFieldValue("typeName"); if (serviceType != null) { serviceTypeName = serviceType; } } catch (Exception e) { log.warn("Error obtaining MBeanInfo descriptor field values. Default values will be used. Cause: " + e.getMessage()); } return new ServiceType(serviceTypeName, productName, new ServiceTypeInfo( serverType.getName() + ' ' + serviceTypeName, serviceInfo.getDescription(), serverType)); }