use of javax.management.remote.JMXServiceURL in project jdk8u_jdk by JetBrains.
the class DaemonRMIExporterTest method main.
public static void main(String[] args) throws Exception {
Set<Thread> initialNonDaemonThreads = getNonDaemonThreads();
JMXServiceURL addr = new JMXServiceURL("rmi", null, 0);
System.out.println("DaemonRMIExporterTest: Creating a RMIConnectorServer on " + addr);
Map<String, ?> env = Collections.singletonMap("jmx.remote.x.daemon", "true");
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(addr, env, MBeanServerFactory.createMBeanServer());
server.start();
System.out.println("DaemonRMIExporterTest: Started the server on " + server.getAddress());
System.out.println("DaemonRMIExporterTest: Connecting a client to the server ...");
final JMXConnector conn = JMXConnectorFactory.connect(server.getAddress());
conn.getMBeanServerConnection().getDefaultDomain();
System.out.println("DaemonRMIExporterTest: Closing the client ...");
conn.close();
System.out.println("DaemonRMIExporterTest No more user code to execute, the VM should " + "exit normally, otherwise will be blocked forever if the bug is not fixed.");
long deadline = System.currentTimeMillis() + 10000;
ok: {
while (System.currentTimeMillis() < deadline) {
Set<Thread> nonDaemonThreads = getNonDaemonThreads();
nonDaemonThreads.removeAll(initialNonDaemonThreads);
if (nonDaemonThreads.isEmpty())
break ok;
System.out.println("Non-daemon threads: " + nonDaemonThreads);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
throw new Exception("TEST FAILED: non-daemon threads remain");
}
System.out.println("TEST PASSED");
}
use of javax.management.remote.JMXServiceURL in project jdk8u_jdk by JetBrains.
the class GetConnectionTest method test.
private static boolean test(String proto) throws Exception {
JMXConnector client;
try {
JMXServiceURL url = new JMXServiceURL(proto, null, 0);
client = JMXConnectorFactory.newJMXConnector(url, null);
} catch (MalformedURLException e) {
System.out.println("Protocol " + proto + " not supported, ignoring");
return true;
}
// IOException is expected
try {
MBeanServerConnection connection = client.getMBeanServerConnection();
System.out.println("FAILED: Expected IOException is not thrown.");
return false;
} catch (IOException e) {
System.out.println("PASSED");
return true;
}
}
use of javax.management.remote.JMXServiceURL in project jdk8u_jdk by JetBrains.
the class RMIExitTest method test.
private static void test() {
try {
JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer server;
JMXServiceURL addr;
JMXConnector client;
MBeanServerConnection mserver;
final ObjectName delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
final NotificationListener dummyListener = new NotificationListener() {
public void handleNotification(Notification n, Object o) {
// do nothing
return;
}
};
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
server.start();
addr = server.getAddress();
client = JMXConnectorFactory.newJMXConnector(addr, null);
client.connect(null);
mserver = client.getMBeanServerConnection();
String s1 = "1";
String s2 = "2";
String s3 = "3";
mserver.addNotificationListener(delegateName, dummyListener, null, s1);
mserver.addNotificationListener(delegateName, dummyListener, null, s2);
mserver.addNotificationListener(delegateName, dummyListener, null, s3);
mserver.removeNotificationListener(delegateName, dummyListener, null, s3);
mserver.removeNotificationListener(delegateName, dummyListener, null, s2);
mserver.removeNotificationListener(delegateName, dummyListener, null, s1);
client.close();
server.stop();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
System.exit(1);
}
}
use of javax.management.remote.JMXServiceURL in project jdk8u_jdk by JetBrains.
the class URLTest method main.
public static void main(String[] args) throws Exception {
System.out.println("Testing that JMXServiceURL accepts the same " + "hosts as java.net.URI");
System.out.println("(Except that it allows empty host names and " + "forbids a trailing \".\")");
System.out.println();
int failures = 0;
for (int pass = 1; pass <= 2; pass++) {
final boolean accept = (pass == 1);
System.out.println(" Hosts that should " + (accept ? "" : "not ") + "work");
String[] hosts = accept ? good : bad;
for (int i = 0; i < hosts.length; i++) {
final String host = hosts[i];
System.out.print(" " + host + ": ");
boolean jmxAccept = true;
try {
new JMXServiceURL("rmi", hosts[i], 0);
} catch (MalformedURLException e) {
jmxAccept = false;
}
boolean uriAccept;
try {
final URI uri = new URI("http://" + host + "/");
uriAccept = (uri.getHost() != null);
} catch (URISyntaxException e) {
uriAccept = false;
}
final int len = host.length();
if (accept != uriAccept && len != 0 && !(len > 1 && host.charAt(len - 1) == '.' && host.charAt(len - 2) != '.')) {
// JMXServiceURL allows empty host name; also
// java.net.URI allows trailing dot in hostname,
// following RFC 2396, but JMXServiceURL doesn't,
// following RFC 2609
System.out.println("TEST BUG: URI accept=" + uriAccept);
failures++;
} else {
if (jmxAccept == accept)
System.out.println("OK");
else {
System.out.println("FAILED");
failures++;
}
}
}
System.out.println();
}
if (failures == 0)
System.out.println("Test passed");
else {
System.out.println("TEST FAILURES: " + failures);
System.exit(1);
}
}
use of javax.management.remote.JMXServiceURL in project jdk8u_jdk by JetBrains.
the class RMIConnectorLogAttributesTest method connectToServer.
private JMXConnector connectToServer(JMXConnectorServer server) throws IOException, MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException {
JMXServiceURL url = server.getAddress();
Map<String, Object> env = new HashMap<String, Object>();
JMXConnector connector = JMXConnectorFactory.connect(url, env);
System.out.println("DEBUG: Client connected to RMI at: " + url);
return connector;
}
Aggregations