use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class MXBeanInteropTest2 method run.
public void run(Map<String, Object> args) {
System.out.println("MXBeanInteropTest2::run: Start");
int errorCount = 0;
try {
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// Prints all MBeans whatever the domain is.
printMBeans(mbsc);
// Call test body
errorCount += doBasicMXBeanTest(mbsc);
// Terminate the JMX Client
cc.close();
} catch (Exception e) {
Utils.printThrowable(e, true);
throw new RuntimeException(e);
}
if (errorCount == 0) {
System.out.println("MXBeanInteropTest2::run: Done without any error");
} else {
System.out.println("MXBeanInteropTest2::run: Done with " + errorCount + " error(s)");
throw new RuntimeException("errorCount = " + errorCount);
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class GenericArrayTypeTest method main.
public static void main(String[] args) throws Exception {
int error = 0;
JMXConnector cc = null;
JMXConnectorServer cs = null;
try {
// Instantiate the MBean server
//
echo("\n>>> Create the MBean server");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Get default domain
//
echo("\n>>> Get the MBean server's default domain");
String domain = mbs.getDefaultDomain();
echo("\tDefault Domain = " + domain);
// Register TestMXBean
//
echo("\n>>> Register TestMXBean");
ObjectName name = ObjectName.getInstance(domain + ":type=" + TestMXBean.class);
mbs.createMBean(Test.class.getName(), name);
// Create an RMI connector server
//
echo("\n>>> Create an RMI connector server");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
// Start the RMI connector server
//
echo("\n>>> Start the RMI connector server");
cs.start();
// Create an RMI connector client
//
echo("\n>>> Create an RMI connector client");
cc = JMXConnectorFactory.connect(cs.getAddress(), null);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// Create TestMXBean proxy
//
echo("\n>>> Create the TestMXBean proxy");
TestMXBean test = JMX.newMXBeanProxy(mbsc, name, TestMXBean.class);
// Play with proxy getters and setters
//
echo("\n>>> Play with proxy getters and setters");
String[] t1 = new String[] { "t1" };
MonitorInfo[] t2 = new MonitorInfo[] { new MonitorInfo("dummy", 0, 0, new StackTraceElement("dummy", "dummy", "dummy", 0)) };
Map<String, String[]> t3 = new HashMap<String, String[]>();
t3.put("key", t1);
Map<String, MonitorInfo[]> t4 = new HashMap<String, MonitorInfo[]>();
t4.put("key", t2);
Set<String[]> t5 = new HashSet<String[]>();
t5.add(t1);
Set<MonitorInfo[]> t6 = new HashSet<MonitorInfo[]>();
t6.add(t2);
List<String[]> t7 = new ArrayList<String[]>();
t7.add(t1);
List<MonitorInfo[]> t8 = new ArrayList<MonitorInfo[]>();
t8.add(t2);
Set<List<String[]>> t9 = new HashSet<List<String[]>>();
t9.add(t7);
Set<List<MonitorInfo[]>> t10 = new HashSet<List<MonitorInfo[]>>();
t10.add(t8);
Map<String, Set<List<String[]>>> t11 = new HashMap<String, Set<List<String[]>>>();
t11.put("key", t9);
Map<String, Set<List<MonitorInfo[]>>> t12 = new HashMap<String, Set<List<MonitorInfo[]>>>();
t12.put("key", t10);
test.setT1(t1);
test.setT2(t2);
test.setT3(t3);
test.setT4(t4);
test.setT5(t5);
test.setT6(t6);
test.setT7(t7);
test.setT8(t8);
test.setT9(t9);
test.setT10(t10);
test.setT11(t11);
test.setT12(t12);
String r;
String e1 = "t1";
String e2 = "dummy";
echo("\tT1 = " + test.getT1());
r = ((String[]) test.getT1())[0];
echo("\tR1 = " + r);
if (!e1.equals(r))
error++;
echo("\tT2 = " + test.getT2());
r = ((MonitorInfo[]) test.getT2())[0].getClassName();
echo("\tR2 = " + r);
if (!e2.equals(r))
error++;
echo("\tT3 = " + test.getT3());
r = ((String[]) ((Map<String, String[]>) test.getT3()).get("key"))[0];
echo("\tR3 = " + r);
if (!e1.equals(r))
error++;
echo("\tT4 = " + test.getT4());
r = ((MonitorInfo[]) ((Map<String, MonitorInfo[]>) test.getT4()).get("key"))[0].getClassName();
echo("\tR4 = " + r);
if (!e2.equals(r))
error++;
echo("\tT5 = " + test.getT5());
r = ((String[]) ((Set<String[]>) test.getT5()).iterator().next())[0];
echo("\tR5 = " + r);
if (!e1.equals(r))
error++;
echo("\tT6 = " + test.getT6());
r = ((MonitorInfo[]) ((Set<MonitorInfo[]>) test.getT6()).iterator().next())[0].getClassName();
echo("\tR6 = " + r);
if (!e2.equals(r))
error++;
echo("\tT7 = " + test.getT7());
r = ((String[]) ((List<String[]>) test.getT7()).get(0))[0];
echo("\tR7 = " + r);
if (!e1.equals(r))
error++;
echo("\tT8 = " + test.getT8());
r = ((MonitorInfo[]) ((List<MonitorInfo[]>) test.getT8()).get(0))[0].getClassName();
echo("\tR8 = " + r);
if (!e2.equals(r))
error++;
echo("\tT9 = " + test.getT9());
r = ((String[]) ((List<String[]>) ((Set<List<String[]>>) test.getT9()).iterator().next()).get(0))[0];
echo("\tR9 = " + r);
if (!e1.equals(r))
error++;
echo("\tT10 = " + test.getT10());
r = ((MonitorInfo[]) ((List<MonitorInfo[]>) ((Set<List<MonitorInfo[]>>) test.getT10()).iterator().next()).get(0))[0].getClassName();
echo("\tR10 = " + r);
if (!e2.equals(r))
error++;
echo("\tT11 = " + test.getT11());
r = ((String[]) ((List<String[]>) ((Set<List<String[]>>) ((Map<String, Set<List<String[]>>>) test.getT11()).get("key")).iterator().next()).get(0))[0];
echo("\tR11 = " + r);
if (!e1.equals(r))
error++;
echo("\tT12 = " + test.getT12());
r = ((MonitorInfo[]) ((List<MonitorInfo[]>) ((Set<List<MonitorInfo[]>>) ((Map<String, Set<List<MonitorInfo[]>>>) test.getT12()).get("key")).iterator().next()).get(0))[0].getClassName();
echo("\tR12 = " + r);
if (!e2.equals(r))
error++;
} catch (Exception e) {
e.printStackTrace(System.out);
error++;
} finally {
// Close client
//
echo("\n>>> Close the RMI connector client");
if (cc != null)
cc.close();
// Stop server
//
echo("\n>>> Stop the RMI connector server");
if (cs != null)
cs.stop();
echo("\n>>> Bye! Bye!");
}
if (error > 0) {
echo("\nTest failed! " + error + " errors.\n");
throw new IllegalArgumentException("Test failed");
} else {
echo("\nTest passed!\n");
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class MXBeanInteropTest1 method run.
public void run(Map<String, Object> args) {
System.out.println("MXBeanInteropTest1::run: Start");
int errorCount = 0;
try {
// JMX MbeanServer used inside single VM as if remote.
// MBeanServer mbs = MBeanServerFactory.newMBeanServer();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// Print out registered java.lang.management MXBeans found
// in the remote jvm.
printMBeans(mbsc);
// For each possible kind of JDK 5 defined MXBean, we retrieve its
// MBeanInfo and print it and we call all getters and print
// their output.
errorCount += doClassLoadingMXBeanTest(mbsc);
errorCount += doMemoryMXBeanTest(mbsc);
errorCount += doThreadMXBeanTest(mbsc);
errorCount += doRuntimeMXBeanTest(mbsc);
errorCount += doOperatingSystemMXBeanTest(mbsc);
errorCount += doCompilationMXBeanTest(mbsc);
errorCount += doGarbageCollectorMXBeanTest(mbsc);
errorCount += doMemoryManagerMXBeanTest(mbsc);
errorCount += doMemoryPoolMXBeanTest(mbsc);
// Terminate the JMX Client
cc.close();
} catch (Exception e) {
Utils.printThrowable(e, true);
throw new RuntimeException(e);
}
if (errorCount == 0) {
System.out.println("MXBeanInteropTest1::run: Done without any error");
} else {
System.out.println("MXBeanInteropTest1::run: Done with " + errorCount + " error(s)");
throw new RuntimeException("errorCount = " + errorCount);
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class RMIExporterTest method main.
public static void main(String[] args) {
try {
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Initialize environment map to be passed to the connector server
//
System.out.println("Initialize environment map");
HashMap env = new HashMap();
CustomRMIExporter exporter = new CustomRMIExporter();
env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);
// Create an RMI connector server
//
System.out.println("Create an RMI connector server");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
cs.start();
// Create an RMI connector client
//
System.out.println("Create an RMI connector client");
JMXConnector cc = JMXConnectorFactory.connect(cs.getAddress(), null);
// Close RMI connector client
//
System.out.println("Close the RMI connector client");
cc.close();
// Stop RMI connector server
//
System.out.println("Stop the RMI connector server");
cs.stop();
// Check if remote objects were exported/unexported successfully
//
int errorCount = 0;
if (exporter.rmiServerExported) {
System.out.println("RMIServer exported OK!");
} else {
System.out.println("RMIServer exported KO!");
errorCount++;
}
if (exporter.rmiServerUnexported) {
System.out.println("RMIServer unexported OK!");
} else {
System.out.println("RMIServer unexported KO!");
errorCount++;
}
if (exporter.rmiConnectionExported) {
System.out.println("RMIConnection exported OK!");
} else {
System.out.println("RMIConnection exported KO!");
errorCount++;
}
if (exporter.rmiConnectionUnexported) {
System.out.println("RMIConnection unexported OK!");
} else {
System.out.println("RMIConnection unexported KO!");
errorCount++;
}
System.out.println("Bye! Bye!");
if (errorCount > 0) {
System.out.println("RMIExporterTest FAILED!");
System.exit(1);
} else {
System.out.println("RMIExporterTest PASSED!");
}
} catch (Exception e) {
System.out.println("Unexpected exception caught = " + e);
e.printStackTrace();
System.exit(1);
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class MissingClassTest method test.
private static boolean test(String proto) throws Exception {
System.out.println("Testing for proto " + proto);
boolean ok = true;
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
mbs.createMBean(Test.class.getName(), on);
JMXConnectorServer cs;
JMXServiceURL url = new JMXServiceURL(proto, null, 0);
Map<String, Object> serverMap = new HashMap<>();
serverMap.put(JMXConnectorServerFactory.DEFAULT_CLASS_LOADER, serverLoader);
// make sure no auto-close at server side
serverMap.put("jmx.remote.x.server.connection.timeout", "888888888");
try {
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, serverMap, mbs);
} catch (MalformedURLException e) {
System.out.println("System does not recognize URL: " + url + "; ignoring");
return true;
}
cs.start();
JMXServiceURL addr = cs.getAddress();
Map<String, Object> clientMap = new HashMap<>();
clientMap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, clientLoader);
System.out.println("Connecting for client-unknown test");
JMXConnector client = JMXConnectorFactory.connect(addr, clientMap);
// add a listener to verify no failed notif
CNListener cnListener = new CNListener();
client.addConnectionNotificationListener(cnListener, null, null);
MBeanServerConnection mbsc = client.getMBeanServerConnection();
System.out.println("Getting attribute with class unknown to client");
try {
Object result = mbsc.getAttribute(on, "ClientUnknown");
System.out.println("TEST FAILS: getAttribute for class " + "unknown to client should fail, returned: " + result);
ok = false;
} catch (IOException e) {
Throwable cause = e.getCause();
if (// see CR 4935098
isInstance(cause, "org.omg.CORBA.MARSHAL"))
cause = cause.getCause();
if (cause instanceof ClassNotFoundException) {
System.out.println("Success: got an IOException wrapping " + "a ClassNotFoundException");
} else {
System.out.println("TEST FAILS: Caught IOException (" + e + ") but cause should be " + "ClassNotFoundException: " + cause);
ok = false;
}
}
System.out.println("Doing queryNames to ensure connection alive");
Set<ObjectName> names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names);
System.out.println("Provoke exception of unknown class");
try {
mbsc.invoke(on, "throwClientUnknown", NO_OBJECTS, NO_STRINGS);
System.out.println("TEST FAILS: did not get exception");
ok = false;
} catch (IOException e) {
Throwable wrapped = e.getCause();
if (// see CR 4935098
isInstance(wrapped, "org.omg.CORBA.MARSHAL"))
wrapped = wrapped.getCause();
if (wrapped instanceof ClassNotFoundException) {
System.out.println("Success: got an IOException wrapping " + "a ClassNotFoundException: " + wrapped);
} else {
System.out.println("TEST FAILS: Got IOException but cause " + "should be ClassNotFoundException: ");
if (wrapped == null)
System.out.println("(null)");
else
wrapped.printStackTrace(System.out);
ok = false;
}
} catch (Exception e) {
System.out.println("TEST FAILS: Got wrong exception: " + "should be IOException with cause " + "ClassNotFoundException:");
e.printStackTrace(System.out);
ok = false;
}
System.out.println("Doing queryNames to ensure connection alive");
names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names);
ok &= notifyTest(client, mbsc);
System.out.println("Doing queryNames to ensure connection alive");
names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names);
for (int i = 0; i < 2; i++) {
// else invoke
boolean setAttribute = (i == 0);
String what = setAttribute ? "setAttribute" : "invoke";
System.out.println("Trying " + what + " with class unknown to server");
try {
if (setAttribute) {
mbsc.setAttribute(on, new Attribute("ServerUnknown", serverUnknown));
} else {
mbsc.invoke(on, "useServerUnknown", new Object[] { serverUnknown }, new String[] { "java.lang.Object" });
}
System.out.println("TEST FAILS: " + what + " with " + "class unknown to server should fail " + "but did not");
ok = false;
} catch (IOException e) {
Throwable cause = e.getCause();
if (// see CR 4935098
isInstance(cause, "org.omg.CORBA.MARSHAL"))
cause = cause.getCause();
if (cause instanceof ClassNotFoundException) {
System.out.println("Success: got an IOException " + "wrapping a ClassNotFoundException");
} else {
System.out.println("TEST FAILS: Caught IOException (" + e + ") but cause should be " + "ClassNotFoundException: " + cause);
// XXX
e.printStackTrace(System.out);
ok = false;
}
}
}
System.out.println("Doing queryNames to ensure connection alive");
names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names);
System.out.println("Trying to get unserializable attribute");
try {
mbsc.getAttribute(on, "Unserializable");
System.out.println("TEST FAILS: get unserializable worked " + "but should not");
ok = false;
} catch (IOException e) {
System.out.println("Success: got an IOException: " + e + " (cause: " + e.getCause() + ")");
}
System.out.println("Doing queryNames to ensure connection alive");
names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names);
System.out.println("Trying to set unserializable attribute");
try {
Attribute attr = new Attribute("Unserializable", unserializableObject);
mbsc.setAttribute(on, attr);
System.out.println("TEST FAILS: set unserializable worked " + "but should not");
ok = false;
} catch (IOException e) {
System.out.println("Success: got an IOException: " + e + " (cause: " + e.getCause() + ")");
}
System.out.println("Doing queryNames to ensure connection alive");
names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names);
System.out.println("Trying to throw unserializable exception");
try {
mbsc.invoke(on, "throwUnserializable", NO_OBJECTS, NO_STRINGS);
System.out.println("TEST FAILS: throw unserializable worked " + "but should not");
ok = false;
} catch (IOException e) {
System.out.println("Success: got an IOException: " + e + " (cause: " + e.getCause() + ")");
}
client.removeConnectionNotificationListener(cnListener);
ok = ok && !cnListener.failed;
client.close();
cs.stop();
if (ok)
System.out.println("Test passed for protocol " + proto);
System.out.println();
return ok;
}
Aggregations