Loading and starting the Java Socket adaptor

This section outlines how to start the Socket adaptor in your Java MBeanServer. This will allow C# MBeanServers to transparently connect to your Java MBean server.

Starting a SocketMBeanServer

Make sure the MonoJMX jar file is in your classpath, and then simply copy paste the code snippet in Listing 1.
Listing 1


MBeanServer mbs = MBeanServerFactory.createMBeanServer("net.sourceforge.monojmx.socket");



Starting a JMXConnectorServer

Listing 2


JMXServiceURL nativeurl = new JMXServiceURL("socket","localhost",8765,"/socketconnector");



Map env = new java.util.HashMap();

env.put(JMXConnectorServerFactory.PROTOCOL_PROVIDER_PACKAGES,"net.sourceforge.monojmx");

JMXConnectorServer jcs = JMXConnectorServerFactory.newJMXConnectorServer(nativeurl,env,mbs);

jcs.start();



Connecting to a remove SocketMBeanServer

Listing 3


Map env = new java.util.HashMap();

env.put(JMXConnectorServerFactory.PROTOCOL_PROVIDER_PACKAGES,"net.sourceforge.monojmx");

JMXServiceURL url = new JMXServiceURL("service:jmx:socket://localhost:8765");

JMXConnector remoteConnectorClient = JMXConnectorFactory.connect(url,env);

MBeanServerConnection rmbs = remoteConnectorClient.getMBeanServerConnection();