JBoss Community

Re: Java API to get JBoss message queue information

created by jboss debugg in JBoss Messaging - View the full discussion

thanks Justin

 

https://community.jboss.org/wiki/HowDoIGetRemoteAccessToMyMBean

 

code from above link

Using the RMIAdaptor (weakly typed interface)

The RMIAdaptor provides a remote view of the MBeanServer Note: Use the MBeanServerConnection interface rather than RMIAdaptor on the most recent versions of JBoss.  RMIAdaptor should not be used in version 6.0 (M3) or greater (you must use MBeanServerConnection).

//import org.jboss.jmx.adapter.rmi.RMIAdaptor; import javax.management.MBeanServerConnection;   public void doSomething() throws Exception {    InitialContext ctx = new InitialContext(); // From jndi.properties    //RMIAdaptor server = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");    MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");    System.out.println(server.getAttribute(new ObjectName("MyDomain:key=property"), "AnAttribute"));    server.invoke(new ObjectName("MyDomain:key=property"), "doSomething", new Object[0], new String[0]); }   // For AS 6.0 (M3) or greater, use the following example import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL;   public void doSomething() throws Exception {    String serverURL = "service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"    String username = null;    String password = null;    HashMap env = new HashMap();    if (username != null && password != null)    {       String[] creds = new String[2];       creds[0] = username;       creds[1] = password;       env.put(JMXConnector.CREDENTIALS, creds);    }    JMXServiceURL url = new JMXServiceURL(serverURL);    JMXConnector jmxc = JMXConnectorFactory.connect(url, env);    // Remember to call jmxc.close() when you are done with server connection.    MbeanServerConnection server = jmxc.getMBeanServerConnection();    System.out.println(server.getAttribute(new ObjectName("MyDomain:key=property"), "AnAttribute"));    server.invoke(new ObjectName("MyDomain:key=property"), "doSomething", new Object[0], new String[0]); }      

Reply to this message by going to Community

Start a new discussion in JBoss Messaging at Community