KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 public class TimeServer {
18   private static TimeServiceIF _theTimeService;
19
20   public TimeServer() {
21   }
22
23   public static void main(String JavaDoc[] args) {
24     try {
25       _theTimeService = new TimeServiceImpl();
26
27       System.setProperty(Consts.MARSHALLING, "true");
28
29       Properties JavaDoc props = new Properties JavaDoc();
30
31       props.setProperty(InitialContext.PROVIDER_URL, "ubik://" + Localhost.getLocalAddress().getHostAddress() +":1099/");
32       props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
33         RemoteInitialContextFactory.class.getName());
34
35       InitialContext JavaDoc context = new InitialContext JavaDoc(props);
36       context.bind("util/timeService", _theTimeService);
37       System.out.println("Time service bound");
38
39       while (true) {
40         Thread.sleep(100000);
41       }
42     } catch (UnknownHostException JavaDoc e){
43       System.err.println("Could not find JNDI host");
44       e.printStackTrace();
45     } catch (NamingException JavaDoc ne) {
46       System.err.println("Error creating the JNDI context");
47       ne.printStackTrace();
48     } catch (InterruptedException JavaDoc ie) {
49       System.err.println("The time server is interrupted and will exit");
50     } catch (RuntimeException JavaDoc re) {
51       System.err.println("System error running the time service");
52       re.printStackTrace();
53     }
54   }
55 }
56
Popular Tags