[jboss-user] [Management, JMX/JBoss] - Re: Looking up RMIAdaptor sometimes results in java.rmi.NoSu

sileshikassa do-not-reply at jboss.com
Wed Mar 18 18:49:08 EDT 2009


Here is the relevant code used:

import java.util.Hashtable;
import java.util.Properties;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.jboss.logging.Logger;

public class MBeanLocator
{
    private static final Logger log = Logger.getLogger(PeerLocator.class);

    public static FooMBean locateMBean(String ipAddress)
    {
        Hashtable<String, String> props =  new Hashtable<String, String>();
        MBeanServerConnection wrapper = null;
        Properties props = new Properties();
        InitialContext ctx = null;

        try
        {
            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
            props.put(Context.PROVIDER_URL, "jnp://" + ipAddress + ":" + 1099 + "/");
            props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            props.put(Context.SECURITY_PRINCIPAL, "tpAdmin");
            props.put(Context.SECURITY_CREDENTIALS, "rp!3$0mS");

            props.put("jnp.timeout", "10000");
            props.put("jnp.sotimeout", "3000");
            props.put("jnp.maxRetries", "5"); 


            ctx = new InitialContext(props);

            MBeanServerConnection server = (MBeanServerConnection) ctx.lookup(jmx/invoker/RMIAdaptor);
            Object proxy = Proxy.newProxyInstance(MBeanServerProxy.class.getClassLoader(),
                                                  MBeanServerProxy.INTERFACES,
                                                  new MBeanServerProxy(server));
            wrapper = (MBeanServerConnection) proxy;
            ObjectName objectName = new ObjectName("jboss:service=FooMBean");
            fooMbean = (FooMBean) MBeanServerInvocationHandler.newProxyInstance(wrapper,
                                                                                objectName,
                                                                                RemotePeerInterfaceMBean.class,
                                                                                true);
        }
        catch (Throwable e)
        {
            String msg = "Unable to lookup remote MBeanServer. cause: " + e;
            log.error(msg, e);
        }
        finally
        {
            try {
                if (ctx != null) {
                    ctx.close();
                }
            } catch (Throwable e1) {
            }
        }

        return fooMbean;
    }
}

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4219298#4219298

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4219298



More information about the jboss-user mailing list