8 |
|
import java.net.*; |
9 |
|
|
10 |
|
/** |
11 |
< |
* CORBA Services |
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$ |
20 |
|
* @version $Id$ |
21 |
|
*/ |
28 |
|
*/ |
29 |
|
public static final String REVISION = "$Revision$"; |
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 |
< |
|
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; |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
+ |
// Read in the services configuration |
93 |
|
System.out.println("--- Reading Configuration ---"); |
94 |
|
|
95 |
|
LinkedList serviceList = getServicesList(servicesConf); |
108 |
|
j++; |
109 |
|
} |
110 |
|
|
111 |
+ |
// Start the services one by one |
112 |
|
System.out.println("--- Starting CORBA Services ---"); |
113 |
|
|
85 |
– |
// start the services |
114 |
|
try { |
115 |
< |
|
116 |
< |
// get hook on the runtime |
115 |
> |
|
116 |
> |
// get hooks on the system loaders |
117 |
|
Runtime myRuntime = Runtime.getRuntime(); |
90 |
– |
// get hook on the system Class loader |
118 |
|
ClassLoader myClassLoader = ClassLoader.getSystemClassLoader(); |
119 |
|
|
120 |
< |
// step through each app, and start it rolling |
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 |
< |
// and we don't support passing of individual args, but we will ;-) so its just null |
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; |
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 |
< |
ApplicationThread anApp = new ApplicationThread(myMethod, passedArgsObject); |
146 |
> |
ServiceThread aSvc = new ServiceThread(myMethod, passedArgsObject); |
147 |
|
|
148 |
|
// Finally we start it going |
149 |
< |
anApp.start(); |
150 |
< |
System.out.println(svcList[k]+arglist); |
123 |
< |
|
124 |
< |
// Now we go and start the rest of the Apps listed |
149 |
> |
aSvc.start(); |
150 |
> |
System.out.println(svcList[k]+arglist); |
151 |
|
} |
152 |
|
|
153 |
|
} catch (Exception e) { |
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(); |
175 |
|
|
176 |
|
System.out.println("--- i-scream CORBA Services Ready ---"); |
177 |
|
} |
178 |
< |
|
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>"); |
194 |
|
System.out.println(" -h - this help screen"); |
195 |
|
System.exit(1); |
196 |
|
} |
197 |
< |
|
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 |
|
} |
237 |
|
//---STATIC ATTRIBUTES--- |
238 |
|
|
239 |
|
//---INNER CLASSES--- |
240 |
< |
|
241 |
< |
private static class ApplicationThread extends Thread { |
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 |
< |
ApplicationThread(Method mainMethod, Object[] args) { |
248 |
> |
ServiceThread(Method mainMethod, Object[] args) { |
249 |
|
_mainMethod = mainMethod; |
250 |
|
_args = args; |
251 |
|
} |