KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webjmx > mx4j > RMIServer


1 /*
2  * Copyright (C) WebJMX.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the WebJMX License version 2.0.
6  * See the terms of the WebJMX License in the documentation provided with this software.
7  */

8 /*
9  * RMIServer.java
10  *
11  * Created on August 2, 2002, 2:25 PM
12  */

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 /** Starts an MBeanServer that's reachable via RMI using the MX4J package
22  *
23  * @author john aronson
24  */

25 public class RMIServer
26 {
27
28     public static void main(String JavaDoc[] args) throws Exception JavaDoc
29     {
30     // Create a MBeanServer
31
MBeanServer server = MBeanServerFactory.createMBeanServer();
32
33     // Create and start the naming service
34
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     // Create the JRMP adaptor
40
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     // Set the JNDI name with which will be registered
44
String JavaDoc jndiName = "jrmp";
45     mbean.setJNDIName(jndiName);
46     // Register the JRMP adaptor in JNDI and start it
47
mbean.start();
48         
49         System.out.println("started JRMPAdaptorMBean, InitialContext environment ...");
50         javax.naming.Context JavaDoc ctx = new javax.naming.InitialContext JavaDoc();
51         Enumeration e = ctx.getEnvironment().keys();
52         while(e.hasMoreElements())
53         {
54             String JavaDoc s = (String JavaDoc)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 JavaDoc ne = ctx.listBindings("");
60         while(ne.hasMore())
61         {
62             javax.naming.Binding JavaDoc b = (javax.naming.Binding JavaDoc)ne.next();
63             System.out.println(b.getName() + " : " +b.getObject());
64         }
65         System.out.println("end InitialContext bindings.");
66     }
67
68 }
69
Popular Tags