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.4
Committed: Mon Feb 26 22:26:10 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.3: +62 -20 lines
Log Message:
Commenting and javadoc'ing.

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 Manager
12 *
13 * This class provides a simple wrapper to CORBA services
14 * that require a web service to "share" their IOR files.
15 * This provides an all-in-one way of starting up service(s)
16 * and serving their IOR files. No external web servers are
17 * required.
18 *
19 * @author $Author: tdb1 $
20 * @version $Id: CorbaServices.java,v 1.3 2001/02/26 22:13:39 tdb1 Exp $
21 */
22 class CorbaServices {
23
24 //---FINAL ATTRIBUTES---
25
26 /**
27 * The current CVS revision of this class
28 */
29 public static final String REVISION = "$Revision: 1.3 $";
30
31 /**
32 * Default path to "ok URL's" list
33 */
34 public static final String DEFAULTOKURLS = "./etc/okUrls.conf";
35
36 /**
37 * Default path to services list
38 */
39 public static final String DEFAULTSERVICESCONF = "./etc/services.conf";
40
41 /**
42 * Default path to web directory. Note there is *no* trailing slash.
43 */
44 public static final String DEFAULTWEBDIR = "./web";
45
46 /**
47 * Default port number
48 */
49 public static final int DEFAULTPORT = 8080;
50
51 //---STATIC METHODS---
52
53 /**
54 * This main method starts the whole system up. A lot
55 * of the functionality is provided in this main class.
56 */
57 public static void main(String args[]) {
58
59 // Use JacORB
60 System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
61 System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
62
63 System.out.println("--- i-scream CORBA Services Manager ---");
64 System.out.println("--- Starting System ---");
65
66 // Read command line arguments
67 String okUrls = DEFAULTOKURLS;
68 String servicesConf = DEFAULTSERVICESCONF;
69 String webDir = DEFAULTWEBDIR;
70 int port = DEFAULTPORT;
71 for(int i=0; i < args.length; i++) {
72 if(args[i].equals("-h")) {
73 usage();
74 }
75 else if(args[i].equals("-u")) {
76 i++; okUrls = args[i];
77 }
78 else if(args[i].equals("-s")) {
79 i++; servicesConf = args[i];
80 }
81 else if(args[i].equals("-w")) {
82 i++; webDir = args[i];
83 }
84 else if(args[i].equals("-p")) {
85 i++; port = Integer.parseInt(args[i]);
86 }
87 else {
88 usage();
89 }
90 }
91
92 // Read in the services configuration
93 System.out.println("--- Reading Configuration ---");
94
95 LinkedList serviceList = getServicesList(servicesConf);
96 String[] svcList = new String[serviceList.size()];
97 LinkedList[] svcListParams = new LinkedList[serviceList.size()];
98 Iterator i = serviceList.iterator();
99 int j=0;
100 while(i.hasNext()) {
101 StringTokenizer st = new StringTokenizer((String)i.next());
102 svcList[j] = (String) st.nextToken();
103 LinkedList l = new LinkedList();
104 while (st.hasMoreTokens()) {
105 l.add(st.nextToken());
106 }
107 svcListParams[j] = l;
108 j++;
109 }
110
111 // Start the services one by one
112 System.out.println("--- Starting CORBA Services ---");
113
114 try {
115
116 // get hooks on the system loaders
117 Runtime myRuntime = Runtime.getRuntime();
118 ClassLoader myClassLoader = ClassLoader.getSystemClassLoader();
119
120 // start each service one by one
121 for (int k=0; k < svcList.length; k++) {
122
123 // Load the class
124 Class myClass = myClassLoader.loadClass(svcList[k]);
125 // Sort out the command line parameters
126 String[] passedArgs = new String[svcListParams[k].size()];
127 // keep a String list for printing out later :)
128 String arglist = "";
129 i = svcListParams[k].iterator();
130 int p = 0;
131 while(i.hasNext()) {
132 passedArgs[p] = (String) i.next();
133 arglist += " " + passedArgs[p];
134 p++;
135 }
136
137 // create an array of classes that are listed in the main method header
138 // so we can get a hook to the main method
139 Class[] passedArgsClass = {passedArgs.getClass()};
140 // get a hook on the main method
141 Method myMethod = myClass.getMethod("main",passedArgsClass);
142
143 // Now we know where it is, we need to create a thread for it, passing in
144 // a list of objects that represent its args.
145 Object[] passedArgsObject = {passedArgs};
146 ServiceThread aSvc = new ServiceThread(myMethod, passedArgsObject);
147
148 // Finally we start it going
149 aSvc.start();
150 System.out.println(svcList[k]+arglist);
151 }
152
153 } catch (Exception e) {
154 System.out.println(e);
155 e.printStackTrace();
156 }
157
158 System.out.println("--- Starting Mini WebServer ---");
159
160 // print out some system details
161 String host;
162 try {
163 host = InetAddress.getLocalHost().getHostName();
164 } catch(UnknownHostException e) {
165 host = "<unknown>";
166 }
167 System.out.println("Host:\t\t"+host);
168 System.out.println("Port:\t\t"+port);
169 System.out.println("URL List File:\t"+okUrls);
170 System.out.println("Web Directory:\t"+webDir);
171
172 // start the mini-webserver
173 MiniWebServer mws = new MiniWebServer(port, okUrls, webDir);
174 mws.start();
175
176 System.out.println("--- i-scream CORBA Services Ready ---");
177 }
178
179 /**
180 * Print out usage information.
181 */
182 private static void usage() {
183 System.out.println("USAGE: java uk.ac.ukc.iscream.corbaservices.CorbaServices <option>");
184 System.out.println(" or: java -jar iscream-corbaservices.jar <option>");
185 System.out.println("WHERE <option>:");
186 System.out.println(" -u <filename> - the location of okUrls config file");
187 System.out.println(" the default is ./etc/okUrls.conf");
188 System.out.println(" -s <filename> - the location of services config file");
189 System.out.println(" the default is ./etc/services.conf");
190 System.out.println(" -w <dir> - the location of the web directory");
191 System.out.println(" the default is ./web (no trailing /)");
192 System.out.println(" -p <port> - this port to bind the webserver to");
193 System.out.println(" the default is 8080");
194 System.out.println(" -h - this help screen");
195 System.exit(1);
196 }
197
198 /**
199 * Read the services into a LinkedList. This is later
200 * parsed to get classes and parameters.
201 *
202 * @param filename the services configuration file
203 * @return a LinkedList of services
204 */
205 private static LinkedList getServicesList(String filename) {
206 File file = new File(filename);
207 LinkedList svcList = new LinkedList();
208 if(file.exists() && file.canRead()) {
209 // if we can read the file, do so into svcList
210 try {
211 BufferedReader reader = new BufferedReader(new FileReader(file));
212 while(reader.ready()) {
213 String line = reader.readLine();
214 // ignore comments
215 if(!line.startsWith("#")) {
216 svcList.add(line);
217 }
218 }
219 } catch(IOException e) {
220 System.out.println(e);
221 e.printStackTrace();
222 }
223 }
224 return svcList;
225 }
226
227 //---CONSTRUCTORS---
228
229 //---PUBLIC METHODS---
230
231 //---PRIVATE METHODS---
232
233 //---ACCESSOR/MUTATOR METHODS---
234
235 //---ATTRIBUTES---
236
237 //---STATIC ATTRIBUTES---
238
239 //---INNER CLASSES---
240
241 /**
242 * Inner class to provide a thread for running a Service.
243 */
244 private static class ServiceThread extends Thread {
245
246 // The constructor takes the name of the method we're gonna run
247 // and the arguments we're gonna pass into it
248 ServiceThread(Method mainMethod, Object[] args) {
249 _mainMethod = mainMethod;
250 _args = args;
251 }
252
253 // The main bit of the thread just starts the functionality of the given
254 // method running
255 public void run() {
256 try {
257 _mainMethod.invoke(null, _args);
258 } catch (Exception e){
259 System.out.println(e);
260 e.printStackTrace();
261 }
262 }
263
264 Method _mainMethod = null;
265 Object[] _args = null;
266 }
267
268 }