use of javax.management.modelmbean.ModelMBeanInfo in project Activiti by Activiti.
the class MBeanInfoAssembler method getMBeanInfo.
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
if ((defaultManagedBean == null && customManagedBean == null) || objectName == null)
return null;
// skip proxy classes
if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
return null;
}
// maps and lists to contain information about attributes and operations
Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();
// extract details from default managed bean
if (defaultManagedBean != null) {
extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
}
// extract details from custom managed bean
if (customManagedBean != null) {
extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
extractMbeanOperations(customManagedBean, operations, mBeanOperations);
extractMbeanNotifications(customManagedBean, mBeanNotifications);
}
// create the ModelMBeanInfo
String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
LOG.trace("Created ModelMBeanInfo {}", info);
return info;
}
use of javax.management.modelmbean.ModelMBeanInfo in project Activiti by Activiti.
the class MBeanInfoAssemblerTest method testInherited.
@Test
public void testInherited() throws JMException {
ModelMBeanInfo beanInfo = mbeanInfoAssembler.getMBeanInfo(new BadInherited(), null, "someName");
assertNotNull(beanInfo);
assertNotNull(beanInfo.getAttributes());
assertEquals(2, beanInfo.getAttributes().length);
assertNotNull(beanInfo.getOperations());
assertEquals(3, beanInfo.getOperations().length);
}
use of javax.management.modelmbean.ModelMBeanInfo in project camel by apache.
the class SpringManagementMBeanAssembler method assemble.
public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
ModelMBeanInfo mbi = null;
// prefer to use the managed instance if it has been annotated with Spring JMX annotations
if (obj instanceof ManagedInstance) {
Object custom = ((ManagedInstance) obj).getInstance();
if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom);
// get the mbean info from the custom managed object
mbi = springAssembler.getMBeanInfo(custom, name.toString());
// and let the custom object be registered in JMX
obj = custom;
}
}
if (mbi == null) {
if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class)) {
// the object has a Spring ManagedResource annotations so assemble the MBeanInfo
LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
mbi = springAssembler.getMBeanInfo(obj, name.toString());
} else {
// fallback and let the default mbean assembler handle this instead
return super.assemble(mBeanServer, obj, name);
}
}
LOG.trace("Assembled MBeanInfo {}", mbi);
RequiredModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
mbean.setModelMBeanInfo(mbi);
try {
mbean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException e) {
throw new JMException(e.getMessage());
}
// Allows the managed object to send notifications
if (obj instanceof NotificationSenderAware) {
((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
}
return mbean;
}
use of javax.management.modelmbean.ModelMBeanInfo in project camel by apache.
the class MBeanInfoAssembler method getMBeanInfo.
/**
* Gets the {@link ModelMBeanInfo} for the given managed bean
*
* @param defaultManagedBean the default managed bean
* @param customManagedBean an optional custom managed bean
* @param objectName the object name
* @return the model info, or <tt>null</tt> if not possible to create, for example due the managed bean is a proxy class
* @throws JMException is thrown if error creating the model info
*/
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
// skip proxy classes
if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
return null;
}
// maps and lists to contain information about attributes and operations
Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();
// extract details from default managed bean
if (defaultManagedBean != null) {
extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
}
// extract details from custom managed bean
if (customManagedBean != null) {
extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
extractMbeanOperations(customManagedBean, operations, mBeanOperations);
extractMbeanNotifications(customManagedBean, mBeanNotifications);
}
// create the ModelMBeanInfo
String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
LOG.trace("Created ModelMBeanInfo {}", info);
return info;
}
use of javax.management.modelmbean.ModelMBeanInfo in project camel by apache.
the class DefaultManagementMBeanAssembler method assemble.
public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
ModelMBeanInfo mbi = null;
ModelMBeanInfo standardMbi = null;
Object custom = null;
// prefer to use the managed instance if it has been annotated with JMX annotations
if (obj instanceof ManagedInstance) {
// there may be a custom embedded instance which have additional methods
custom = ((ManagedInstance) obj).getInstance();
if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom);
// get the mbean info into different groups (mbi = both, standard = standard out of the box mbi)
mbi = assembler.getMBeanInfo(obj, custom, name.toString());
standardMbi = assembler.getMBeanInfo(obj, null, name.toString());
}
}
if (mbi == null) {
// use the default provided mbean which has been annotated with JMX annotations
LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
mbi = assembler.getMBeanInfo(obj, null, name.toString());
}
if (mbi == null) {
return null;
}
RequiredModelMBean mbean;
RequiredModelMBean mixinMBean = null;
boolean sanitize = camelContext.getManagementStrategy().getManagementAgent().getMask() != null && camelContext.getManagementStrategy().getManagementAgent().getMask();
// as we want a combined mbean that has both the custom and the standard
if (standardMbi != null) {
mixinMBean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
mixinMBean.setModelMBeanInfo(standardMbi);
try {
mixinMBean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException e) {
throw new JMException(e.getMessage());
}
// use custom as the object to call
obj = custom;
}
// use a mixin mbean model to combine the custom and standard (custom is optional)
mbean = new MixinRequiredModelMBean(mbi, sanitize, standardMbi, mixinMBean);
try {
mbean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException e) {
throw new JMException(e.getMessage());
}
// Allows the managed object to send notifications
if (obj instanceof NotificationSenderAware) {
((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
}
return mbean;
}
Aggregations