1 8 13 14 package org.webjmx.mx4j; 15 16 import java.util.*; 17 import javax.management.*; 18 import mx4j.adaptor.rmi.jrmp.*; 19 import mx4j.util.*; 20 21 25 public class RMIServer 26 { 27 28 public static void main(String [] args) throws Exception 29 { 30 MBeanServer server = MBeanServerFactory.createMBeanServer(); 32 33 ObjectName naming = new ObjectName("Naming:type=rmiregistry"); 35 server.createMBean("mx4j.tools.naming.NamingService", naming, null); 36 server.invoke(naming, "start", null, null); 37 System.out.println("started NamingService"); 38 39 ObjectName adaptor = new ObjectName("Adaptor:protocol=JRMP"); 41 server.createMBean("mx4j.adaptor.rmi.jrmp.JRMPAdaptor", adaptor, null); 42 JRMPAdaptorMBean mbean = (JRMPAdaptorMBean)StandardMBeanProxy.create(JRMPAdaptorMBean.class, server, adaptor); 43 String jndiName = "jrmp"; 45 mbean.setJNDIName(jndiName); 46 mbean.start(); 48 49 System.out.println("started JRMPAdaptorMBean, InitialContext environment ..."); 50 javax.naming.Context ctx = new javax.naming.InitialContext (); 51 Enumeration e = ctx.getEnvironment().keys(); 52 while(e.hasMoreElements()) 53 { 54 String s = (String )e.nextElement(); 55 System.out.println(s +" : " +ctx.getEnvironment().get(s)); 56 } 57 System.out.println("end InitialContext environment."); 58 System.out.println("InitialContext bindings ..."); 59 javax.naming.NamingEnumeration ne = ctx.listBindings(""); 60 while(ne.hasMore()) 61 { 62 javax.naming.Binding b = (javax.naming.Binding )ne.next(); 63 System.out.println(b.getName() + " : " +b.getObject()); 64 } 65 System.out.println("end InitialContext bindings."); 66 } 67 68 } 69 | Popular Tags |