use of javax.management.MBeanConstructorInfo in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testGetMBeanInfo.
@Test
public final void testGetMBeanInfo() {
MemoryPoolMXBean testImpl = testBean;
MBeanInfo mbi = null;
try {
mbi = mbs.getMBeanInfo(objName);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
} catch (ReflectionException e) {
Assert.fail("Unexpected ReflectionException : " + e.getMessage());
} catch (IntrospectionException e) {
Assert.fail("Unexpected IntrospectionException : " + e.getMessage());
}
AssertJUnit.assertNotNull(mbi);
// Now make sure that what we got back is what we expected.
// Class name
AssertJUnit.assertTrue(mbi.getClassName().equals(testImpl.getClass().getName()));
// No public constructors
MBeanConstructorInfo[] constructors = mbi.getConstructors();
AssertJUnit.assertNotNull(constructors);
AssertJUnit.assertTrue(constructors.length == 0);
// One public operation - resetPeakUsage
MBeanOperationInfo[] operations = mbi.getOperations();
AssertJUnit.assertNotNull(operations);
AssertJUnit.assertTrue(operations.length == 1);
AssertJUnit.assertEquals("resetPeakUsage", operations[0].getName());
// No notifications
MBeanNotificationInfo[] notifications = mbi.getNotifications();
AssertJUnit.assertNotNull(notifications);
AssertJUnit.assertTrue(notifications.length == 0);
// Print description and the class name (not necessarily identical).
logger.debug("MBean description for " + testImpl.getClass().getName() + ": " + mbi.getDescription());
// Sixteen attributes - only two are writable.
MBeanAttributeInfo[] attributes = mbi.getAttributes();
AssertJUnit.assertNotNull(attributes);
AssertJUnit.assertTrue(attributes.length == 17);
for (int i = 0; i < attributes.length; i++) {
MBeanAttributeInfo info = attributes[i];
AssertJUnit.assertNotNull(info);
AllManagementTests.validateAttributeInfo(info, TestMemoryPoolMXBean.ignoredAttributes, attribs);
}
// end for
}
use of javax.management.MBeanConstructorInfo in project openj9 by eclipse.
the class TestMemoryManagerMXBean method testGetMBeanInfo.
@Test
public final void testGetMBeanInfo() {
MBeanInfo mbi = null;
try {
mbi = mbs.getMBeanInfo(objName);
} catch (InstanceNotFoundException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
} catch (ReflectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected ReflectionException : " + e.getMessage());
} catch (IntrospectionException e) {
// An unlikely exception - if this occurs, we can't proceed with the test.
Assert.fail("Unexpected IntrospectionException : " + e.getMessage());
}
AssertJUnit.assertNotNull(mbi);
// Now make sure that what we got back is what we expected.
/* Check the class name. Test substring match (not equals()) since clb.getClass().getName()
* typically returns a fully qualified name (prefixing package name). This should have always
* been prefixed by package name, and not being changed as an aftermath of current changes
*/
Class<?> mmbClass = mmb.getClass();
String runtimeType = mmbClass.getName();
AssertJUnit.assertTrue(runtimeType.endsWith(mbi.getClassName()));
// No public constructors
MBeanConstructorInfo[] constructors = mbi.getConstructors();
AssertJUnit.assertNotNull(constructors);
AssertJUnit.assertTrue(constructors.length == 0);
// No public operations
MBeanOperationInfo[] operations = mbi.getOperations();
AssertJUnit.assertNotNull(operations);
AssertJUnit.assertTrue(operations.length == 0);
// No notifications
MBeanNotificationInfo[] notifications = mbi.getNotifications();
AssertJUnit.assertNotNull(notifications);
/* nonHeap memoryManager has 0 notification and garbageCollector has 1 notification */
AssertJUnit.assertTrue((0 == notifications.length) || (1 == notifications.length));
// Print description and the class name (not necessarily identical).
logger.debug("MBean description for " + runtimeType + ": " + mbi.getDescription());
// The number of attributes depends on what kind of MemoryManagerMXBean
// we have.
MBeanAttributeInfo[] attributes = mbi.getAttributes();
AssertJUnit.assertNotNull(attributes);
if (GarbageCollectorMXBean.class.isAssignableFrom(mmbClass)) {
AssertJUnit.assertTrue(attributes.length == 11);
validateGCAttributes(attributes);
} else if (MemoryManagerMXBean.class.isAssignableFrom(mmbClass)) {
AssertJUnit.assertTrue(attributes.length == 4);
validateMemoryManagerAttributes(attributes);
} else {
Assert.fail("Unexpected kind of memory manager MXBean : " + runtimeType);
}
}
use of javax.management.MBeanConstructorInfo in project jetty.project by eclipse.
the class ObjectMBean method getMBeanInfo.
public MBeanInfo getMBeanInfo() {
try {
if (_info == null) {
// Start with blank lazy lists attributes etc.
String desc = null;
List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
List<MBeanConstructorInfo> constructors = new ArrayList<MBeanConstructorInfo>();
List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
List<MBeanNotificationInfo> notifications = new ArrayList<MBeanNotificationInfo>();
// Find list of classes that can influence the mbean
Class<?> o_class = _managed.getClass();
List<Class<?>> influences = new ArrayList<Class<?>>();
// always add MBean itself
influences.add(this.getClass());
influences = findInfluences(influences, _managed.getClass());
if (LOG.isDebugEnabled())
LOG.debug("Influence Count: {}", influences.size());
// Process Type Annotations
ManagedObject primary = o_class.getAnnotation(ManagedObject.class);
if (primary != null) {
desc = primary.value();
} else {
if (LOG.isDebugEnabled())
LOG.debug("No @ManagedObject declared on {}", _managed.getClass());
}
// For each influence
for (int i = 0; i < influences.size(); i++) {
Class<?> oClass = influences.get(i);
ManagedObject typeAnnotation = oClass.getAnnotation(ManagedObject.class);
if (LOG.isDebugEnabled())
LOG.debug("Influenced by: " + oClass.getCanonicalName());
if (typeAnnotation == null) {
if (LOG.isDebugEnabled())
LOG.debug("Annotations not found for: {}", oClass.getCanonicalName());
continue;
}
for (Method method : oClass.getDeclaredMethods()) {
ManagedAttribute methodAttributeAnnotation = method.getAnnotation(ManagedAttribute.class);
if (methodAttributeAnnotation != null) {
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
if (LOG.isDebugEnabled())
LOG.debug("Attribute Annotation found for: {}", method.getName());
MBeanAttributeInfo mai = defineAttribute(method, methodAttributeAnnotation);
if (mai != null) {
attributes.add(mai);
}
}
ManagedOperation methodOperationAnnotation = method.getAnnotation(ManagedOperation.class);
if (methodOperationAnnotation != null) {
if (LOG.isDebugEnabled())
LOG.debug("Method Annotation found for: {}", method.getName());
MBeanOperationInfo oi = defineOperation(method, methodOperationAnnotation);
if (oi != null) {
operations.add(oi);
}
}
}
}
_info = new MBeanInfo(o_class.getName(), desc, (MBeanAttributeInfo[]) attributes.toArray(new MBeanAttributeInfo[attributes.size()]), (MBeanConstructorInfo[]) constructors.toArray(new MBeanConstructorInfo[constructors.size()]), (MBeanOperationInfo[]) operations.toArray(new MBeanOperationInfo[operations.size()]), (MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
}
} catch (RuntimeException e) {
LOG.warn(e);
throw e;
}
return _info;
}
use of javax.management.MBeanConstructorInfo in project jdk8u_jdk by JetBrains.
the class MBeanInfoEqualsNPETest method main.
public static void main(String[] args) throws Exception {
System.out.println("---MBeanInfoEqualsNPETest-main ...");
// ----
System.out.println("\n---Testing on MBeanAttributeInfo...");
MBeanAttributeInfo mbeanAttributeInfo0 = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), "description", true, true, false);
MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "class name");
mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "type");
mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
test(mbeanAttributeInfo0, mbeanAttributeInfo, "description");
// ----
System.out.println("\n---Testing on MBeanConstructorInfo...");
MBeanConstructorInfo mbeanConstructorInfo0 = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, new DescriptorSupport());
MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "name");
mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "description");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
test(mbeanConstructorInfo0, mbeanConstructorInfo, "MBeanParameterInfo");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
test(mbeanConstructorInfo0, mbeanConstructorInfo, "descriptor");
// ----
System.out.println("\n---Testing on MBeanOperationInfo...");
MBeanOperationInfo mbeanOperationInfo0 = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "name");
mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "description");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "MBeanParameterInfo");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
test(mbeanOperationInfo0, mbeanOperationInfo, "type");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, null);
test(mbeanOperationInfo0, mbeanOperationInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanParameterInfo...");
MBeanParameterInfo mbeanParameterInfo0 = new MBeanParameterInfo("name", "type", "description", new DescriptorSupport());
MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "name");
mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "type");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanFeatureInfo ...");
MBeanFeatureInfo mbeanFeatureInfo0 = new MBeanFeatureInfo("name", "description", new DescriptorSupport());
MBeanFeatureInfo mbeanFeatureInfo = new MBeanFeatureInfo(null, "description", new DescriptorSupport());
test(mbeanFeatureInfo0, mbeanFeatureInfo, "name");
mbeanFeatureInfo = new MBeanFeatureInfo("name", null, new DescriptorSupport());
test(mbeanParameterInfo0, mbeanParameterInfo, "description");
mbeanFeatureInfo = new MBeanFeatureInfo("name", "description", null);
test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanInfo...");
String className = "toto";
String description = "titi";
MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
MBeanInfo minfo0 = new MBeanInfo("toto", description, attrInfos, constrInfos, operaInfos, notifInfos);
MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "class name");
minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "description");
minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
test(minfo0, minfo, "attrInfos");
minfo = new MBeanInfo(className, description, attrInfos, null, operaInfos, notifInfos);
test(minfo0, minfo, "constrInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
test(minfo0, minfo, "operaInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
test(minfo0, minfo, "notifInfos");
if (failed > 0) {
throw new RuntimeException("Test failed: " + failed);
} else {
System.out.println("---Test: PASSED");
}
}
use of javax.management.MBeanConstructorInfo in project jdk8u_jdk by JetBrains.
the class MBeanInfoHashCodeNPETest method main.
public static void main(String[] args) throws Exception {
System.out.println("---MBeanInfoHashCodeNPETest-main ...");
// ----
System.out.println("\n---Testing on MBeanAttributeInfo...");
MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
test(mbeanAttributeInfo, "class name");
mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
test(mbeanAttributeInfo, "type");
mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
test(mbeanAttributeInfo, "description");
// ----
System.out.println("\n---Testing on MBeanConstructorInfo...");
MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo, "name");
mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
test(mbeanConstructorInfo, "description");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
test(mbeanConstructorInfo, "MBeanParameterInfo");
mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
test(mbeanConstructorInfo, "descriptor");
// ----
System.out.println("\n---Testing on MBeanOperationInfo...");
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo, "name");
mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo, "description");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
test(mbeanOperationInfo, "MBeanParameterInfo");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, 1, new DescriptorSupport());
test(mbeanOperationInfo, "type");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", -1, new DescriptorSupport());
test(mbeanOperationInfo, "native impact");
mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", 1, null);
test(mbeanOperationInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanParameterInfo...");
MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
test(mbeanParameterInfo, "name");
mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
test(mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
test(mbeanParameterInfo, "description");
mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
test(mbeanParameterInfo, "Descriptor");
// ----
System.out.println("\n---Testing on MBeanInfo...");
String className = "toto";
String description = "titi";
MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo, "class name");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo, "name");
minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
test(minfo, "description");
minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
test(minfo, "attrInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
test(minfo, "operaInfos");
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
test(minfo, "notifInfos");
Thread.sleep(100);
if (failed > 0) {
throw new RuntimeException("Test failed: " + failed);
} else {
System.out.println("---Test: PASSED");
}
}
Aggregations