use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class FeatureOrderTest method main.
public static void main(String[] args) throws Exception {
// Build the lists of attributes and operations that we would expect
// if they are derived by reflection and preserve the reflection order
List<String> expectedAttributeNames = new ArrayList<String>();
List<String> expectedOperationNames = new ArrayList<String>();
for (Method m : OrderMXBean.class.getMethods()) {
String name = m.getName();
String attrName = null;
if (name.startsWith("get") && !name.equals("get") && m.getParameterTypes().length == 0 && m.getReturnType() != void.class)
attrName = name.substring(3);
else if (name.startsWith("is") && !name.equals("is") && m.getParameterTypes().length == 0 && m.getReturnType() == boolean.class)
attrName = name.substring(2);
else if (name.startsWith("set") && !name.equals("set") && m.getReturnType() == void.class && m.getParameterTypes().length == 1)
attrName = name.substring(3);
if (attrName != null) {
if (!expectedAttributeNames.contains(attrName))
expectedAttributeNames.add(attrName);
} else
expectedOperationNames.add(name);
}
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (boolean mxbean : booleans) {
for (boolean withStandardMBean : booleans) {
String testName = "MXBean: " + mxbean + "; " + "using javax.management.StandardMBean: " + withStandardMBean;
System.out.println("Test case: " + testName);
Object mbean;
if (mxbean) {
if (withStandardMBean) {
mbean = new StandardMBean(new OrderImpl(), OrderMXBean.class, true);
} else
mbean = new OrderImpl();
} else {
if (withStandardMBean)
mbean = new StandardMBean(new Order(), OrderMBean.class);
else
mbean = new Order();
}
ObjectName name = new ObjectName(":mxbean=" + mxbean + "," + "withStandardMBean=" + withStandardMBean);
mbs.registerMBean(mbean, name);
/* Make sure we are testing what we think. */
MBeanInfo mbi = mbs.getMBeanInfo(name);
boolean isWithStandardMBean = mbs.isInstanceOf(name, StandardMBean.class.getName());
System.out.println("classname " + mbi.getClassName());
String mxbeanField = (String) mbi.getDescriptor().getFieldValue("mxbean");
boolean isMXBean = "true".equalsIgnoreCase(mxbeanField);
if (mxbean != isMXBean)
throw new Exception("Test error: MXBean mismatch");
if (withStandardMBean != isWithStandardMBean)
throw new Exception("Test error: StandardMBean mismatch");
// Check that order of attributes and operations matches
MBeanAttributeInfo[] mbais = mbi.getAttributes();
checkEqual(expectedAttributeNames.size(), mbais.length, "number of attributes");
List<String> attributeNames = new ArrayList<String>();
for (MBeanAttributeInfo mbai : mbais) attributeNames.add(mbai.getName());
checkEqual(expectedAttributeNames, attributeNames, "order of attributes");
MBeanOperationInfo[] mbois = mbi.getOperations();
checkEqual(expectedOperationNames.size(), mbois.length, "number of operations");
List<String> operationNames = new ArrayList<String>();
for (MBeanOperationInfo mboi : mbois) operationNames.add(mboi.getName());
checkEqual(expectedOperationNames, operationNames, "order of operations");
System.out.println();
}
}
if (failed)
throw new Exception("TEST FAILED");
System.out.println("TEST PASSED");
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class ImmutableNotificationInfoTest method test.
private static boolean test(Object mbean, boolean expectImmutable) throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("a:b=c");
mbs.registerMBean(mbean, on);
MBeanInfo mbi = mbs.getMBeanInfo(on);
Descriptor d = mbi.getDescriptor();
String immutableValue = (String) d.getFieldValue("immutableInfo");
boolean immutable = ("true".equals(immutableValue));
if (immutable != expectImmutable) {
System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue);
return false;
} else {
System.out.println("OK: " + mbean.getClass().getName());
return true;
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class AnnotationTest method check.
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
MBeanInfo mbi = mbs.getMBeanInfo(on);
// check the MBean itself
check(mbi);
// check attributes
MBeanAttributeInfo[] attrs = mbi.getAttributes();
for (MBeanAttributeInfo attr : attrs) {
check(attr);
if (attr.getName().equals("ReadOnly"))
check("@Full", attr.getDescriptor(), expectedFullDescriptor);
}
// check operations
MBeanOperationInfo[] ops = mbi.getOperations();
for (MBeanOperationInfo op : ops) {
check(op);
check(op.getSignature());
}
MBeanConstructorInfo[] constrs = mbi.getConstructors();
for (MBeanConstructorInfo constr : constrs) {
check(constr);
check(constr.getSignature());
}
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class MXBeanInteropTest1 method doMemoryPoolMXBeanTest.
private final int doMemoryPoolMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0;
System.out.println("---- MemoryPoolMXBean");
try {
ObjectName filterName = new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName memoryPoolName = iter.next();
System.out.println("-------- " + memoryPoolName);
MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryPoolName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
MemoryPoolMXBean memoryPool = null;
memoryPool = JMX.newMXBeanProxy(mbsc, memoryPoolName, MemoryPoolMXBean.class, true);
System.out.println("getCollectionUsage\t\t" + memoryPool.getCollectionUsage());
System.out.println("getMemoryManagerNames\t\t" + Arrays.deepToString(memoryPool.getMemoryManagerNames()));
System.out.println("getName\t\t" + memoryPool.getName());
System.out.println("getPeakUsage\t\t" + memoryPool.getPeakUsage());
System.out.println("getType\t\t" + memoryPool.getType());
System.out.println("getUsage\t\t" + memoryPool.getUsage());
System.out.println("isValid\t\t" + memoryPool.isValid());
boolean supported = memoryPool.isUsageThresholdSupported();
System.out.println("isUsageThresholdSupported\t\t" + supported);
if (supported) {
System.out.println("getUsageThreshold\t\t" + memoryPool.getUsageThreshold());
System.out.println("isUsageThresholdExceeded\t\t" + memoryPool.isUsageThresholdExceeded());
System.out.println("getUsageThresholdCount\t\t" + memoryPool.getUsageThresholdCount());
}
supported = memoryPool.isCollectionUsageThresholdSupported();
System.out.println("isCollectionUsageThresholdSupported\t\t" + supported);
if (supported) {
System.out.println("getCollectionUsageThreshold\t\t" + memoryPool.getCollectionUsageThreshold());
System.out.println("getCollectionUsageThresholdCount\t\t" + memoryPool.getCollectionUsageThresholdCount());
System.out.println("isCollectionUsageThresholdExceeded\t\t" + memoryPool.isCollectionUsageThresholdExceeded());
}
memoryPool.resetPeakUsage();
}
System.out.println("---- OK\n");
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
System.out.println("---- ERROR\n");
}
return errorCount;
}
use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.
the class MXBeanInteropTest1 method doGarbageCollectorMXBeanTest.
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0;
System.out.println("---- GarbageCollectorMXBean");
try {
ObjectName filterName = new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName garbageName = iter.next();
System.out.println("-------- " + garbageName);
MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
GarbageCollectorMXBean garbage = null;
garbage = JMX.newMXBeanProxy(mbsc, garbageName, GarbageCollectorMXBean.class);
System.out.println("getCollectionCount\t\t" + garbage.getCollectionCount());
System.out.println("getCollectionTime\t\t" + garbage.getCollectionTime());
}
System.out.println("---- OK\n");
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
System.out.println("---- ERROR\n");
}
return errorCount;
}
Aggregations