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.1
Committed: Mon Feb 26 21:34:05 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Log Message:
Build files for the Corba Services manager.
CorbaServices loader, and mini webserver.

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