KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > tool > ServerLauncher


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

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 JavaDoc;
32
33 public class ServerLauncher {
34
35     public static void main(String JavaDoc[] args) {
36         try {
37             parseArgs(args, System.out);
38         } catch (Exception JavaDoc 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 JavaDoc[] args, PrintStream JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc communicationFactoryClassName;
79     private static int port;
80
81     private static final String JavaDoc CLASS_OPTION = "-class";
82     private static final String JavaDoc PORT_OPTION = "-port";
83 }
84
Popular Tags