1 package org.sapia.ubik.rmi.naming.remote; 2 3 import java.io.IOException ; 4 5 import javax.naming.Context ; 6 import javax.naming.NamingException ; 7 8 import org.sapia.ubik.mcast.EventChannel; 9 import org.sapia.ubik.net.ServerAddress; 10 import org.sapia.ubik.rmi.naming.remote.archie.UbikRemoteContext; 11 12 13 21 public class JNDIServerHelper implements Consts { 22 23 30 public static Args parseArgs(String [] args) { 31 int port = DEFAULT_PORT; 32 String domain = DEFAULT_DOMAIN; 33 String mcastAddress = org.sapia.ubik.rmi.Consts.DEFAULT_MCAST_ADDR; 34 int mcastPort = org.sapia.ubik.rmi.Consts.DEFAULT_MCAST_PORT; 35 36 if (args.length > 0) { 37 if (args[0].equals("-h")) { 38 help(); 39 40 return null; 41 } 42 43 try { 44 port = Integer.parseInt(args[0]); 45 46 if (args.length == 2) { 47 domain = args[1]; 48 } 49 } catch (NumberFormatException e) { 50 domain = args[0]; 51 52 if (args.length == 2) { 53 try { 54 port = Integer.parseInt(args[1]); 55 } catch (NumberFormatException e2) { 56 help(); 57 58 return null; 59 } 60 } 61 } 62 } 63 64 try { 65 if (System.getProperty(org.sapia.ubik.rmi.Consts.MCAST_PORT_KEY) != null) { 66 mcastPort = Integer.parseInt(System.getProperty( 67 org.sapia.ubik.rmi.Consts.MCAST_PORT_KEY)); 68 } 69 } catch (NumberFormatException e) { 70 System.out.println("Invalid multicast port: " + 71 System.getProperty(org.sapia.ubik.rmi.Consts.MCAST_PORT_KEY)); 72 help(); 73 74 return null; 75 } 76 77 if (System.getProperty(org.sapia.ubik.rmi.Consts.MCAST_ADDR_KEY) != null) { 78 mcastAddress = System.getProperty(org.sapia.ubik.rmi.Consts.MCAST_ADDR_KEY); 79 } 80 81 return new Args(port, domain, mcastAddress, mcastPort); 82 } 83 84 public static Context newRootContext(EventChannel ec) 85 throws NamingException { 86 return UbikRemoteContext.newInstance(ec); 87 } 88 89 public static ClientListener createClientListener(EventChannel ec, 90 ServerAddress addr) throws NamingException , IOException { 91 ClientListener listener = new ClientListener(ec, addr); 92 ec.registerAsyncListener(Consts.JNDI_CLIENT_PUBLISH, listener); 93 94 ec.dispatch(Consts.JNDI_SERVER_PUBLISH, addr); 95 96 return listener; 97 } 98 99 static final void help() { 100 System.out.println(); 101 System.out.println("Syntax: jndi [<port>] [<domain>]"); 102 System.out.println("where:"); 103 System.out.println( 104 "<port> := port on which JNDI server should listen (defaults to 1099)."); 105 System.out.println( 106 "<domain>:= domain name that JNDI server is part of (defaults to 'default')."); 107 System.out.println(); 108 System.out.println(); 109 System.exit(1); 110 } 111 112 public static class Args { 113 int port; 114 int mcastPort; 115 String mcastAddress; 116 String domain; 117 118 Args(int port, String domain, String mcastAddress, int mcastPort) { 119 this.port = port; 120 this.domain = domain; 121 this.mcastAddress = mcastAddress; 122 this.mcastPort = mcastPort; 123 } 124 } 125 } 126 | Popular Tags |