-
2. Re: Connecting to MBean from a Client
sgturner Oct 8, 2002 2:33 PM (in response to marco.rovati)Here is my source code I have used to connect to an MBean from a client:
package com.tes.rmiconnector;
import java.util.*;
import javax.management.*;
import javax.naming.*;
import org.jboss.jmx.adaptor.rmi.*;
import org.jboss.jmx.connector.*;
import org.jboss.jmx.connector.rmi.RMIConnectorImpl;
public class Client {
public static void main (String[] args) throws Exception {
try {
// Set up jndi properties
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
InitialContext ctx = new InitialContext(props);
System.out.println ("Got context");
// Retrieve the RMI adaptor
Object obj = ctx.lookup("jmx:my_machine_name:rmi");
System.out.println ("Got RMI Adapter");
ctx.close();
// Wrap it in a connector
RemoteMBeanServer server = new RMIConnectorImpl((RMIAdaptor)obj);
// Print the EJB count
System.out.println(server.queryMBeans(new ObjectName("jboss.j2ee:service=EJB,*"), null).size());
}
catch (Exception ex) {
ex.printStackTrace();
}
}
} -
3. Re: Connecting to MBean from a Client
marco.rovati Oct 9, 2002 4:31 AM (in response to marco.rovati)Ok, I run this code and I have this error:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
I need to do some CLASSPATH configuration?
Bye,
Marco -
4. Re: Connecting to MBean from a Client
marco.rovati Oct 9, 2002 5:26 AM (in response to marco.rovati)Ok, thank you.
Your sample run correctly.
Now I need to connect to my MBEAN (the jndiName is ServiceDistributor) and run a method and get a property.
How can I do this?
Thank you in advance
Regards,
Marco