1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.ac.ukc.iscream.componentmanager; |
22 |
> |
package uk.org.iscream.cms.server.componentmanager; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
|
import java.util.*; |
26 |
|
import java.io.*; |
27 |
< |
import uk.ac.ukc.iscream.util.*; |
27 |
> |
import uk.org.iscream.cms.util.*; |
28 |
|
|
29 |
|
/** |
30 |
|
* The component manager is the starting point for all |
32 |
|
* It loads its initial system configuration from the |
33 |
|
* default properties file, it then starts all the iscream |
34 |
|
* components as specified in the default.properties under |
35 |
< |
* uk.ac.ukc.iscream.ComponentList |
35 |
> |
* uk.org.iscream.cms.server.ComponentList |
36 |
|
* |
37 |
|
* @author $Author$ |
38 |
|
* @version $Id$ |
59 |
|
public static final String DEFAULTPROPERTIES = "./etc/default.properties"; |
60 |
|
|
61 |
|
/** |
62 |
< |
* The default time to wait before retrying |
62 |
> |
* The default time to wait before retrying |
63 |
|
* component. |
64 |
|
*/ |
65 |
|
public static final int DEFAULT_COMPONENT_START_TIMEOUT = 5; |
73 |
|
* @param args the command line arguments |
74 |
|
*/ |
75 |
|
public static void main(String[] args) { |
76 |
+ |
System.out.println("-----------------------------------------"); |
77 |
|
System.out.println("--- i-scream Server Component Manager ---"); |
78 |
< |
System.out.println("--- Starting System ---"); |
78 |
> |
System.out.println("--- (c) 2001 The i-scream Project ---"); |
79 |
> |
System.out.println("--- (http://www.i-scream.org) ---"); |
80 |
> |
System.out.println("-----------------------------------------"); |
81 |
> |
System.out.println("--- Starting System ---"); |
82 |
|
|
83 |
|
// get the command line args |
84 |
|
String defaultProperties = DEFAULTPROPERTIES; |
85 |
|
String filterName = null; |
86 |
+ |
String filterManagerName = null; |
87 |
+ |
String clientInterfaceName = null; |
88 |
|
for(int i=0; i < args.length; i++) { |
89 |
|
if(args[i].equals("-h")) { |
90 |
|
usage(); |
91 |
|
} |
92 |
|
else if(args[i].equals("-f")) { |
93 |
< |
i++; filterName = args[i]; |
93 |
> |
if(++i < args.length) { |
94 |
> |
filterName = args[i]; |
95 |
> |
} |
96 |
> |
else { |
97 |
> |
usage(); |
98 |
> |
} |
99 |
|
} |
100 |
+ |
else if(args[i].equals("-fm")) { |
101 |
+ |
if(++i < args.length) { |
102 |
+ |
filterManagerName = args[i]; |
103 |
+ |
} |
104 |
+ |
else { |
105 |
+ |
usage(); |
106 |
+ |
} |
107 |
+ |
} |
108 |
+ |
else if(args[i].equals("-ci")) { |
109 |
+ |
if(++i < args.length) { |
110 |
+ |
clientInterfaceName = args[i]; |
111 |
+ |
} |
112 |
+ |
else { |
113 |
+ |
usage(); |
114 |
+ |
} |
115 |
+ |
} |
116 |
|
else if(args[i].equals("-l")) { |
117 |
< |
i++; defaultProperties = args[i]; |
117 |
> |
if(++i < args.length) { |
118 |
> |
defaultProperties = args[i]; |
119 |
> |
} |
120 |
> |
else { |
121 |
> |
usage(); |
122 |
> |
} |
123 |
|
} |
124 |
|
else { |
125 |
|
usage(); |
148 |
|
refman.activatePOA(); |
149 |
|
|
150 |
|
// get the list of components |
151 |
< |
String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList"); |
151 |
> |
String componentList = System.getProperty("uk.org.iscream.cms.server.ComponentList"); |
152 |
|
StringTokenizer st = new StringTokenizer(componentList, ";"); |
153 |
< |
_componentsToStart = new ArrayList(); |
153 |
> |
_componentsToStart = new LinkedList(); |
154 |
|
|
155 |
|
// this could be done using reflection |
156 |
|
// but..well..we don't ;-p |
161 |
|
|
162 |
|
// ### This is where the list of supported components is checked! ### |
163 |
|
if (componentName.equalsIgnoreCase("core")) { |
164 |
< |
component = new uk.ac.ukc.iscream.core.Core(); |
164 |
> |
component = new uk.org.iscream.cms.server.core.Core(); |
165 |
> |
// note the passing of the FilterManagers's name in its constructor |
166 |
|
} else if (componentName.equalsIgnoreCase("filtermanager")) { |
167 |
< |
component = new uk.ac.ukc.iscream.filtermanager.FilterManager(); |
167 |
> |
component = new uk.org.iscream.cms.server.filtermanager.FilterManager(filterManagerName); |
168 |
|
} else if (componentName.equalsIgnoreCase("rootfilter")) { |
169 |
< |
component = new uk.ac.ukc.iscream.rootfilter.RootFilter(); |
117 |
< |
} else if (componentName.equalsIgnoreCase("dbinterface")) { |
118 |
< |
component = new uk.ac.ukc.iscream.dbinterface.DBInterface(); |
169 |
> |
component = new uk.org.iscream.cms.server.rootfilter.RootFilter(); |
170 |
|
} else if (componentName.equalsIgnoreCase("clientinterface")) { |
171 |
< |
component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain(); |
171 |
> |
component = new uk.org.iscream.cms.server.clientinterface.ClientInterfaceMain(clientInterfaceName); |
172 |
|
// note the passing of the Filter's name in its constructor |
173 |
|
} else if (componentName.equalsIgnoreCase("filter")) { |
174 |
< |
component = new uk.ac.ukc.iscream.filter.FilterMain(filterName); |
174 |
> |
component = new uk.org.iscream.cms.server.filter.FilterMain(filterName); |
175 |
|
} else if (componentName.equalsIgnoreCase("client")) { |
176 |
< |
component = new uk.ac.ukc.iscream.client.ClientMain(); |
176 |
> |
component = new uk.org.iscream.cms.server.client.ClientMain(); |
177 |
|
} |
178 |
|
// ### Add new component constructors in the above section! ### |
179 |
|
|
180 |
|
// build the list of components to start |
181 |
|
if (component != null) { |
182 |
< |
_componentsToStart.add(component); |
182 |
> |
_componentsToStart.add(component); |
183 |
|
} else { |
184 |
< |
System.err.println(toString + ": WARNING unsupported component not started"); |
184 |
> |
System.err.println(toString + ": WARNING unsupported component not started: "+componentName); |
185 |
|
} |
186 |
|
} |
187 |
|
|
191 |
|
|
192 |
|
String confTimeout = null; |
193 |
|
try { |
194 |
< |
confTimeout = System.getProperty("uk.ac.ukc.iscream.ComponentTimeout"); |
194 |
> |
confTimeout = System.getProperty("uk.org.iscream.cms.server.ComponentTimeout"); |
195 |
|
confTimeout.trim(); |
196 |
|
_startTimeout = Integer.parseInt(confTimeout); |
197 |
|
} catch (NumberFormatException e) { |
198 |
|
_startTimeout = DEFAULT_COMPONENT_START_TIMEOUT; |
199 |
< |
System.err.println(toString + ": unable to read uk.ac.ukc.iscream.ComponentTimeout value (" + confTimeout + "), using default!"); |
199 |
> |
System.err.println(toString + ": unable to read uk.org.iscream.cms.server.ComponentTimeout value (" + confTimeout + "), using default!"); |
200 |
|
} |
201 |
|
System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds"); |
202 |
|
|
203 |
|
// startup the system components |
204 |
|
startUp(); |
205 |
|
|
206 |
< |
// block on the ORB...in time, management functionality can be placed here. |
207 |
< |
// if we detect a CORBA communication error, we'll restart all the components. |
208 |
< |
while(true) { |
209 |
< |
try { |
206 |
> |
// block on the ORB...in time, management functionality can be placed here. |
207 |
> |
// if we detect a CORBA communication error, we'll restart all the components. |
208 |
> |
// !! this doesn't appear to work !! |
209 |
> |
while(true) { |
210 |
> |
try { |
211 |
|
refman.getORB().run(); |
212 |
|
} catch (org.omg.CORBA.COMM_FAILURE e) { |
213 |
|
System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage()); |
222 |
|
* This method calls the start() methods on all the components. |
223 |
|
* If a component fails to start due to a CORBA communication |
224 |
|
* problem, then it catches this and tries to start it again |
225 |
< |
* according to uk.ac.ukc.iscream.ComponentTimeout time. |
225 |
> |
* according to uk.org.iscream.cms.server.ComponentTimeout time. |
226 |
|
* |
227 |
|
* If the server dies and CORBA connections are lost, this method |
228 |
|
* is called again. |
229 |
|
*/ |
230 |
|
private static void startUp() { |
231 |
< |
// now we try and start the beast up |
231 |
> |
// now we try and start the beast up |
232 |
|
boolean tryAgain = true; |
233 |
|
Component component = null; |
234 |
|
|
236 |
|
// maybe add support for a limited number of retries |
237 |
|
while(tryAgain) { |
238 |
|
Iterator i = _componentsToStart.iterator(); |
239 |
< |
ArrayList failedComponents = new ArrayList(); |
239 |
> |
LinkedList failedComponents = new LinkedList(); |
240 |
|
// go through all the components |
241 |
|
while(i.hasNext()) { |
242 |
< |
try { |
243 |
< |
component = (Component) i.next(); |
244 |
< |
System.out.println(toString + ": starting component - " + component.toString()); |
245 |
< |
|
246 |
< |
// start the component |
247 |
< |
component.start(); |
248 |
< |
|
249 |
< |
// if we get this then there was a problem |
250 |
< |
// that we can't recover from |
251 |
< |
} catch (ComponentStartException e) { |
252 |
< |
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
253 |
< |
System.err.println(toString + ": component reports - " + e.getMessage()); |
254 |
< |
System.exit(1); |
255 |
< |
|
256 |
< |
// if we get this exception then we've tried |
257 |
< |
// to talk to something which may not be up yet |
258 |
< |
// so we want to try again in a minute |
259 |
< |
} catch(ComponentCORBAException e2) { |
260 |
< |
System.err.println(toString + ": WARNING Component reported CORBA communications failure"); |
242 |
> |
// get a refence to the component |
243 |
> |
component = (Component) i.next(); |
244 |
> |
System.out.println(toString + ": dependency checking component - " + component.toString()); |
245 |
> |
|
246 |
> |
// check it's dependencies |
247 |
> |
boolean depOK = component.depCheck(); |
248 |
> |
if(depOK) { |
249 |
> |
System.out.println(toString + ": starting component - " + component.toString()); |
250 |
> |
// it should be ok to start the component |
251 |
> |
try { |
252 |
> |
// start the component |
253 |
> |
component.start(); |
254 |
> |
} catch (ComponentStartException e) { |
255 |
> |
// if we get this then there was a problem |
256 |
> |
// that we can't recover from |
257 |
> |
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
258 |
> |
System.err.println(toString + ": component reports - " + e.getMessage()); |
259 |
> |
System.exit(1); |
260 |
> |
} |
261 |
> |
} |
262 |
> |
else { |
263 |
> |
// it seems the depedencies failed |
264 |
> |
// so we want to try again after a delay |
265 |
> |
System.err.println(toString + ": WARNING Component reported dependency failure"); |
266 |
|
System.err.println(toString + ": This could be because it can't communicate with components it needs."); |
210 |
– |
System.err.println(toString + ": component reports - " + e2.getMessage()); |
267 |
|
|
268 |
|
// make a list of the failed components |
269 |
|
failedComponents.add(component); |
279 |
|
_componentsToStart = failedComponents; |
280 |
|
|
281 |
|
// sleep for a given timeout |
282 |
< |
try { |
282 |
> |
try { |
283 |
|
Thread.sleep(_startTimeout * 1000); |
284 |
|
} catch (InterruptedException e) { |
285 |
|
// we're not bothered |
290 |
|
tryAgain = false; |
291 |
|
} |
292 |
|
} |
293 |
< |
|
294 |
< |
System.out.println(toString + ": running"); |
295 |
< |
} |
293 |
> |
|
294 |
> |
System.out.println(toString + ": running"); |
295 |
> |
} |
296 |
|
|
297 |
|
/** |
298 |
|
* A simple method to print the usage of this class. |
301 |
|
* properly. |
302 |
|
*/ |
303 |
|
public static void usage() { |
304 |
< |
System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>"); |
304 |
> |
System.out.println("USAGE: java uk.org.iscream.cms.server.componentmanager.ComponentManager <option>"); |
305 |
|
System.out.println(" or: java -jar iscream.jar <option>"); |
306 |
|
System.out.println("WHERE <option>:"); |
307 |
|
System.out.println(" -l <filename> - the location of initial system properties"); |
308 |
|
System.out.println(" the default is ./etc/default.properties"); |
309 |
|
System.out.println(" -f <name> - the name of the filter (if there is one configured"); |
310 |
+ |
System.out.println(" -fm <name> - the name of the filter manager (if there is one configured"); |
311 |
+ |
System.out.println(" -ci <name> - the name of the client interface (if there is one configured"); |
312 |
|
System.out.println(" -h - this help screen"); |
313 |
|
System.exit(1); |
314 |
|
} |
325 |
|
|
326 |
|
//---STATIC ATTRIBUTES--- |
327 |
|
|
328 |
< |
private static ArrayList _componentsToStart; |
328 |
> |
private static LinkedList _componentsToStart; |
329 |
|
private static int _startTimeout = 0; |
330 |
|
|
331 |
|
} |