Skip to content

Instantly share code, notes, and snippets.

@nak3
Created September 9, 2013 01:40
Show Gist options
  • Save nak3/6490434 to your computer and use it in GitHub Desktop.
Save nak3/6490434 to your computer and use it in GitHub Desktop.
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.util.Set;
import java.util.Iterator;
import java.util.HashMap;
/*
[How to exec?]
export CLASSPATH=${JBOSS_HOME}/bin/client/jboss-client.jar:$CLASSPATH
javac JMXExample.java ; java JMXExample
*/
public class JMXExample {
public static void main(String[] args) throws Exception {
//String host = "xxx.xxx.xxx.xxx";
String host = "localhost"; //TODO
String username = "" ; //TODO
String password = ""; //TODO
/* JBoss EAP 6 */
int port = 9999;
String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;
HashMap<String, String[]> env = new HashMap<String, String[]>(); //TODO <String, String[]>
String[] credentials = new String[] { username , password };
env.put("jmx.remote.credentials", credentials);
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
/* -- TEST -- */
int count = connection.getMBeanCount();
System.out.println(count);
ObjectName all = new ObjectName("*:*");
Set names = connection.queryNames(all, null);
Iterator iter = names.iterator();
while( iter.hasNext() )
System.out.println(iter.next());
jmxConnector.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment