1 package org.sapia.ubik.rmi.examples.time; 2 3 import java.util.Properties ; 4 5 import javax.naming.InitialContext ; 6 import javax.naming.NamingException ; 7 8 import org.sapia.ubik.rmi.Consts; 9 import org.sapia.ubik.util.Localhost; 10 11 12 15 public class StatelessTimeServer { 16 private static TimeServiceIF _theTimeService; 17 18 public StatelessTimeServer() { 19 } 20 21 public static void main(String [] args) { 22 try { 23 String aJndiUrlProvider = "ubik://" + Localhost.getLocalAddress().getHostAddress() + ":1099/"; 25 String 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 _theTimeService = new StatelessTimeServiceImpl(); 37 38 Properties props = new Properties (); 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 InitialContext context = new InitialContext (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 ne) { 53 System.err.println("Error creating the JNDI context"); 54 ne.printStackTrace(); 55 } catch (InterruptedException ie) { 56 System.err.println("The time server is interrupted and will exit"); 57 ie.printStackTrace(); 58 } catch (Exception e) { 59 System.err.println("System error running the time service"); 60 e.printStackTrace(); 61 } 62 } 63 } 64 | Popular Tags |