本文整理匯總了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) {
}
}
}