本文整理汇总了Java中javax.management.remote.JMXConnector.connect方法的典型用法代码示例。如果您正苦于以下问题:Java JMXConnector.connect方法的具体用法?Java JMXConnector.connect怎么用?Java JMXConnector.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.remote.JMXConnector
的用法示例。
在下文中一共展示了JMXConnector.connect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dotest
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
private static void dotest(JMXServiceURL url, MBeanServer mbs)
throws Exception {
JMXConnectorServer server = null;
JMXConnector client = null;
server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
server.start();
JMXServiceURL outputAddr = server.getAddress();
System.out.println("Server started ["+ outputAddr+ "]");
client = JMXConnectorFactory.newJMXConnector(outputAddr, null);
client.connect();
System.out.println("Client connected");
MBeanServerConnection connection
= client.getMBeanServerConnection();
System.out.println(connection.getDefaultDomain());
}
示例2: MBeanWrapper
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
MBeanWrapper( int jvmPort ) throws MonitorConfigurationException {
this.jvmPort = jvmPort;
try {
JMXConnector connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"
+ this.jvmPort
+ "/jmxrmi"),
null);
connector.connect();
this.connection = connector.getMBeanServerConnection();
} catch (Exception e) {
final String msg = "Error initializing the JMV monitor. Unable to connect to JVM at port "
+ this.jvmPort;
log.error(msg, e);
throw new MonitorConfigurationException(msg, e);
}
}
示例3: testStop
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
@Test
public void testStop() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
LOG.info("shutdown hbase cluster...");
cluster.shutdown();
LOG.info("wait for the hbase cluster shutdown...");
cluster.waitUntilShutDown();
JMXConnector connector = JMXConnectorFactory.newJMXConnector(
JMXListener.buildJMXServiceURL(connectorPort,connectorPort), null);
expectedEx.expect(IOException.class);
connector.connect();
}
示例4: main
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// 如果执行的JavaScript脚本内容过长
// 则可以把脚本写在一个文件里,然后使用jmx client 动态调用mbean接口方法
String user = "root";
String pwd = "root";
// 如果生产环境需要账号验证的话
String[] account = new String[] { user, pwd };
Map<String, String[]> props = new HashMap<String, String[]>();
props.put("jmx.remote.credentials", account);
// 10086参数,具体见启动脚本的vm参数,@see -Dcom.sun.management.jmxremote.port=10086
JMXServiceURL address =
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:10086/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address, props);
MBeanServerConnection mBeanConnection = connector.getMBeanServerConnection();
connector.connect();
ObjectName objectName=new ObjectName("GameMXBean:name=GameMonitor");
System.out.println("\nMBean count = " + mBeanConnection.getMBeanCount());
for (ObjectInstance object : mBeanConnection.queryMBeans(null, null)) {
// System.out.println("object.getObjectName="+object.getObjectName());
}
final GameMonitorMXBean mBean = JMX.newMBeanProxy(mBeanConnection, objectName,
GameMonitorMXBean.class);
String script = readScript("script.js");
System.err.println(script);
System.err.println(mBean.execJavascript(script));
}
示例5: test
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
private static void test() {
try {
JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer server;
JMXServiceURL addr;
JMXConnector client;
MBeanServerConnection mserver;
final ObjectName delegateName =
new ObjectName("JMImplementation:type=MBeanServerDelegate");
final NotificationListener dummyListener =
new NotificationListener() {
public void handleNotification(Notification n,
Object o) {
// do nothing
return;
}
};
server = JMXConnectorServerFactory.newJMXConnectorServer(u,
null,
mbs);
server.start();
addr = server.getAddress();
client = JMXConnectorFactory.newJMXConnector(addr, null);
client.connect(null);
mserver = client.getMBeanServerConnection();
String s1 = "1";
String s2 = "2";
String s3 = "3";
mserver.addNotificationListener(delegateName,
dummyListener, null, s1);
mserver.addNotificationListener(delegateName,
dummyListener, null, s2);
mserver.addNotificationListener(delegateName,
dummyListener, null, s3);
mserver.removeNotificationListener(delegateName,
dummyListener, null, s3);
mserver.removeNotificationListener(delegateName,
dummyListener, null, s2);
mserver.removeNotificationListener(delegateName,
dummyListener, null, s1);
client.close();
server.stop();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
System.exit(1);
}
}
示例6: main
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("---RMIConnectorNullSubjectConnTest starting...");
JMXConnectorServer connectorServer = null;
JMXConnector connectorClient = null;
try {
MBeanServer mserver = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0);
connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver);
connectorServer.start();
JMXServiceURL serverAddr = connectorServer.getAddress();
connectorClient = JMXConnectorFactory.connect(serverAddr, null);
connectorClient.connect();
Field nullSubjectConnField = RMIConnector.class.getDeclaredField("nullSubjectConnRef");
nullSubjectConnField.setAccessible(true);
WeakReference<MBeanServerConnection> weak =
(WeakReference<MBeanServerConnection>)nullSubjectConnField.get(connectorClient);
if (weak != null && weak.get() != null) {
throw new RuntimeException("nullSubjectConnRef must be null at initial time.");
}
MBeanServerConnection conn1 = connectorClient.getMBeanServerConnection(null);
MBeanServerConnection conn2 = connectorClient.getMBeanServerConnection(null);
if (conn1 == null) {
throw new RuntimeException("A connection with null subject should not be null.");
} else if (conn1 != conn2) {
throw new RuntimeException("The 2 connections with null subject are not equal.");
}
conn1 = null;
conn2 = null;
int i = 1;
do {
System.gc();
Thread.sleep(100);
weak = (WeakReference<MBeanServerConnection>)nullSubjectConnField.get(connectorClient);
} while ((weak != null && weak.get() != null) && i++ < 60);
System.out.println("---GC times: " + i);
if (weak != null && weak.get() != null) {
throw new RuntimeException("Failed to clean RMIConnector's nullSubjectConn");
} else {
System.out.println("---RMIConnectorNullSubjectConnTest: PASSED!");
}
} finally {
try {
connectorClient.close();
connectorServer.stop();
} catch (Exception e) {
}
}
}
示例7: main
import javax.management.remote.JMXConnector; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("---RMIConnectorInternalMapTest starting...");
JMXConnectorServer connectorServer = null;
JMXConnector connectorClient = null;
try {
MBeanServer mserver = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0);
connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver);
connectorServer.start();
JMXServiceURL serverAddr = connectorServer.getAddress();
connectorClient = JMXConnectorFactory.connect(serverAddr, null);
connectorClient.connect();
Field rmbscMapField = RMIConnector.class.getDeclaredField("rmbscMap");
rmbscMapField.setAccessible(true);
Map<Subject, WeakReference<MBeanServerConnection>> map =
(Map<Subject, WeakReference<MBeanServerConnection>>) rmbscMapField.get(connectorClient);
if (map != null && !map.isEmpty()) { // failed
throw new RuntimeException("RMIConnector's rmbscMap must be empty at the initial time.");
}
Subject delegationSubject =
new Subject(true,
Collections.singleton(new JMXPrincipal("delegate")),
Collections.EMPTY_SET,
Collections.EMPTY_SET);
MBeanServerConnection mbsc1 =
connectorClient.getMBeanServerConnection(delegationSubject);
MBeanServerConnection mbsc2 =
connectorClient.getMBeanServerConnection(delegationSubject);
if (mbsc1 == null) {
throw new RuntimeException("Got null connection.");
}
if (mbsc1 != mbsc2) {
throw new RuntimeException("Not got same connection with a same subject.");
}
map = (Map<Subject, WeakReference<MBeanServerConnection>>) rmbscMapField.get(connectorClient);
if (map == null || map.isEmpty()) { // failed
throw new RuntimeException("RMIConnector's rmbscMap has wrong size "
+ "after creating a delegated connection.");
}
delegationSubject = null;
mbsc1 = null;
mbsc2 = null;
int i = 0;
while (!map.isEmpty() && i++ < 60) {
System.gc();
Thread.sleep(100);
}
System.out.println("---GC times: " + i);
if (!map.isEmpty()) {
throw new RuntimeException("Failed to clean RMIConnector's rmbscMap");
} else {
System.out.println("---RMIConnectorInternalMapTest: PASSED!");
}
} finally {
try {
connectorClient.close();
connectorServer.stop();
} catch (Exception e) {
}
}
}