ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/corbaservices/uk/org/iscream/cms/corbaservices/CorbaServices.java
Revision: 1.3
Committed: Mon Feb 26 22:13:39 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.2: +32 -6 lines
Log Message:
Made the startup more verbose.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.corbaservices;
3
4 //---IMPORTS---
5 import java.lang.reflect.*;
6 import java.util.*;
7 import java.io.*;
8 import java.net.*;
9
10 /**
11 * CORBA Services
12 *
13 * @author $Author: tdb1 $
14 * @version $Id: CorbaServices.java,v 1.2 2001/02/26 21:53:01 tdb1 Exp $
15 */
16 class CorbaServices {
17
18 //---FINAL ATTRIBUTES---
19
20 /**
21 * The current CVS revision of this class
22 */
23 public static final String REVISION = "$Revision: 1.2 $";
24
25 public static final String DEFAULTOKURLS = "./etc/okUrls.conf";
26 public static final String DEFAULTSERVICESCONF = "./etc/services.conf";
27 public static final String DEFAULTWEBDIR = "./web";
28 public static final int DEFAULTPORT = 8080;
29
30 //---STATIC METHODS---
31
32 public static void main(String args[]) {
33
34 System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
35 System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
36
37 System.out.println("--- i-scream CORBA Services Manager ---");
38 System.out.println("--- Starting System ---");
39
40 String okUrls = DEFAULTOKURLS;
41 String servicesConf = DEFAULTSERVICESCONF;
42 String webDir = DEFAULTWEBDIR;
43 int port = DEFAULTPORT;
44 for(int i=0; i < args.length; i++) {
45 if(args[i].equals("-h")) {
46 usage();
47 }
48 else if(args[i].equals("-u")) {
49 i++; okUrls = args[i];
50 }
51 else if(args[i].equals("-s")) {
52 i++; servicesConf = args[i];
53 }
54 else if(args[i].equals("-w")) {
55 i++; webDir = args[i];
56 }
57 else if(args[i].equals("-p")) {
58 i++; port = Integer.parseInt(args[i]);
59 }
60 else {
61 usage();
62 }
63 }
64
65 System.out.println("--- Reading Configuration ---");
66
67 LinkedList serviceList = getServicesList(servicesConf);
68 String[] svcList = new String[serviceList.size()];
69 LinkedList[] svcListParams = new LinkedList[serviceList.size()];
70 Iterator i = serviceList.iterator();
71 int j=0;
72 while(i.hasNext()) {
73 StringTokenizer st = new StringTokenizer((String)i.next());
74 svcList[j] = (String) st.nextToken();
75 LinkedList l = new LinkedList();
76 while (st.hasMoreTokens()) {
77 l.add(st.nextToken());
78 }
79 svcListParams[j] = l;
80 j++;
81 }
82
83 System.out.println("--- Starting CORBA Services ---");
84
85 // start the services
86 try {
87
88 // get hook on the runtime
89 Runtime myRuntime = Runtime.getRuntime();
90 // get hook on the system Class loader
91 ClassLoader myClassLoader = ClassLoader.getSystemClassLoader();
92
93 // step through each app, and start it rolling
94 for (int k=0; k < svcList.length; k++) {
95
96 // Load the class
97 Class myClass = myClassLoader.loadClass(svcList[k]);
98 // and we don't support passing of individual args, but we will ;-) so its just null
99 String[] passedArgs = new String[svcListParams[k].size()];
100 String arglist = "";
101 i = svcListParams[k].iterator();
102 int p = 0;
103 while(i.hasNext()) {
104 passedArgs[p] = (String) i.next();
105 arglist += " " + passedArgs[p];
106 p++;
107 }
108
109 // create an array of classes that are listed in the main method header
110 // so we can get a hook to the main method
111 Class[] passedArgsClass = {passedArgs.getClass()};
112 // get a hook on the main method
113 Method myMethod = myClass.getMethod("main",passedArgsClass);
114
115 // Now we know where it is, we need to create a thread for it, passing in
116 // a list of objects that represent its args.
117 Object[] passedArgsObject = {passedArgs};
118 ApplicationThread anApp = new ApplicationThread(myMethod, passedArgsObject);
119
120 // Finally we start it going
121 anApp.start();
122 System.out.println(svcList[k]+arglist);
123
124 // Now we go and start the rest of the Apps listed
125 }
126
127 } catch (Exception e) {
128 System.out.println(e);
129 e.printStackTrace();
130 }
131
132 System.out.println("--- Starting Mini WebServer ---");
133
134 String host;
135 try {
136 host = InetAddress.getLocalHost().getHostName();
137 } catch(UnknownHostException e) {
138 host = "<unknown>";
139 }
140 System.out.println("Host:\t\t"+host);
141 System.out.println("Port:\t\t"+port);
142 System.out.println("URL List File:\t"+okUrls);
143 System.out.println("Web Directory:\t"+webDir);
144
145 // start the mini-webserver
146 MiniWebServer mws = new MiniWebServer(port, okUrls, webDir);
147 mws.start();
148
149 System.out.println("--- i-scream CORBA Services Ready ---");
150 }
151
152 private static void usage() {
153 System.out.println("USAGE: java uk.ac.ukc.iscream.corbaservices.CorbaServices <option>");
154 System.out.println(" or: java -jar iscream-corbaservices.jar <option>");
155 System.out.println("WHERE <option>:");
156 System.out.println(" -u <filename> - the location of okUrls config file");
157 System.out.println(" the default is ./etc/okUrls.conf");
158 System.out.println(" -s <filename> - the location of services config file");
159 System.out.println(" the default is ./etc/services.conf");
160 System.out.println(" -w <dir> - the location of the web directory");
161 System.out.println(" the default is ./web (no trailing /)");
162 System.out.println(" -p <port> - this port to bind the webserver to");
163 System.out.println(" the default is 8080");
164 System.out.println(" -h - this help screen");
165 System.exit(1);
166 }
167
168 private static LinkedList getServicesList(String filename) {
169 File file = new File(filename);
170 LinkedList svcList = new LinkedList();
171 if(file.exists() && file.canRead()) {
172 try {
173 BufferedReader reader = new BufferedReader(new FileReader(file));
174 while(reader.ready()) {
175 String line = reader.readLine();
176 if(!line.startsWith("#")) {
177 svcList.add(line);
178 }
179 }
180 } catch(IOException e) {
181 System.out.println(e);
182 e.printStackTrace();
183 }
184 }
185 return svcList;
186 }
187
188 //---CONSTRUCTORS---
189
190 //---PUBLIC METHODS---
191
192 //---PRIVATE METHODS---
193
194 //---ACCESSOR/MUTATOR METHODS---
195
196 //---ATTRIBUTES---
197
198 //---STATIC ATTRIBUTES---
199
200 //---INNER CLASSES---
201
202 private static class ApplicationThread extends Thread {
203
204 // The constructor takes the name of the method we're gonna run
205 // and the arguments we're gonna pass into it
206 ApplicationThread(Method mainMethod, Object[] args) {
207 _mainMethod = mainMethod;
208 _args = args;
209 }
210
211 // The main bit of the thread just starts the functionality of the given
212 // method running
213 public void run() {
214 try {
215 _mainMethod.invoke(null, _args);
216 } catch (Exception e){
217 System.out.println(e);
218 e.printStackTrace();
219 }
220 }
221
222 Method _mainMethod = null;
223 Object[] _args = null;
224 }
225
226 }