下面列出了javax.management.MBeanServerConnection#getMBeanCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void connect_and_server_restarts_after_we_detect_connection_death() throws Exception {
jmx_server.start();
try (JmxClient jmx_client = new JmxClient(jmx_server.url)) {
jmx_client.getConnection(threadpool).get().get().getMBeanServerConnection().getMBeanCount(); // Force connection to come up.
/* Restart JMX server. */
jmx_server.stop();
try {
/* Attempt to get data from JMX server while it is down. */
jmx_client.getConnection(threadpool).get();
} catch (ExecutionException ex) {
/* expected */
}
/* Complete restart of JMX server. */
jmx_server.start();
MBeanServerConnection connection = jmx_client.getConnection(threadpool).get().get().getMBeanServerConnection();
assertNotNull(connection);
connection.getMBeanCount();
}
}
/**
* Get the connection, but don't bother with the recovery protocol if the
* connection is lost.
*
* @return An optional with a connection, or empty optional indicating there
* is no connection.
*/
public synchronized Optional<MBeanServerConnection> getOptionalConnection() {
if (conn_ != null && conn_.isCompletedExceptionally()) conn_ = null;
if (conn_ != null && conn_.isDone() && !conn_.isCompletedExceptionally()) {
try {
MBeanServerConnection result = conn_.get().get().getMBeanServerConnection();
result.getMBeanCount();
return Optional.of(result);
} catch (Exception ex) {
conn_ = null; // Connection gone bad.
}
}
return Optional.empty();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote+http://localhost:8080";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat( count ).isGreaterThan( 1 );
jmxConnector.close();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote+http://localhost:9990";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat(count).isGreaterThan(1);
jmxConnector.close();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote+http://localhost:9990";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat(count).isGreaterThan(1);
jmxConnector.close();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote://localhost:4447";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat(count).isGreaterThan(1);
jmxConnector.close();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote://localhost:4447";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat(count).isGreaterThan(1);
jmxConnector.close();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote+http://localhost:8080";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat( count ).isGreaterThan( 1 );
jmxConnector.close();
}
@Test
@RunAsClient
public void testRemoteConnection() throws Exception {
String urlString = "service:jmx:remote+http://localhost:8080";
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
int count = connection.getMBeanCount();
assertThat(count).isGreaterThan(1);
jmxConnector.close();
}
@Test
public void testExposedMBeans() throws Exception {
MBeanServerConnection connection = setupAndGetConnection(new BaseAdditionalInitialization(ProcessType.STANDALONE_SERVER));
int count = connection.getMBeanCount();
checkQueryMBeans(connection, count, null);
checkQueryMBeans(connection, count, new ObjectName("*:*"));
Set<ObjectInstance> filteredInstances = connection.queryMBeans(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"),
null);
Set<ObjectName> filteredNames = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"), null);
Assert.assertEquals(2, filteredInstances.size());
Assert.assertEquals(2, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, LEGACY_SOCKET_BINDING_GROUP_NAME, LEGACY_SERVER_SOCKET_BINDING_NAME);
filteredInstances = connection.queryMBeans(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"),
null);
filteredNames = connection.queryNames(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"), null);
Assert.assertEquals(2, filteredInstances.size());
Assert.assertEquals(2, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, EXPR_SOCKET_BINDING_GROUP_NAME, EXPR_SERVER_SOCKET_BINDING_NAME);
// WFCORE-1716 Test with a property list pattern where the non-wildcard keys are for items later in the address
filteredInstances = connection.queryMBeans(createObjectName(LEGACY_DOMAIN + ":socket-binding=*,*"),
null);
filteredNames = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":socket-binding=*,*"), null);
Assert.assertEquals(1, filteredInstances.size());
Assert.assertEquals(1, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, LEGACY_SERVER_SOCKET_BINDING_NAME);
// WFCORE-1257 -- Test with QueryExp
// First a numeric query (port) = (12345)
filteredInstances = connection.queryMBeans(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"),
PORT_QUERY_EXP);
filteredNames = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"), PORT_QUERY_EXP);
Assert.assertEquals(1, filteredInstances.size());
Assert.assertEquals(1, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, LEGACY_SERVER_SOCKET_BINDING_NAME);
// Doesn't match on jboss.as.expr as the value is a string
filteredInstances = connection.queryMBeans(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"),
PORT_QUERY_EXP);
filteredNames = connection.queryNames(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"), PORT_QUERY_EXP);
Assert.assertEquals(0, filteredInstances.size());
Assert.assertEquals(0, filteredNames.size());
// Next a port string query (port) = ("12345")
// Doesn't match on jboss.as as the value is an int
filteredInstances = connection.queryMBeans(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"),
PORT_STRING_QUERY_EXP);
filteredNames = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"), PORT_STRING_QUERY_EXP);
Assert.assertEquals(0, filteredInstances.size());
Assert.assertEquals(0, filteredNames.size());
// Does match on jboss.as.expr as the value is a string
filteredInstances = connection.queryMBeans(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"),
PORT_STRING_QUERY_EXP);
filteredNames = connection.queryNames(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"), PORT_STRING_QUERY_EXP);
Assert.assertEquals(1, filteredInstances.size());
Assert.assertEquals(1, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, EXPR_SERVER_SOCKET_BINDING_NAME);
// Next a straight string query (defaultInterface) = ("test-interface")
// Note this also checks a bit on the default-interface -> defaultInterface camel case handling
filteredInstances = connection.queryMBeans(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"),
DEFAULT_INTERFACE_QUERY_EXP);
filteredNames = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":socket-binding-group=*,*"),
DEFAULT_INTERFACE_QUERY_EXP);
Assert.assertEquals(1, filteredInstances.size());
Assert.assertEquals(1, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, LEGACY_SOCKET_BINDING_GROUP_NAME);
filteredInstances = connection.queryMBeans(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"),
DEFAULT_INTERFACE_QUERY_EXP);
filteredNames = connection.queryNames(createObjectName(EXPR_DOMAIN + ":socket-binding-group=*,*"), DEFAULT_INTERFACE_QUERY_EXP);
Assert.assertEquals(1, filteredInstances.size());
Assert.assertEquals(1, filteredNames.size());
checkSameMBeans(filteredInstances, filteredNames);
assertContainsNames(filteredNames, EXPR_SOCKET_BINDING_GROUP_NAME);
}
@Test
public void testInstallIntoController() throws Exception {
//Parse the subsystem xml and install into the controller
String subsystemXml =
"<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\">" +
"<remoting-connector/>" +
"</subsystem>";
KernelServices services = createKernelServicesBuilder(new BaseAdditionalInitialization())
.setSubsystemXml(subsystemXml)
.build();
Assert.assertTrue(services.isSuccessfulBoot());
//Read the whole model and make sure it looks as expected
ModelNode model = services.readWholeModel();
Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(JMXExtension.SUBSYSTEM_NAME));
//Make sure that we can connect to the MBean server
String urlString = System.getProperty("jmx.service.url",
"service:jmx:remoting-jmx://localhost:" + JMX_PORT);
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector connector = null;
try {
MBeanServerConnection connection = null;
long end = System.currentTimeMillis() + 10000;
do {
try {
connector = JMXConnectorFactory.connect(serviceURL, null);
connection = connector.getMBeanServerConnection();
} catch (Exception e) {
e.printStackTrace();
Thread.sleep(500);
}
} while (connection == null && System.currentTimeMillis() < end);
Assert.assertNotNull(connection);
connection.getMBeanCount();
} finally {
IoUtils.safeClose(connector);
}
super.assertRemoveSubsystemResources(services);
}