{
JMXServiceURL temp = createJMXConnectorServerAddress();
JMXServiceURL url1 = new JMXServiceURL(temp.getProtocol(), temp.getHost(), temp.getPort(), "one");
JMXServiceURL url2 = new JMXServiceURL(temp.getProtocol(), temp.getHost(), temp.getPort(), "two");
JMXConnectorServer cntorServer1 = null;
JMXConnectorServer cntorServer2 = null;
try
{
cntorServer1 = JMXConnectorServerFactory.newJMXConnectorServer(url1, getEnvironment(), newMBeanServer());
cntorServer2 = JMXConnectorServerFactory.newJMXConnectorServer(url2, getEnvironment(), newMBeanServer());
cntorServer1.start();
sleep(5000);
cntorServer2.start();
sleep(5000);
// Make sure they work
JMXConnector cntor1 = null;
JMXConnector cntor2 = null;
try
{
cntor1 = JMXConnectorFactory.connect(cntorServer1.getAddress(), getEnvironment());
cntor2 = JMXConnectorFactory.connect(cntorServer2.getAddress(), getEnvironment());
MBeanServerConnection conn1 = cntor1.getMBeanServerConnection();
Set names = conn1.queryNames(null, null);
assertNotNull(names);
assertTrue(names.size() > 0);
MBeanServerConnection conn2 = cntor2.getMBeanServerConnection();
names = conn2.queryNames(null, null);
assertNotNull(names);
assertTrue(names.size() > 0);
cntorServer1.stop();
try
{
conn1.queryNames(null, null);
fail();
}
catch (IOException ignored)
{
}
names = conn2.queryNames(null, null);
assertNotNull(names);
assertTrue(names.size() > 0);
}
catch (Exception x)
{
x.printStackTrace();
throw x;
}
finally
{
if (cntor2 != null) cntor2.close();
}
}
finally
{
if (cntorServer2 != null) cntorServer2.stop();
}
}