KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > naming > remote > JNDIServer


1 package org.sapia.ubik.rmi.naming.remote;
2
3 import org.sapia.ubik.rmi.server.Hub;
4 import org.sapia.ubik.rmi.server.Log;
5
6
7 /**
8  * This class implements a <code>JNDIServer</code> by exporting a root
9  * <code>javax.naming.Context</code> as a remote object. It has the following
10  * characteristics:
11  *
12  * <ul>
13  * <li>It sends notifications to new clients that appear on the network, allowing these
14  * clients to benefit from the dynamic discovery of JNDI servers.
15  * <li>It sends notifications to clients every time a service is bound to them. This allows
16  * clients to benefit from the dynamic discovry of new services that appear on the
17  * network.
18  * </ul>
19  *
20  * To benefit from these features, clients must connect to this server by using a
21  * <code>RemoteInitialContextFactory</code>.
22  *
23  *
24  * @see org.sapia.ubik.rmi.naming.remote.JNDIServer
25  * @see org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory
26  *
27  * @author Yanick Duchesne
28  * <dl>
29  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
30  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
31  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
32  * </dl>
33  */

34 public class JNDIServer {
35   /**
36    * Starts this server. The port on which the server must listen, as well as its domain, can
37    * be specified. The default value for each of these arguments is - respectively - 1099 and
38    * and "default".
39    * <p>
40    * The multicast address and port on which this JNDI server listens - and through which
41    * it sends notifications - can be specified through system properties. The latter are:
42    *
43    * <ul>
44    * <li>ubik.rmi.naming.mcast.address
45    * <li>ubik.rmi.naming.mcast.port
46    * </ul>
47    *
48    * If not specified, the following are used for multicast address and port, respectively:
49    *
50    * <ul>
51    * <li>224.0.0.1
52    * <li>5454
53    * </ul>
54    */

55   public static void main(String JavaDoc[] args) {
56     JNDIServerHelper.Args argsObj = JNDIServerHelper.parseArgs(args);
57     if (argsObj != null) {
58       try {
59         EmbeddableJNDIServer server = new EmbeddableJNDIServer(argsObj.domain,
60             argsObj.port, argsObj.mcastAddress, argsObj.mcastPort);
61
62         server.start(false);
63
64         Runtime.getRuntime().addShutdownHook(new ShutdownHook(server));
65       } catch (Throwable JavaDoc t) {
66         t.printStackTrace();
67       }
68     }
69   }
70
71   public static final class ShutdownHook extends Thread JavaDoc {
72     private EmbeddableJNDIServer _svr;
73
74     ShutdownHook(EmbeddableJNDIServer svr) {
75       _svr = svr;
76     }
77
78     /**
79      * @see java.lang.Thread#run()
80      */

81     public void run() {
82       _svr.stop();
83       try{
84     Hub.shutdown(30000);
85       }catch(InterruptedException JavaDoc e){
86         Log.error(getClass(), "JNDI server could not shut down properly", e);
87       }
88     }
89   }
90 }
91
Popular Tags