1 |
tdb |
1.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 |
tdb |
1.3 |
import java.net.*; |
9 |
tdb |
1.1 |
|
10 |
|
|
/** |
11 |
|
|
* CORBA Services |
12 |
|
|
* |
13 |
tdb |
1.2 |
* @author $Author: tdb1 $ |
14 |
tdb |
1.3 |
* @version $Id: CorbaServices.java,v 1.2 2001/02/26 21:53:01 tdb1 Exp $ |
15 |
tdb |
1.1 |
*/ |
16 |
|
|
class CorbaServices { |
17 |
|
|
|
18 |
|
|
//---FINAL ATTRIBUTES--- |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* The current CVS revision of this class |
22 |
|
|
*/ |
23 |
tdb |
1.3 |
public static final String REVISION = "$Revision: 1.2 $"; |
24 |
tdb |
1.1 |
|
25 |
|
|
public static final String DEFAULTOKURLS = "./etc/okUrls.conf"; |
26 |
|
|
public static final String DEFAULTSERVICESCONF = "./etc/services.conf"; |
27 |
tdb |
1.2 |
public static final String DEFAULTWEBDIR = "./web"; |
28 |
tdb |
1.1 |
public static final int DEFAULTPORT = 8080; |
29 |
|
|
|
30 |
|
|
//---STATIC METHODS--- |
31 |
|
|
|
32 |
|
|
public static void main(String args[]) { |
33 |
|
|
|
34 |
tdb |
1.3 |
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 |
tdb |
1.1 |
|
40 |
|
|
String okUrls = DEFAULTOKURLS; |
41 |
|
|
String servicesConf = DEFAULTSERVICESCONF; |
42 |
tdb |
1.2 |
String webDir = DEFAULTWEBDIR; |
43 |
tdb |
1.1 |
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 |
tdb |
1.2 |
else if(args[i].equals("-w")) { |
55 |
|
|
i++; webDir = args[i]; |
56 |
|
|
} |
57 |
tdb |
1.1 |
else if(args[i].equals("-p")) { |
58 |
|
|
i++; port = Integer.parseInt(args[i]); |
59 |
|
|
} |
60 |
|
|
else { |
61 |
|
|
usage(); |
62 |
|
|
} |
63 |
|
|
} |
64 |
|
|
|
65 |
tdb |
1.3 |
System.out.println("--- Reading Configuration ---"); |
66 |
|
|
|
67 |
tdb |
1.1 |
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 |
tdb |
1.3 |
|
83 |
|
|
System.out.println("--- Starting CORBA Services ---"); |
84 |
|
|
|
85 |
tdb |
1.1 |
// 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 |
tdb |
1.3 |
String arglist = ""; |
101 |
tdb |
1.1 |
i = svcListParams[k].iterator(); |
102 |
|
|
int p = 0; |
103 |
|
|
while(i.hasNext()) { |
104 |
|
|
passedArgs[p] = (String) i.next(); |
105 |
tdb |
1.3 |
arglist += " " + passedArgs[p]; |
106 |
tdb |
1.1 |
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 |
tdb |
1.3 |
System.out.println(svcList[k]+arglist); |
123 |
tdb |
1.1 |
|
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 |
tdb |
1.3 |
|
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 |
tdb |
1.1 |
// start the mini-webserver |
146 |
tdb |
1.2 |
MiniWebServer mws = new MiniWebServer(port, okUrls, webDir); |
147 |
tdb |
1.1 |
mws.start(); |
148 |
tdb |
1.3 |
|
149 |
|
|
System.out.println("--- i-scream CORBA Services Ready ---"); |
150 |
tdb |
1.1 |
} |
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 |
tdb |
1.2 |
System.out.println(" -w <dir> - the location of the web directory"); |
161 |
|
|
System.out.println(" the default is ./web (no trailing /)"); |
162 |
tdb |
1.1 |
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 |
|
|
} |