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())) {
LOGGER.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<>();
Set<ManagedOperationInfo> operations = new LinkedHashSet<>();
Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<>();
Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<>();
Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<>();
// 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);
LOGGER.trace("Created ModelMBeanInfo {}", info);
return info;
}
java类javax.management.modelmbean.ModelMBeanOperationInfo的实例源码
MBeanInfoAssembler.java 文件源码
项目:flowable-engine
阅读 21
收藏 0
点赞 0
评论 0
MBeanInfoAssembler.java 文件源码
项目:Camel
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
MetadataMBeanInfoAssembler.java 文件源码
项目:metaworks_framework
阅读 20
收藏 0
点赞 0
评论 0
protected ModelMBeanOperationInfo[] getOperationInfo(Object managedBean, String beanKey) {
managedBean = AspectUtil.exposeRootBean(managedBean);
return super.getOperationInfo(managedBean, beanKey);
}
MetadataMBeanInfoAssembler.java 文件源码
项目:SparkCommerce
阅读 19
收藏 0
点赞 0
评论 0
protected ModelMBeanOperationInfo[] getOperationInfo(Object managedBean, String beanKey) {
managedBean = AspectUtil.exposeRootBean(managedBean);
return super.getOperationInfo(managedBean, beanKey);
}
MetadataMBeanInfoAssembler.java 文件源码
项目:blcdemo
阅读 22
收藏 0
点赞 0
评论 0
protected ModelMBeanOperationInfo[] getOperationInfo(Object managedBean, String beanKey) {
managedBean = AspectUtil.exposeRootBean(managedBean);
return super.getOperationInfo(managedBean, beanKey);
}
AnnotationMetadataAssemblerTests.java 文件源码
项目:class-guard
阅读 20
收藏 0
点赞 0
评论 0
@Test
public void testOperationFromInterface() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanOperationInfo op = inf.getOperation("fromInterface");
assertNotNull(op);
}
AnnotationMetadataAssemblerTests.java 文件源码
项目:class-guard
阅读 18
收藏 0
点赞 0
评论 0
@Test
public void testOperationOnGetter() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanOperationInfo op = inf.getOperation("getExpensiveToCalculate");
assertNotNull(op);
}
InvocationTest.java 文件源码
项目:freeVM
阅读 26
收藏 0
点赞 0
评论 0
private void printValue(MBeanInfo beanInfo) {
ModelMBeanOperationInfo operationInfo2 = (ModelMBeanOperationInfo)beanInfo
.getOperations()[0];
assertEquals(returnedObject, operationInfo2.getDescriptor()
.getFieldValue("value"));
}
RequiredModelMBeanTest.java 文件源码
项目:freeVM
阅读 18
收藏 0
点赞 0
评论 0
/**
* Verify that value of attribute return value which return getter method if
* currencyTimeLimit < 0.
* <ul>
* Step by step:
* <li>1.Create java class, which is not MBean. This class has getter and
* setter methods.
* <li>2.Create ModelMBeanAttibuteInfo object for class in 1st step.
* <li>3.Extract descriptor from ModelMBeanAttibuteInfo class and set
* additional fields currencyTimeLimit < 0 and setMethod=nameOfSetterMethod.
* <li>4.Create ModelMBeanInfoSupport object.
* <li>5.Create RequiredModelMBean object.
* <li>6.Create notification listener and register it in RequiredModelMBean
* object for attribute using addAttributeChangeNotificationListener.
* <li>7.Instance of java class in 1st step sets managed resource for
* RequiredModelMBean using setManagedResource method.
* <li>8.Create objectName.
* <li>9.Register RequiredModelMBean object in MBeanServer with objectName
* specified in previous step.
* <li>10.Set attribute on MBeanServer using setAttribute method.
* <li>11.Verify that notification listener was notified about change
* attribute.
* <li>12.Verify that setter method was invoked.
* <li>13.Verify that getAttribute of MBeanServer returns correct value of
* attribute and getter method was invoked.
* <li>14. Invoke again getAttribute of MBeanServer method and verify
* returned value. Also verify that getter method was invoked.
* </ul>
*/
public Result testNegative() throws Exception {
Method getter = class1.getMethod("getG", null);
Method setter = class1.getMethod("setG", new Class[] { String.class });
ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
"name", "description", getter, setter);
Descriptor descriptor = attributeInfoForG.getDescriptor();
descriptor.setField("currencyTimeLimit", "-1");
descriptor.setField("setMethod", setter.getName());
descriptor.setField("getMethod", getter.getName());
attributeInfoForG.setDescriptor(descriptor);
ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
ModelMBeanOperationInfo[] operationInfos = new ModelMBeanOperationInfo[] {
new ModelMBeanOperationInfo("description", setter),
new ModelMBeanOperationInfo("description", getter) };
ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
class1.getName(), "description", attributeInfos, null,
operationInfos, null);
RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
beanInfoSupport);
ManageResourceAndNotification notificationListener = new ManageResourceAndNotification();
requiredModelMBean.addAttributeChangeNotificationListener(
notificationListener, attributeInfoForG.getName(),
ManageResourceAndNotification.handback);
ManageResourceAndNotification managedResource = new ManageResourceAndNotification();
requiredModelMBean.setManagedResource(managedResource,
"ObjectReference");
ObjectName objectName = new ObjectName("domain", "name", "simple name");
MBeanServer server = MBeanServerFactory.createMBeanServer();
server.registerMBean(requiredModelMBean, objectName);
String newValue = "new value";
server.setAttribute(objectName, new Attribute(attributeInfoForG
.getName(), newValue));
assertTrue(notificationListener.isWasHandleNotificationInvoked());
assertEquals(managedResource.getG(), newValue);
managedResource.isGetGWasInvoked();
assertEquals(server.getAttribute(objectName, attributeInfoForG
.getName()), newValue);
assertTrue(managedResource.isGetGWasInvoked());
assertTrue(server.getMBeanInfo(objectName).getAttributes()[0] == attributeInfoForG);
assertNull(attributeInfoForG.getDescriptor().getFieldValue("value"));
return result();
}
RequiredModelMBeanTest.java 文件源码
项目:freeVM
阅读 20
收藏 0
点赞 0
评论 0
/**
* Verify that value of attribute retrieves a value from cache if
* currencyTimeLimit = 0.
* <ul>
* Step by step:
* <li>1.Create java class, which is not MBean. This class has getter and
* setter methods.
* <li>2.Create ModelMBeanAttibuteInfo object for class in 1st step.
* <li>3.Extract descriptor from ModelMBeanAttibuteInfo class and set
* additional fields currencyTimeLimit = 0 and setMethod=nameOfSetterMethod.
* <li>4.Create ModelMBeanInfoSupport object.
* <li>5.Create RequiredModelMBean object.
* <li>6.Create notification listener and register it in RequiredModelMBean
* object for attribute using addAttributeChangeNotificationListener.
* <li>7.Instance of java class in 1st step sets managed resource for
* RequiredModelMBean using setManagedResource method.
* <li>8.Create objectName.
* <li>9.Register RequiredModelMBean object in MBeanServer with objectName
* specified in previous step.
* <li>10.Set attribute on MBeanServer using setAttribute method.
* <li>11.Verify that notification listener was notified about change
* attribute.
* <li>12.Verify that setter method was invoked.
* <li>13.Verify that getAttribute returns correct value of attribute and
* getter method was not invoked.
* <li>14.Verify value of field value of descriptor of
* ModelMBeanAttibuteInfo.
*/
public Result testZero() throws Exception {
Method getter = class1.getMethod("getG", null);
Method setter = class1.getMethod("setG", new Class[] { String.class });
ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
"name", "description", getter, setter);
Descriptor descriptor = attributeInfoForG.getDescriptor();
descriptor.setField("currencyTimeLimit", "0");
descriptor.setField("setMethod", setter.getName());
descriptor.setField("getMethod", getter.getName());
attributeInfoForG.setDescriptor(descriptor);
ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
ModelMBeanOperationInfo[] operationInfos = new ModelMBeanOperationInfo[] {
new ModelMBeanOperationInfo("description", setter),
new ModelMBeanOperationInfo("description", getter) };
ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
class1.getName(), "description", attributeInfos, null,
operationInfos, null);
RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
beanInfoSupport);
ManageResourceAndNotification notificationListener = new ManageResourceAndNotification();
requiredModelMBean.addAttributeChangeNotificationListener(
notificationListener, attributeInfoForG.getName(),
ManageResourceAndNotification.handback);
ManageResourceAndNotification managedResource = new ManageResourceAndNotification();
requiredModelMBean.setManagedResource(managedResource,
"ObjectReference");
ObjectName objectName = new ObjectName("domain", "name", "simple name");
MBeanServer server = MBeanServerFactory.createMBeanServer();
server.registerMBean(requiredModelMBean, objectName);
String newValue = "new value";
server.setAttribute(objectName, new Attribute(attributeInfoForG
.getName(), newValue));
assertTrue(notificationListener.isWasHandleNotificationInvoked());
assertEquals(managedResource.getG(), newValue);
managedResource.isGetGWasInvoked();
assertEquals(server.getAttribute(objectName, attributeInfoForG
.getName()), newValue);
assertFalse(managedResource.isGetGWasInvoked());
assertTrue(server.getMBeanInfo(objectName).getAttributes()[0] == attributeInfoForG);
assertEquals(attributeInfoForG.getDescriptor().getFieldValue("value"),
newValue);
return result();
}