use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class MultiThreadDeadLockTest method main.
public static void main(String[] args) throws Exception {
print("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
print("Initialize environment map");
HashMap env = new HashMap();
print("Specify a client socket factory to control socket creation.");
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientFactory);
print("Specify a server idle timeout to make a server close an idle connection.");
env.put("jmx.remote.x.server.connection.timeout", serverTimeout);
print("Disable client heartbeat.");
env.put("jmx.remote.x.client.connection.check.period", 0);
env.put("jmx.remote.x.notification.fetch.timeout", serverTimeout);
print("Create an RMI server");
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
server.start();
url = server.getAddress();
print("Create jmx client on " + url);
// allow to create client socket
StateMachine.setState(CREATE_SOCKET);
client = JMXConnectorFactory.connect(url, env);
Thread.sleep(100);
totoName = new ObjectName("default:name=toto");
mbs.registerMBean(toto, totoName);
print("Register the mbean: " + totoName);
print("Add listener to toto MBean");
client.getMBeanServerConnection().addNotificationListener(totoName, myListener, null, null);
Thread.sleep(10);
print("send notif, listener will block the fetcher");
toto.sendNotif();
Thread.sleep(100);
StateMachine.setState(NO_OP);
print("Sleep 3 times of server idle timeout: " + serverTimeout + ", the sever should close the idle connection.");
Thread.sleep(serverTimeout * 3);
print("start the user thread to call mbean method, it will get IOexception" + " and start the reconnection, the socket factory will block the" + " socket creation.");
UserThread ut = new UserThread();
ut.start();
Thread.sleep(10);
print("Free the listener, the fetcher will get IO and makes " + "a deadlock if the bug is not fixed.");
StateMachine.setState(FREE_LISTENER);
Thread.sleep(100);
print("Allow to create new socket for the reconnection");
StateMachine.setState(CREATE_SOCKET);
print("Check whether the user thread gets free to call the mbean.");
if (!ut.waitDone(5000)) {
throw new RuntimeException("Possible deadlock!");
}
print("Remove the listener.");
client.getMBeanServerConnection().removeNotificationListener(totoName, myListener, null, null);
Thread.sleep(serverTimeout * 3);
print("\nWell passed, bye!");
client.close();
Thread.sleep(10);
server.stop();
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class IIOPURLTest method main.
public static void main(String[] args) throws Exception {
JMXServiceURL inputAddr = new JMXServiceURL("service:jmx:iiop://");
JMXConnectorServer s;
try {
s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
} catch (java.net.MalformedURLException x) {
try {
Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
} catch (ClassNotFoundException expected) {
}
System.out.println("IIOP protocol not supported, test skipped");
return;
}
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
mbs.registerMBean(s, new ObjectName("a:b=c"));
s.start();
JMXServiceURL outputAddr = s.getAddress();
if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
throw new RuntimeException("URL path should start with \"/ior/IOR:\": " + outputAddr);
}
System.out.println("IIOP URL path looks OK: " + outputAddr);
JMXConnector c = JMXConnectorFactory.connect(outputAddr);
System.out.println("Successfully got default domain: " + c.getMBeanServerConnection().getDefaultDomain());
c.close();
s.stop();
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class IdleTimeoutTest method getIdleTimeout.
private static long getIdleTimeout(MBeanServer mbs, JMXServiceURL url) throws Exception {
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
server.start();
try {
url = server.getAddress();
// Force initialization (class loading, JIT, etc...)
//
JMXConnector client = JMXConnectorFactory.connect(url);
try {
String connId = client.getConnectionId();
MBeanServerConnection conn = client.getMBeanServerConnection();
} finally {
client.close();
}
// Do the time measurement
//
final long firstTime = System.currentTimeMillis();
final long endtime;
client = JMXConnectorFactory.connect(url);
try {
String connId = client.getConnectionId();
MBeanServerConnection conn = client.getMBeanServerConnection();
endtime = System.currentTimeMillis();
} finally {
client.close();
}
// multipled by 10 for a slow machine, plus 1500 for a fast one.
return 10 * (endtime - firstTime) + 1500;
} finally {
server.stop();
}
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class IdleTimeoutTest method test.
private static boolean test(String proto, int opCount, int liCount) throws Exception {
System.out.println("Idle timeout test for protocol " + proto);
ObjectName delegateName = ObjectName.getInstance("JMImplementation:" + "type=MBeanServerDelegate");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto + "://");
final long timeout = getIdleTimeout(mbs, url);
System.out.println("Timeout for " + proto + " is: " + timeout + " ms");
Map idleMap = new HashMap();
idleMap.put(EnvHelp.SERVER_CONNECTION_TIMEOUT, new Long(timeout));
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, idleMap, mbs);
final int[] listenerCount = new int[1];
final NotificationListener[] countListeners = new NotificationListener[liCount];
int i;
for (i = 0; i < countListeners.length; i++) {
countListeners[i] = new NotificationCounter(listenerCount, "Listener" + i);
}
server.start();
try {
url = server.getAddress();
final long firstTime = System.currentTimeMillis();
JMXConnector client = JMXConnectorFactory.connect(url);
long elapsed, startIdle = 0;
try {
String connId = client.getConnectionId();
MBeanServerConnection conn = client.getMBeanServerConnection();
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("Idle Time: " + elapsed + "ms");
for (i = 0; i < countListeners.length; i++) {
System.out.println("add " + countListeners[i] + ": starting at " + elapsed + "ms");
conn.addNotificationListener(delegateName, countListeners[i], null, null);
}
System.out.println("connId=" + connId);
for (i = 0; i < opCount; i++) {
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("Operation[" + (i + 1) + "]: starting at " + elapsed + "ms");
final String name = "d:type=mlet,instance=" + i;
mbs.createMBean("javax.management.loading.MLet", new ObjectName(name));
if (i == (opCount - 1))
startIdle = System.currentTimeMillis();
Thread.sleep(2);
}
// Wait for notifs to arrive before doing removeNListener
long startTime = System.currentTimeMillis();
long deadline = startTime + 10000;
System.out.println("Waiting for notifs: starting at " + (startTime - firstTime) + "ms");
final int expectedCount = opCount * countListeners.length;
while (System.currentTimeMillis() < deadline) {
synchronized (listenerCount) {
if (listenerCount[0] >= expectedCount)
break;
listenerCount.wait();
}
}
long elapsedWait = System.currentTimeMillis() - startTime;
System.out.println("Waited " + elapsedWait + "ms for notifs to arrive");
if (listenerCount[0] != expectedCount) {
System.out.println("Did not get expected " + expectedCount + " notifications: " + listenerCount[0]);
return false;
}
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("idle time since last operation: " + (elapsed + firstTime - startIdle) + "ms");
System.out.println("Requesting conn id at: " + elapsed + "ms");
final String cid = client.getConnectionId();
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("Got conn id <" + cid + "> at: " + elapsed + "ms");
if (!connId.equals(cid)) {
System.out.println("Client id changed: <" + connId + "> -> <" + cid + ">");
return false;
}
List ids = Arrays.asList(server.getConnectionIds());
if (!ids.contains(connId)) {
System.out.println("Server ids don't contain our id: " + ids + " - " + connId);
return false;
}
for (i = 0; i < countListeners.length; i++) {
System.out.println("Removing notification listener: " + countListeners[i]);
conn.removeNotificationListener(delegateName, countListeners[i]);
}
System.out.println("Waiting for id list to drop ours");
// pass or timed out by test harness - see 8025204
do {
Thread.sleep(100);
ids = Arrays.asList(server.getConnectionIds());
} while (ids.contains(connId));
conn.getDefaultDomain();
if (connId.equals(client.getConnectionId())) {
System.out.println("Client id did not change: <" + connId + ">: idle timeout did not happen?");
return false;
} else {
System.out.println("Client id changed as expected: <" + connId + "> -> <" + client.getConnectionId() + ">");
}
} finally {
client.close();
System.out.println("Connection id list on server after " + "client close: " + Arrays.asList(server.getConnectionIds()));
}
} finally {
server.stop();
}
System.out.println("*** ------------------------------------------");
System.out.println("*** Test passed for " + proto);
System.out.println("*** ------------------------------------------");
return true;
}
use of javax.management.remote.JMXConnectorServer 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");
}
Aggregations