JMX协议连接方式

阅读更多

JMX协议的实现由IIOP和JMXMP,其连接方式有所不同:

IIOP如下:

 

Hashtable env = new Hashtable();
String prividerUrl = "iiop://" + host + ":" + port;
String[] credentials = new String[] { userName, userPwd };
env.clear();
env.put(Context.PROVIDER_URL, prividerUrl);
env.put(JMXConnector.CREDENTIALS, credentials);
env.put(Context.AUTHORITATIVE, userName);
env.put(Context.SECURITY_CREDENTIALS, userPwd);
try {
   JMXServiceURL url = new JMXServiceURL("iiop", host, port, "/jndi/corbaname::1.2@" + host + ":" + port + "#jmx/rmi/RMIConnectorServer");
   connector = JMXConnectorFactory.connect(url, env);
} catch (MalformedURLException e) {
   throw new OperationNoSuccessException("connection to connector server fail,either no legal protocol could be found in a specification string or the string could not be parsed", e);
} catch (IOException e) {
   throw new OperationNoSuccessException("connection to connector server fail", e);
}

 

 

JMXMP如下:

 

try {
   url = new JMXServiceURL("service:jmx:jmxmp://" + host + ":" + port);
} catch (MalformedURLException e) {
   throw new RuntimeException(e);
}
Hashtable env = new Hashtable();
env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "com.sun.jmx.remote.protocol");
env.put("jmx.remote.profiles", "SASL/PLAIN");
env.put("jmx.remote.sasl.callback.handler", new SaslUserPasswordCallbackHandler(userName, userPwd));
env.put(GenericConnector.MESSAGE_CONNECTION, new MuxSocketClientMessageConnection(url.getHost(), url.getPort()));

// install SASL/PLAIN mechanism provider
SaslClientSecurityProvider.install();
if (url != null) {
    return JMXConnectorFactory.connect(url, env);
}

 

 
 

 

 

你可能感兴趣的:(JMX协议连接方式)