use of javax.management.remote.JMXConnector in project jvm-tools by aragozin.
the class JmxConnectionInfo method connectJmx.
@SuppressWarnings("resource")
private MBeanServerConnection connectJmx(String host, int port, Map<String, Object> props) {
try {
String proto = System.getProperty("jmx.service.protocol", "rmi");
final String uri = "rmi".equals(proto) ? "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" : "service:jmx:" + proto + "://" + host + ":" + port;
JMXServiceURL jmxurl = new JMXServiceURL(uri);
JMXConnector conn = props == null ? JMXConnectorFactory.connect(jmxurl) : JMXConnectorFactory.connect(jmxurl, props);
// TODO credentials
MBeanServerConnection mserver = conn.getMBeanServerConnection();
return mserver;
} catch (MalformedURLException e) {
commandHost.fail("JMX Connection failed: " + e.toString(), e);
} catch (IOException e) {
commandHost.fail("JMX Connection failed: " + e.toString(), e);
}
return null;
}
use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.
the class TreeWalker method main.
public static void main(String[] args) throws Exception {
Server server = Server.builder().setHost("localhost").setPort("1099").build();
JMXConnector conn = null;
try {
conn = server.getServerConnection();
MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
TreeWalker tw = new TreeWalker();
tw.walkTree(mbeanServer);
} catch (IOException e) {
log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
} finally {
if (conn != null) {
conn.close();
}
}
}
use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.
the class TreeWalker2 method main.
/** */
public static void main(String[] args) throws Exception {
Server server = Server.builder().setHost("localhost").setPort("1099").build();
JMXConnector conn = null;
try {
conn = server.getServerConnection();
MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
TreeWalker2 tw = new TreeWalker2();
tw.walkTree(mbeanServer, server);
} catch (IOException e) {
log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
} finally {
if (conn != null) {
conn.close();
}
}
}
use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.
the class TreeWalker3 method main.
/** */
public static void main(String[] args) throws Exception {
Server server = Server.builder().setHost("w2").setPort("1105").build();
JMXConnector conn = null;
try {
conn = server.getServerConnection();
MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
TreeWalker3 tw = new TreeWalker3();
tw.walkTree(mbeanServer, server);
} catch (IOException e) {
log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
} finally {
if (conn != null) {
conn.close();
}
}
}
use of javax.management.remote.JMXConnector in project jvm-breakglass by matlux.
the class MBeanTest method testStartStopViaJMX.
@Test
public void testStartStopViaJMX() throws Exception {
int port = 9876;
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());
proxy.stop();
assertFalse(proxy.isStarted());
} finally {
connector.close();
}
} finally {
jmxServer.stop();
}
assertFalse(nreplServer.isStarted());
}
Aggregations