use of javax.management.remote.JMXConnector in project jvm-breakglass by matlux.
the class MBeanTest method testStartViaJMX.
@Test
public void testStartViaJMX() throws Exception {
int port = 9875;
JMXServiceURL url = new JMXServiceURL(String.format("service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi", port));
JMXConnectorServer jmxServer = createJMXServer(port, url);
try {
jmxServer.start();
assertFalse(nreplServer.isStarted());
JMXConnector connector = JMXConnectorFactory.connect(url);
try {
MBeanServerConnection conn = connector.getMBeanServerConnection();
ObjectName objectName = MBeanRegistration.getObjectName();
NreplMBean proxy = JMX.newMBeanProxy(conn, objectName, NreplMBean.class);
assertFalse(proxy.isStarted());
proxy.start();
assertTrue(proxy.isStarted());
} finally {
connector.close();
}
assertTrue(nreplServer.isStarted());
} finally {
jmxServer.stop();
}
}
use of javax.management.remote.JMXConnector in project druid by alibaba.
the class DruidStat method printDruidStat.
@SuppressWarnings("all")
public static void printDruidStat(Option option) throws Exception {
PrintStream out = option.getPrintStream();
String address = loadManagementAgentAndGetAddress(option.getPid());
JMXServiceURL jmxUrl = new JMXServiceURL(address);
JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl);
MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection();
if (option.printDataSourceData()) {
List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.DATA_SOURCE);
TabledDataPrinter.printDataSourceData(content, option);
}
if (option.printSqlData()) {
List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.SQL);
if (content == null) {
out.println("无SqlStat统计数据,请检查是否已执行了SQL");
} else {
TabledDataPrinter.printSqlData(content, option);
}
}
if (option.printActiveConn()) {
List<List<String>> content = (List<List<String>>) invokeService(jmxConn, Option.ACTIVE_CONN);
if (content == null || content.size() == 0) {
out.println("目前无活动中的数据库连接");
} else {
TabledDataPrinter.printActiveConnStack(content, option);
}
}
}
use of javax.management.remote.JMXConnector in project otter by alibaba.
the class JmxLoaderIntegration method test_simple.
@Test
public void test_simple() {
MBeanServer mBeanServer = exporter.getServer();
try {
ObjectName objectName = new ObjectName("bean:name=otterControllor");
MBeanInfo nodeInfo = mBeanServer.getMBeanInfo(objectName);
System.out.println(nodeInfo);
Object result = mBeanServer.getAttribute(objectName, "HeapMemoryUsage");
System.out.println(result);
JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/mbean");
Map environment = null;
JMXConnector cntor = JMXConnectorFactory.connect(address, environment);
MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
String domain = mbsc.getDefaultDomain();
System.out.println(domain);
result = mbsc.getAttribute(objectName, "HeapMemoryUsage");
System.out.println(result);
} catch (Exception e) {
want.fail(e.getMessage());
}
}
use of javax.management.remote.JMXConnector in project spring-framework by spring-projects.
the class ConnectorServerFactoryBeanTests method checkServerConnection.
private void checkServerConnection(MBeanServer hostedServer) throws IOException, MalformedURLException {
// Try to connect using client.
JMXServiceURL serviceURL = new JMXServiceURL(ConnectorServerFactoryBean.DEFAULT_SERVICE_URL);
JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
assertNotNull("Client Connector should not be null", connector);
// Get the MBean server connection.
MBeanServerConnection connection = connector.getMBeanServerConnection();
assertNotNull("MBeanServerConnection should not be null", connection);
// Test for MBean server equality.
assertEquals("Registered MBean count should be the same", hostedServer.getMBeanCount(), connection.getMBeanCount());
}
use of javax.management.remote.JMXConnector in project opennms by OpenNMS.
the class JmxCommand method execute.
protected void execute() throws CmdLineException, CmdRunException {
try (JMXConnector connector = getJmxConnector()) {
MBeanServerConnection mbeanServerConnection = connector.getMBeanServerConnection();
execute(mbeanServerConnection);
} catch (MBeanServerQueryException | JMException | IOException e) {
throw new CmdRunException(e);
}
}
Aggregations