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