2 Replies Latest reply on Jul 3, 2002 12:00 AM by minamoto

    Connecting to remote MBean server

    angelawhelan

      hi all,
      I am just wondering, how do I connect to a remote MBean server, by giving the URL of the MBean server ?

      I want a piece of code which will connect to a remote MBean server using an address, or URL, which I give it ?

      Does anyone have any ideas ?

      Thanks
      A.

        • 1. Re: Connecting to remote MBean server
          davidjencks

          Look at the jboss ant jmx task in varia or in the JBossTestServices in the testsuite.

          • 2. Re: Connecting to remote MBean server
            minamoto

            Hi,
            I wrote a small code to access the RemoteMBeanServer for my ant scripts.
            I hope this helps.

            Miki
            ------
            import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
            import org.jboss.jmx.connector.RemoteMBeanServer;
            import org.jboss.jmx.connector.rmi.RMIConnectorImpl;

            import javax.naming.InitialContext;
            import javax.management.ObjectName;
            import java.io.File;
            import java.net.InetAddress;

            /**
            * DeployerInvoker is a class to invoke the MainDeployer from ant build scripts.
            *
            * example:
            *
            *
            *
            *
            *
            */
            public class DeployerInvoker {
            public static final String DEPLOYER_NAME = "jboss.system:service=MainDeployer";

            public static void main(String args[] ) {
            InitialContext ctx = null;
            try {
            String operation = args[0];
            String fileName = args[1];

            String deployName = new File(fileName).toURL().toString();

            // get a remote mbean server from the jndi
            ctx = new InitialContext();
            String serverName = InetAddress.getLocalHost().getHostName();
            String adaptorName = "jmx:" + serverName + ":rmi";
            RMIAdaptor adaptor = (RMIAdaptor) ctx.lookup(adaptorName);
            RemoteMBeanServer server = new RMIConnectorImpl(adaptor);

            // invoke an operation to the server
            server.invoke(new ObjectName(DEPLOYER_NAME),
            operation,
            new Object[] {deployName},
            new String[] {"java.lang.String"});
            }
            catch (Exception e) {
            e.printStackTrace();
            }
            finally {
            try {
            if (ctx != null) ctx.close();
            }
            catch (Exception ignore) {}
            }
            }
            }