KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > examples > time > StatelessTimeServer


1 package org.sapia.ubik.rmi.examples.time;
2
3 import java.util.Properties JavaDoc;
4
5 import javax.naming.InitialContext JavaDoc;
6 import javax.naming.NamingException JavaDoc;
7
8 import org.sapia.ubik.rmi.Consts;
9 import org.sapia.ubik.util.Localhost;
10
11
12 /**
13  * @
14  */

15 public class StatelessTimeServer {
16   private static TimeServiceIF _theTimeService;
17
18   public StatelessTimeServer() {
19   }
20
21   public static void main(String JavaDoc[] args) {
22     try {
23       // Parse the input arguments
24
String JavaDoc aJndiUrlProvider = "ubik://" + Localhost.getLocalAddress().getHostAddress() + ":1099/";
25       String JavaDoc aJndiInitialContext = "org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory";
26
27       if (args.length > 0) {
28         aJndiUrlProvider = args[0];
29
30         if (args.length > 1) {
31           aJndiInitialContext = args[1];
32         }
33       }
34
35       // Create the time service instance
36
_theTimeService = new StatelessTimeServiceImpl();
37
38       // Create the properties for the JNDI operation
39
Properties JavaDoc props = new Properties JavaDoc();
40       props.setProperty(InitialContext.PROVIDER_URL, aJndiUrlProvider);
41       props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, aJndiInitialContext);
42       props.setProperty(Consts.UBIK_DOMAIN_NAME, Consts.DEFAULT_DOMAIN);
43
44       // Bind the time service to the JNDI service
45
InitialContext JavaDoc context = new InitialContext JavaDoc(props);
46       context.bind("util/timeService", _theTimeService);
47       System.out.println("Time service bind and ready to rock");
48
49       while (true) {
50         Thread.sleep(100000);
51       }
52     } catch (NamingException JavaDoc ne) {
53       System.err.println("Error creating the JNDI context");
54       ne.printStackTrace();
55     } catch (InterruptedException JavaDoc ie) {
56       System.err.println("The time server is interrupted and will exit");
57       ie.printStackTrace();
58     } catch (Exception JavaDoc e) {
59       System.err.println("System error running the time service");
60       e.printStackTrace();
61     }
62   }
63 }
64
Popular Tags