1 24 package org.objectweb.jalisto.se.tool; 25 26 import org.objectweb.jalisto.se.api.remote.JalistoServer; 27 import org.objectweb.jalisto.se.exception.JalistoException; 28 import org.objectweb.jalisto.se.impl.factory.InternalRemoteFactory; 29 import org.objectweb.jalisto.se.impl.client.JalistoPropertiesClientImpl; 30 31 import java.io.PrintStream ; 32 33 public class ServerLauncher { 34 35 public static void main(String [] args) { 36 try { 37 parseArgs(args, System.out); 38 } catch (Exception e) { 39 printUsage(System.out); 40 System.exit(0); 41 } 42 JalistoServer server = InternalRemoteFactory.getInstance().getJalistoServer(communicationFactoryClassName); 43 server.launchServer(port); 44 } 45 46 private static void parseArgs(String [] args, PrintStream writer) { 47 if (args.length == 0) { 48 writer.println("no arguments. Uses default values"); 49 } 50 communicationFactoryClassName = JalistoPropertiesClientImpl.COMMUNICATION_FACTORY_CLASS; 51 port = Integer.parseInt(JalistoPropertiesClientImpl.PORT); 52 for (int i = 0; i < args.length; i++) { 53 String o = args[i]; 54 if (o.equalsIgnoreCase(CLASS_OPTION)) { 55 communicationFactoryClassName = args[i + 1]; 56 57 i++; 58 } else if (o.equalsIgnoreCase(PORT_OPTION)) { 59 port = Integer.parseInt(args[i + 1]); 60 i++; 61 } else { 62 throw new JalistoException("FileViewer : invalid argument format : " + o); 63 } 64 } 65 writer.println("Use implementation class : " + communicationFactoryClassName); 66 writer.println("Listen on port : " + port); 67 writer.flush(); 68 } 69 70 public static void printUsage(PrintStream writer) { 71 writer.println( 72 "java org.objectweb.jalisto.se.tool.ServerLauncher <option> : launch socket server for remote clients"); 73 writer.println("\t" + CLASS_OPTION + " <path> : server will use this implementation class"); 74 writer.println("\t" + PORT_OPTION + " <number> : server listen on this port"); 75 writer.flush(); 76 } 77 78 private static String communicationFactoryClassName; 79 private static int port; 80 81 private static final String CLASS_OPTION = "-class"; 82 private static final String PORT_OPTION = "-port"; 83 } 84 | Popular Tags |