1 package org.sapia.ubik.rmi.examples.time; 2 3 import java.net.UnknownHostException ; 4 import org.sapia.ubik.rmi.Consts; 5 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory; 6 7 import java.util.Properties ; 8 9 import javax.naming.InitialContext ; 10 import javax.naming.NamingException ; 11 import org.sapia.ubik.util.Localhost; 12 13 14 17 public class TimeServer { 18 private static TimeServiceIF _theTimeService; 19 20 public TimeServer() { 21 } 22 23 public static void main(String [] args) { 24 try { 25 _theTimeService = new TimeServiceImpl(); 26 27 System.setProperty(Consts.MARSHALLING, "true"); 28 29 Properties props = new Properties (); 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 context = new InitialContext (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 e){ 43 System.err.println("Could not find JNDI host"); 44 e.printStackTrace(); 45 } catch (NamingException ne) { 46 System.err.println("Error creating the JNDI context"); 47 ne.printStackTrace(); 48 } catch (InterruptedException ie) { 49 System.err.println("The time server is interrupted and will exit"); 50 } catch (RuntimeException re) { 51 System.err.println("System error running the time service"); 52 re.printStackTrace(); 53 } 54 } 55 } 56 | Popular Tags |