use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.
the class PlatformMBeanServerTest method main.
public static void main(String[] argv) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
printMBeans(mbs);
// validate if all standard JVM MBeans are registered
checkStandardMBeans(mbs);
// validate if all platform MBeans are registered
checkPlatformMBeans(mbs);
MBeanServer mbs1 = ManagementFactory.getPlatformMBeanServer();
if (mbs != mbs1) {
throw new RuntimeException("Second call to getPlatformMBeanServer()" + " returns a different MBeanServer.");
}
System.out.println("Test passed.");
}
use of javax.management.MBeanServer in project jdk8u_jdk by JetBrains.
the class LoggingMXBeanTest method main.
public static void main(String[] argv) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
LoggingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(mbs, LogManager.LOGGING_MXBEAN_NAME, LoggingMXBean.class);
// test LoggingMXBean proxy
test = new LoggingMXBeanTest(proxy);
// check if the attributes implemented by PlatformLoggingMXBean
// and LoggingMXBean return the same value
PlatformLoggingMXBean mxbean = ManagementFactory.getPlatformMXBean(mbs, PlatformLoggingMXBean.class);
checkAttributes(proxy, mxbean);
}
use of javax.management.MBeanServer 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.MBeanServer 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.MBeanServer in project jdk8u_jdk by JetBrains.
the class UnregisterMBeanExceptionTest method main.
public static void main(String[] args) throws Exception {
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Register the MBean
//
System.out.println("Create a TestDynamicMBean");
TestDynamicMBean obj = new TestDynamicMBean();
ObjectName n = new ObjectName("d:k=v");
System.out.println("Register a TestDynamicMBean");
mbs.registerMBean(obj, n);
obj.throwException = true;
System.out.println("Unregister a TestDynamicMBean");
try {
mbs.unregisterMBean(n);
} catch (Exception e) {
throw new IllegalArgumentException("Test failed", e);
}
boolean isRegistered = mbs.isRegistered(n);
System.out.println("Is MBean Registered? " + isRegistered);
if (isRegistered) {
throw new IllegalArgumentException("Test failed: the MBean is still registered");
} else {
System.out.println("Test passed");
}
}
Aggregations