public void setNotificationInfos(ManagedNotification[] notificationInfos) { ModelMBeanNotificationInfo[] infos = new ModelMBeanNotificationInfo[notificationInfos.length]; for (int i = 0; i < notificationInfos.length; i++) { ManagedNotification notificationInfo = notificationInfos[i]; infos[i] = JmxMetadataUtils.convertToModelMBeanNotificationInfo(notificationInfo); } this.notificationInfos = infos; }
/** * Adds descriptor fields from the {@code ManagedAttribute} attribute * to the attribute descriptor. Specifically, adds the {@code currencyTimeLimit} * descriptor field if it is present in the metadata. */ @Override protected void populateOperationDescriptor(Descriptor desc, Method method, String beanKey) { ManagedOperation mo = obtainAttributeSource().getManagedOperation(method); if (mo != null) { applyCurrencyTimeLimit(desc, mo.getCurrencyTimeLimit()); } }
/** * Reads managed resource description from the source level metadata. * Returns an empty {@code String} if no description can be found. */ @Override protected String getDescription(Object managedBean, String beanKey) { ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); return (mr != null ? mr.getDescription() : ""); }
ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); if (mr == null) { throw new InvalidMetadataException( "No ManagedResource attribute found for class: " + getClassToExpose(managedBean)); applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit()); if (mr.isLog()) { desc.setField(FIELD_LOG, "true"); if (StringUtils.hasLength(mr.getLogFile())) { desc.setField(FIELD_LOG_FILE, mr.getLogFile()); if (StringUtils.hasLength(mr.getPersistPolicy())) { desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy()); if (mr.getPersistPeriod() >= 0) { desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod())); if (StringUtils.hasLength(mr.getPersistName())) { desc.setField(FIELD_PERSIST_NAME, mr.getPersistName()); if (StringUtils.hasLength(mr.getPersistLocation())) { desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
/** * Retrieves the description for the supplied {@code Method} from the * metadata. Uses the method name is no description is present in the metadata. */ @Override protected String getOperationDescription(Method method, String beanKey) { PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); if (pd != null) { ManagedAttribute ma = obtainAttributeSource().getManagedAttribute(method); if (ma != null && StringUtils.hasText(ma.getDescription())) { return ma.getDescription(); } ManagedMetric metric = obtainAttributeSource().getManagedMetric(method); if (metric != null && StringUtils.hasText(metric.getDescription())) { return metric.getDescription(); } return method.getName(); } else { ManagedOperation mo = obtainAttributeSource().getManagedOperation(method); if (mo != null && StringUtils.hasText(mo.getDescription())) { return mo.getDescription(); } return method.getName(); } }
/** * Creates a description for the attribute corresponding to this property * descriptor. Attempts to create the description using metadata from either * the getter or setter attributes, otherwise uses the property name. */ @Override protected String getAttributeDescription(PropertyDescriptor propertyDescriptor, String beanKey) { Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); ManagedAttribute getter = (readMethod != null ? obtainAttributeSource().getManagedAttribute(readMethod) : null); ManagedAttribute setter = (writeMethod != null ? obtainAttributeSource().getManagedAttribute(writeMethod) : null); if (getter != null && StringUtils.hasText(getter.getDescription())) { return getter.getDescription(); } else if (setter != null && StringUtils.hasText(setter.getDescription())) { return setter.getDescription(); } ManagedMetric metric = (readMethod != null ? obtainAttributeSource().getManagedMetric(readMethod) : null); if (metric != null && StringUtils.hasText(metric.getDescription())) { return metric.getDescription(); } return propertyDescriptor.getDisplayName(); }
/** * Reads the {@link ManagedNotification} metadata from the {@code Class} of the managed resource * and generates and returns the corresponding {@link ModelMBeanNotificationInfo} metadata. */ @Override protected ModelMBeanNotificationInfo[] getNotificationInfo(Object managedBean, String beanKey) { ManagedNotification[] notificationAttributes = obtainAttributeSource().getManagedNotifications(getClassToExpose(managedBean)); ModelMBeanNotificationInfo[] notificationInfos = new ModelMBeanNotificationInfo[notificationAttributes.length]; for (int i = 0; i < notificationAttributes.length; i++) { ManagedNotification attribute = notificationAttributes[i]; notificationInfos[i] = JmxMetadataUtils.convertToModelMBeanNotificationInfo(attribute); } return notificationInfos; }
@Override @Nullable public org.springframework.jmx.export.metadata.ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException { ManagedResource ann = AnnotationUtils.findAnnotation(beanClass, ManagedResource.class); if (ann == null) { return null; } Class<?> declaringClass = AnnotationUtils.findAnnotationDeclaringClass(ManagedResource.class, beanClass); Class<?> target = (declaringClass != null && !declaringClass.isInterface() ? declaringClass : beanClass); if (!Modifier.isPublic(target.getModifiers())) { throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public"); } org.springframework.jmx.export.metadata.ManagedResource managedResource = new org.springframework.jmx.export.metadata.ManagedResource(); AnnotationBeanUtils.copyPropertiesToBean(ann, managedResource, this.embeddedValueResolver); return managedResource; }
/** * Checks to see if the given Method has the {@code ManagedOperation} attribute. * @param method the method to check */ private boolean hasManagedOperation(Method method) { return (obtainAttributeSource().getManagedOperation(method) != null); }
/** * Used for autodetection of beans. Checks to see if the bean's class has a * {@code ManagedResource} attribute. If so it will add it list of included beans. * @param beanClass the class of the bean * @param beanName the name of the bean in the bean factory */ @Override public boolean includeBean(Class<?> beanClass, String beanName) { return (obtainAttributeSource().getManagedResource(getClassToExpose(beanClass)) != null); }
/** * Checks to see if the given Method has the {@code ManagedAttribute} attribute. */ private boolean hasManagedAttribute(Method method) { return (obtainAttributeSource().getManagedAttribute(method) != null); }
/** * Checks to see if the given Method has the {@code ManagedMetric} attribute. */ private boolean hasManagedMetric(Method method) { return (obtainAttributeSource().getManagedMetric(method) != null); }
/** * Adds descriptor fields from the {@code ManagedAttribute} attribute * to the attribute descriptor. Specifically, adds the {@code currencyTimeLimit} * descriptor field if it is present in the metadata. */ @Override protected void populateOperationDescriptor(Descriptor desc, Method method, String beanKey) { ManagedOperation mo = obtainAttributeSource().getManagedOperation(method); if (mo != null) { applyCurrencyTimeLimit(desc, mo.getCurrencyTimeLimit()); } }
/** * Reads managed resource description from the source level metadata. * Returns an empty {@code String} if no description can be found. */ @Override protected String getDescription(Object managedBean, String beanKey) { ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); return (mr != null ? mr.getDescription() : ""); }
/** * Reads the {@link ManagedNotification} metadata from the {@code Class} of the managed resource * and generates and returns the corresponding {@link ModelMBeanNotificationInfo} metadata. */ @Override protected ModelMBeanNotificationInfo[] getNotificationInfo(Object managedBean, String beanKey) { ManagedNotification[] notificationAttributes = obtainAttributeSource().getManagedNotifications(getClassToExpose(managedBean)); ModelMBeanNotificationInfo[] notificationInfos = new ModelMBeanNotificationInfo[notificationAttributes.length]; for (int i = 0; i < notificationAttributes.length; i++) { ManagedNotification attribute = notificationAttributes[i]; notificationInfos[i] = JmxMetadataUtils.convertToModelMBeanNotificationInfo(attribute); } return notificationInfos; }
/** * Checks to see if the given Method has the {@code ManagedOperation} attribute. * @param method the method to check */ private boolean hasManagedOperation(Method method) { return (obtainAttributeSource().getManagedOperation(method) != null); }
/** * Used for autodetection of beans. Checks to see if the bean's class has a * {@code ManagedResource} attribute. If so it will add it list of included beans. * @param beanClass the class of the bean * @param beanName the name of the bean in the bean factory */ @Override public boolean includeBean(Class<?> beanClass, String beanName) { return (obtainAttributeSource().getManagedResource(getClassToExpose(beanClass)) != null); }
public void setNotificationInfos(ManagedNotification[] notificationInfos) { ModelMBeanNotificationInfo[] infos = new ModelMBeanNotificationInfo[notificationInfos.length]; for (int i = 0; i < notificationInfos.length; i++) { ManagedNotification notificationInfo = notificationInfos[i]; infos[i] = JmxMetadataUtils.convertToModelMBeanNotificationInfo(notificationInfo); } this.notificationInfos = infos; }
/** * Checks to see if the given Method has the {@code ManagedAttribute} attribute. */ private boolean hasManagedAttribute(Method method) { return (obtainAttributeSource().getManagedAttribute(method) != null); }
/** * Checks to see if the given Method has the {@code ManagedMetric} attribute. */ private boolean hasManagedMetric(Method method) { return (obtainAttributeSource().getManagedMetric(method) != null); }