use of cn.taketoday.jmx.export.metadata.InvalidMetadataException in project today-infrastructure by TAKETODAY.
the class AnnotationJmxAttributeSource method getManagedResource.
@Override
@Nullable
public cn.taketoday.jmx.export.metadata.ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException {
MergedAnnotation<ManagedResource> ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY).get(ManagedResource.class).withNonMergedAttributes();
if (!ann.isPresent()) {
return null;
}
Class<?> declaringClass = (Class<?>) ann.getSource();
Class<?> target = (declaringClass != null && !declaringClass.isInterface() ? declaringClass : beanClass);
if (!Modifier.isPublic(target.getModifiers())) {
throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public");
}
cn.taketoday.jmx.export.metadata.ManagedResource bean = new cn.taketoday.jmx.export.metadata.ManagedResource();
Map<String, Object> map = ann.asMap();
List<PropertyValue> list = new ArrayList<>(map.size());
map.forEach((attrName, attrValue) -> {
if (!"value".equals(attrName)) {
Object value = attrValue;
if (this.embeddedValueResolver != null && value instanceof String) {
value = this.embeddedValueResolver.resolveStringValue((String) value);
}
list.add(new PropertyValue(attrName, value));
}
});
BeanWrapper.forBeanPropertyAccess(bean).setPropertyValues(new PropertyValues(list));
return bean;
}
use of cn.taketoday.jmx.export.metadata.InvalidMetadataException in project today-infrastructure by TAKETODAY.
the class MetadataMBeanInfoAssembler method populateMBeanDescriptor.
/**
* Adds descriptor fields from the {@code ManagedResource} attribute
* to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
* {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
* and {@code persistName} descriptor fields if they are present in the metadata.
*/
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
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.isNotEmpty(mr.getLogFile())) {
desc.setField(FIELD_LOG_FILE, mr.getLogFile());
}
if (StringUtils.isNotEmpty(mr.getPersistPolicy())) {
desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
}
if (mr.getPersistPeriod() >= 0) {
desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
}
if (StringUtils.isNotEmpty(mr.getPersistName())) {
desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
}
if (StringUtils.isNotEmpty(mr.getPersistLocation())) {
desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
}
}
use of cn.taketoday.jmx.export.metadata.InvalidMetadataException in project today-framework by TAKETODAY.
the class MetadataMBeanInfoAssembler method populateMBeanDescriptor.
/**
* Adds descriptor fields from the {@code ManagedResource} attribute
* to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
* {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
* and {@code persistName} descriptor fields if they are present in the metadata.
*/
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
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.isNotEmpty(mr.getLogFile())) {
desc.setField(FIELD_LOG_FILE, mr.getLogFile());
}
if (StringUtils.isNotEmpty(mr.getPersistPolicy())) {
desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
}
if (mr.getPersistPeriod() >= 0) {
desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
}
if (StringUtils.isNotEmpty(mr.getPersistName())) {
desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
}
if (StringUtils.isNotEmpty(mr.getPersistLocation())) {
desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
}
}
use of cn.taketoday.jmx.export.metadata.InvalidMetadataException in project today-framework by TAKETODAY.
the class AnnotationJmxAttributeSource method getManagedResource.
@Override
@Nullable
public cn.taketoday.jmx.export.metadata.ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException {
MergedAnnotation<ManagedResource> ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY).get(ManagedResource.class).withNonMergedAttributes();
if (!ann.isPresent()) {
return null;
}
Class<?> declaringClass = (Class<?>) ann.getSource();
Class<?> target = (declaringClass != null && !declaringClass.isInterface() ? declaringClass : beanClass);
if (!Modifier.isPublic(target.getModifiers())) {
throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public");
}
cn.taketoday.jmx.export.metadata.ManagedResource bean = new cn.taketoday.jmx.export.metadata.ManagedResource();
Map<String, Object> map = ann.asMap();
List<PropertyValue> list = new ArrayList<>(map.size());
map.forEach((attrName, attrValue) -> {
if (!"value".equals(attrName)) {
Object value = attrValue;
if (this.embeddedValueResolver != null && value instanceof String) {
value = this.embeddedValueResolver.resolveStringValue((String) value);
}
list.add(new PropertyValue(attrName, value));
}
});
BeanWrapper.forBeanPropertyAccess(bean).setPropertyValues(new PropertyValues(list));
return bean;
}
Aggregations