use of cn.taketoday.jmx.export.metadata.ManagedResource 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.ManagedResource in project today-infrastructure by TAKETODAY.
the class MetadataNamingStrategy method getObjectName.
/**
* Reads the {@code ObjectName} from the source-level metadata associated
* with the managed resource's {@code Class}.
*/
@Override
public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException {
Assert.state(attributeSource != null, "No JmxAttributeSource set");
Class<?> managedClass = AopUtils.getTargetClass(managedBean);
ManagedResource mr = attributeSource.getManagedResource(managedClass);
// Check that an object name has been specified.
if (mr != null && StringUtils.hasText(mr.getObjectName())) {
return ObjectNameManager.getInstance(mr.getObjectName());
} else {
Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified");
try {
return ObjectNameManager.getInstance(beanKey);
} catch (MalformedObjectNameException ex) {
String domain = this.defaultDomain;
if (domain == null) {
domain = ClassUtils.getPackageName(managedClass);
}
Hashtable<String, String> properties = new Hashtable<>();
properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", beanKey);
return ObjectNameManager.getInstance(domain, properties);
}
}
}
use of cn.taketoday.jmx.export.metadata.ManagedResource 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.ManagedResource in project today-framework by TAKETODAY.
the class MetadataNamingStrategy method getObjectName.
/**
* Reads the {@code ObjectName} from the source-level metadata associated
* with the managed resource's {@code Class}.
*/
@Override
public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException {
Assert.state(attributeSource != null, "No JmxAttributeSource set");
Class<?> managedClass = AopUtils.getTargetClass(managedBean);
ManagedResource mr = attributeSource.getManagedResource(managedClass);
// Check that an object name has been specified.
if (mr != null && StringUtils.hasText(mr.getObjectName())) {
return ObjectNameManager.getInstance(mr.getObjectName());
} else {
Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified");
try {
return ObjectNameManager.getInstance(beanKey);
} catch (MalformedObjectNameException ex) {
String domain = this.defaultDomain;
if (domain == null) {
domain = ClassUtils.getPackageName(managedClass);
}
Hashtable<String, String> properties = new Hashtable<>();
properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", beanKey);
return ObjectNameManager.getInstance(domain, properties);
}
}
}
Aggregations