Connect to a server
by looking up the Management enterprise bean from the Java Naming and Directory
Interface (JNDI). The Management enterprise bean supplies a remote interface
to the MBean server that runs in the application server. The Management enterprise
bean works almost exactly like the
WebSphere Application Server administrative
client, except that it does not provide
WebSphere Application Server specific
functionality. The following example shows how to look up the Management enterprise
bean.
import javax.management.j2ee.ManagementHome;
import javax.management.j2ee.Management;
Properties props = new Properties();
props.setProperty(Context.PROVIDER_URL, "iiop://myhost:2809");
Context ic = new InitialContext(props);
Object obj = ic.lookup("ejb/mgmt/MEJB");
ManagementHome mejbHome = (ManagementHome)
PortableRemoteObject.narrow(obj, ManagementHome.class);
Management mejb = mejbHome.create();
The example gets an initial context to an application server by
passing the host and port of the Remote Method Invocation (RMI) connector.
You must explicitly code the RMI port, in this case 2809. The lookup method
looks up the
ejb/mgmt/MEJB path, which is the location of
the Management enterprise bean home. The example then creates the mejb stateless
session bean, which you use in the next step.