1 |
tdb |
1.40 |
/* |
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 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
21 |
tdb |
1.38 |
package uk.org.iscream.cms.server.componentmanager; |
22 |
ajm |
1.1 |
|
23 |
|
|
//---IMPORTS--- |
24 |
|
|
import java.util.*; |
25 |
|
|
import java.io.*; |
26 |
tdb |
1.38 |
import uk.org.iscream.cms.server.util.*; |
27 |
ajm |
1.1 |
|
28 |
|
|
/** |
29 |
ajm |
1.2 |
* The component manager is the starting point for all |
30 |
|
|
* server side components of the iscream system. |
31 |
|
|
* It loads its initial system configuration from the |
32 |
|
|
* default properties file, it then starts all the iscream |
33 |
|
|
* components as specified in the default.properties under |
34 |
tdb |
1.38 |
* uk.org.iscream.cms.server.ComponentList |
35 |
ajm |
1.1 |
* |
36 |
tdb |
1.39 |
* @author $Author: tdb $ |
37 |
tdb |
1.40 |
* @version $Id: ComponentManager.java,v 1.39 2002/03/20 13:40:29 tdb Exp $ |
38 |
ajm |
1.1 |
*/ |
39 |
|
|
public class ComponentManager { |
40 |
|
|
|
41 |
|
|
//---FINAL ATTRIBUTES--- |
42 |
|
|
|
43 |
|
|
/** |
44 |
|
|
* The current CVS revision of this class |
45 |
|
|
*/ |
46 |
tdb |
1.40 |
public static final String REVISION = "$Revision: 1.39 $"; |
47 |
ajm |
1.1 |
|
48 |
|
|
/** |
49 |
|
|
* The toString() of this class |
50 |
|
|
* As it won't be instatiated, this is needed. |
51 |
ajm |
1.2 |
* Not also that we pass a null as the class name (as we are static) |
52 |
ajm |
1.1 |
*/ |
53 |
ajm |
1.2 |
public static final String toString = FormatName.getName("ComponentManager", null, REVISION); |
54 |
ajm |
1.1 |
|
55 |
|
|
/** |
56 |
|
|
* The default location of the properties file for the system |
57 |
|
|
*/ |
58 |
ajm |
1.2 |
public static final String DEFAULTPROPERTIES = "./etc/default.properties"; |
59 |
ajm |
1.1 |
|
60 |
ajm |
1.22 |
/** |
61 |
|
|
* The default time to wait before retrying |
62 |
|
|
* component. |
63 |
|
|
*/ |
64 |
|
|
public static final int DEFAULT_COMPONENT_START_TIMEOUT = 5; |
65 |
|
|
|
66 |
ajm |
1.1 |
//---STATIC METHODS--- |
67 |
|
|
|
68 |
|
|
/** |
69 |
ajm |
1.2 |
* The main method which starts the components as |
70 |
|
|
* listed in the default.properties file. |
71 |
ajm |
1.1 |
* |
72 |
|
|
* @param args the command line arguments |
73 |
|
|
*/ |
74 |
|
|
public static void main(String[] args) { |
75 |
ajm |
1.36 |
System.out.println("-----------------------------------------"); |
76 |
tdb |
1.11 |
System.out.println("--- i-scream Server Component Manager ---"); |
77 |
tdb |
1.37 |
System.out.println("--- (c) 2001 The i-scream Project ---"); |
78 |
ajm |
1.36 |
System.out.println("--- (http://www.i-scream.org.uk) ---"); |
79 |
|
|
System.out.println("-----------------------------------------"); |
80 |
ajm |
1.2 |
System.out.println("--- Starting System ---"); |
81 |
|
|
|
82 |
ajm |
1.1 |
// get the command line args |
83 |
|
|
String defaultProperties = DEFAULTPROPERTIES; |
84 |
|
|
String filterName = null; |
85 |
tdb |
1.39 |
String filterManagerName = null; |
86 |
tdb |
1.11 |
for(int i=0; i < args.length; i++) { |
87 |
tdb |
1.12 |
if(args[i].equals("-h")) { |
88 |
ajm |
1.1 |
usage(); |
89 |
tdb |
1.11 |
} |
90 |
tdb |
1.12 |
else if(args[i].equals("-f")) { |
91 |
tdb |
1.39 |
if(++i < args.length) { |
92 |
|
|
filterName = args[i]; |
93 |
|
|
} |
94 |
|
|
else { |
95 |
|
|
usage(); |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
else if(args[i].equals("-fm")) { |
99 |
|
|
if(++i < args.length) { |
100 |
|
|
filterManagerName = args[i]; |
101 |
|
|
} |
102 |
|
|
else { |
103 |
|
|
usage(); |
104 |
|
|
} |
105 |
tdb |
1.11 |
} |
106 |
tdb |
1.12 |
else if(args[i].equals("-l")) { |
107 |
tdb |
1.39 |
if(++i < args.length) { |
108 |
|
|
defaultProperties = args[i]; |
109 |
|
|
} |
110 |
|
|
else { |
111 |
|
|
usage(); |
112 |
|
|
} |
113 |
tdb |
1.11 |
} |
114 |
|
|
else { |
115 |
|
|
usage(); |
116 |
|
|
} |
117 |
ajm |
1.1 |
} |
118 |
|
|
|
119 |
|
|
// load the default properties file into the system properties |
120 |
|
|
System.out.println(toString + ": initialising - using " + defaultProperties); |
121 |
|
|
try { |
122 |
|
|
Properties initProperties = new Properties(System.getProperties()); |
123 |
|
|
initProperties.load(new FileInputStream(new File(defaultProperties))); |
124 |
|
|
System.setProperties(initProperties); |
125 |
|
|
} catch (Exception e) { |
126 |
|
|
System.err.println(toString + ": ERROR " + e.getMessage()); |
127 |
|
|
usage(); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
// continue to bring the system up |
131 |
|
|
System.out.println(toString + ": coming up"); |
132 |
|
|
|
133 |
|
|
// start the ORB by initialising the ReferenceManager |
134 |
ajm |
1.2 |
ReferenceManager refman = ReferenceManager.getInstance(); |
135 |
ajm |
1.1 |
|
136 |
ajm |
1.2 |
// now the ORB is running, we need to activate our RootPOA |
137 |
|
|
// so that we can start serving requests once servants start up |
138 |
ajm |
1.1 |
refman.activatePOA(); |
139 |
|
|
|
140 |
ajm |
1.2 |
// get the list of components |
141 |
tdb |
1.38 |
String componentList = System.getProperty("uk.org.iscream.cms.server.ComponentList"); |
142 |
ajm |
1.1 |
StringTokenizer st = new StringTokenizer(componentList, ";"); |
143 |
tdb |
1.33 |
_componentsToStart = new LinkedList(); |
144 |
ajm |
1.13 |
|
145 |
ajm |
1.1 |
// this could be done using reflection |
146 |
|
|
// but..well..we don't ;-p |
147 |
|
|
while (st.hasMoreTokens()){ |
148 |
|
|
String componentName = st.nextToken(); |
149 |
|
|
Component component = null; |
150 |
ajm |
1.13 |
|
151 |
ajm |
1.2 |
|
152 |
|
|
// ### This is where the list of supported components is checked! ### |
153 |
|
|
if (componentName.equalsIgnoreCase("core")) { |
154 |
tdb |
1.38 |
component = new uk.org.iscream.cms.server.core.Core(); |
155 |
tdb |
1.39 |
// note the passing of the FilterManagers's name in its constructor |
156 |
ajm |
1.3 |
} else if (componentName.equalsIgnoreCase("filtermanager")) { |
157 |
tdb |
1.39 |
component = new uk.org.iscream.cms.server.filtermanager.FilterManager(filterManagerName); |
158 |
ajm |
1.4 |
} else if (componentName.equalsIgnoreCase("rootfilter")) { |
159 |
tdb |
1.38 |
component = new uk.org.iscream.cms.server.rootfilter.RootFilter(); |
160 |
ajm |
1.5 |
} else if (componentName.equalsIgnoreCase("dbinterface")) { |
161 |
tdb |
1.38 |
component = new uk.org.iscream.cms.server.dbinterface.DBInterface(); |
162 |
ajm |
1.6 |
} else if (componentName.equalsIgnoreCase("clientinterface")) { |
163 |
tdb |
1.38 |
component = new uk.org.iscream.cms.server.clientinterface.ClientInterfaceMain(); |
164 |
ajm |
1.7 |
// note the passing of the Filter's name in its constructor |
165 |
|
|
} else if (componentName.equalsIgnoreCase("filter")) { |
166 |
tdb |
1.38 |
component = new uk.org.iscream.cms.server.filter.FilterMain(filterName); |
167 |
tdb |
1.30 |
} else if (componentName.equalsIgnoreCase("client")) { |
168 |
tdb |
1.38 |
component = new uk.org.iscream.cms.server.client.ClientMain(); |
169 |
ajm |
1.1 |
} |
170 |
ajm |
1.2 |
// ### Add new component constructors in the above section! ### |
171 |
ajm |
1.3 |
|
172 |
ajm |
1.22 |
// build the list of components to start |
173 |
ajm |
1.1 |
if (component != null) { |
174 |
ajm |
1.32 |
_componentsToStart.add(component); |
175 |
ajm |
1.13 |
} else { |
176 |
tdb |
1.33 |
System.err.println(toString + ": WARNING unsupported component not started: "+componentName); |
177 |
ajm |
1.13 |
} |
178 |
|
|
} |
179 |
|
|
|
180 |
ajm |
1.32 |
|
181 |
ajm |
1.22 |
|
182 |
|
|
// get the value for timeout |
183 |
ajm |
1.32 |
|
184 |
ajm |
1.28 |
String confTimeout = null; |
185 |
ajm |
1.22 |
try { |
186 |
tdb |
1.38 |
confTimeout = System.getProperty("uk.org.iscream.cms.server.ComponentTimeout"); |
187 |
ajm |
1.29 |
confTimeout.trim(); |
188 |
ajm |
1.32 |
_startTimeout = Integer.parseInt(confTimeout); |
189 |
ajm |
1.22 |
} catch (NumberFormatException e) { |
190 |
ajm |
1.32 |
_startTimeout = DEFAULT_COMPONENT_START_TIMEOUT; |
191 |
tdb |
1.38 |
System.err.println(toString + ": unable to read uk.org.iscream.cms.server.ComponentTimeout value (" + confTimeout + "), using default!"); |
192 |
ajm |
1.22 |
} |
193 |
ajm |
1.32 |
System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds"); |
194 |
ajm |
1.22 |
|
195 |
ajm |
1.31 |
// startup the system components |
196 |
|
|
startUp(); |
197 |
|
|
|
198 |
|
|
// block on the ORB...in time, management functionality can be placed here. |
199 |
|
|
// if we detect a CORBA communication error, we'll restart all the components. |
200 |
tdb |
1.33 |
// !! this doesn't appear to work !! |
201 |
ajm |
1.31 |
while(true) { |
202 |
|
|
try { |
203 |
|
|
refman.getORB().run(); |
204 |
ajm |
1.32 |
} catch (org.omg.CORBA.COMM_FAILURE e) { |
205 |
ajm |
1.31 |
System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage()); |
206 |
|
|
System.out.println(toString + ": WARNING CORBA connections have been lost - attempting to restart!"); |
207 |
|
|
} |
208 |
|
|
startUp(); |
209 |
|
|
} |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
/** |
213 |
|
|
* Starts the components as obtained from the configuration. |
214 |
|
|
* This method calls the start() methods on all the components. |
215 |
|
|
* If a component fails to start due to a CORBA communication |
216 |
|
|
* problem, then it catches this and tries to start it again |
217 |
tdb |
1.38 |
* according to uk.org.iscream.cms.server.ComponentTimeout time. |
218 |
ajm |
1.31 |
* |
219 |
|
|
* If the server dies and CORBA connections are lost, this method |
220 |
|
|
* is called again. |
221 |
|
|
*/ |
222 |
|
|
private static void startUp() { |
223 |
ajm |
1.32 |
// now we try and start the beast up |
224 |
|
|
boolean tryAgain = true; |
225 |
|
|
Component component = null; |
226 |
|
|
|
227 |
ajm |
1.22 |
// keep trying until we've started all the components. |
228 |
|
|
// maybe add support for a limited number of retries |
229 |
ajm |
1.13 |
while(tryAgain) { |
230 |
ajm |
1.32 |
Iterator i = _componentsToStart.iterator(); |
231 |
tdb |
1.33 |
LinkedList failedComponents = new LinkedList(); |
232 |
ajm |
1.22 |
// go through all the components |
233 |
ajm |
1.13 |
while(i.hasNext()) { |
234 |
tdb |
1.33 |
// get a refence to the component |
235 |
|
|
component = (Component) i.next(); |
236 |
tdb |
1.35 |
System.out.println(toString + ": dependency checking component - " + component.toString()); |
237 |
tdb |
1.33 |
|
238 |
|
|
// check it's dependencies |
239 |
|
|
boolean depOK = component.depCheck(); |
240 |
|
|
if(depOK) { |
241 |
tdb |
1.35 |
System.out.println(toString + ": starting component - " + component.toString()); |
242 |
tdb |
1.33 |
// it should be ok to start the component |
243 |
|
|
try { |
244 |
|
|
// start the component |
245 |
|
|
component.start(); |
246 |
|
|
} catch (ComponentStartException e) { |
247 |
|
|
// if we get this then there was a problem |
248 |
|
|
// that we can't recover from |
249 |
|
|
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
250 |
|
|
System.err.println(toString + ": component reports - " + e.getMessage()); |
251 |
|
|
System.exit(1); |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
else { |
255 |
|
|
// it seems the depedencies failed |
256 |
|
|
// so we want to try again after a delay |
257 |
|
|
System.err.println(toString + ": WARNING Component reported dependency failure"); |
258 |
ajm |
1.14 |
System.err.println(toString + ": This could be because it can't communicate with components it needs."); |
259 |
ajm |
1.22 |
|
260 |
|
|
// make a list of the failed components |
261 |
ajm |
1.20 |
failedComponents.add(component); |
262 |
ajm |
1.1 |
} |
263 |
ajm |
1.13 |
} |
264 |
ajm |
1.22 |
|
265 |
|
|
// if we had some failed components that we can retry |
266 |
ajm |
1.21 |
if (failedComponents.size() > 0) { |
267 |
ajm |
1.14 |
System.err.println(toString + ": WARNING One or more components failed to start correctly."); |
268 |
ajm |
1.32 |
System.err.println(toString + ": Will try again in " + _startTimeout + " seconds"); |
269 |
ajm |
1.22 |
|
270 |
|
|
// our list is now the failed list |
271 |
ajm |
1.32 |
_componentsToStart = failedComponents; |
272 |
ajm |
1.22 |
|
273 |
|
|
// sleep for a given timeout |
274 |
ajm |
1.18 |
try { |
275 |
ajm |
1.32 |
Thread.sleep(_startTimeout * 1000); |
276 |
ajm |
1.17 |
} catch (InterruptedException e) { |
277 |
|
|
// we're not bothered |
278 |
|
|
} |
279 |
ajm |
1.22 |
// otherwise we started everything |
280 |
ajm |
1.18 |
} else { |
281 |
ajm |
1.22 |
// so we set to exit the loop |
282 |
ajm |
1.18 |
tryAgain = false; |
283 |
ajm |
1.1 |
} |
284 |
|
|
} |
285 |
ajm |
1.13 |
|
286 |
ajm |
1.3 |
System.out.println(toString + ": running"); |
287 |
ajm |
1.31 |
} |
288 |
ajm |
1.3 |
|
289 |
|
|
/** |
290 |
ajm |
1.1 |
* A simple method to print the usage of this class. |
291 |
|
|
* It never returns, but instead exits to the system |
292 |
|
|
* with a value 1, to indicate the system did not start |
293 |
|
|
* properly. |
294 |
|
|
*/ |
295 |
|
|
public static void usage() { |
296 |
tdb |
1.38 |
System.out.println("USAGE: java uk.org.iscream.cms.server.componentmanager.ComponentManager <option>"); |
297 |
tdb |
1.8 |
System.out.println(" or: java -jar iscream.jar <option>"); |
298 |
ajm |
1.1 |
System.out.println("WHERE <option>:"); |
299 |
|
|
System.out.println(" -l <filename> - the location of initial system properties"); |
300 |
ajm |
1.2 |
System.out.println(" the default is ./etc/default.properties"); |
301 |
ajm |
1.1 |
System.out.println(" -f <name> - the name of the filter (if there is one configured"); |
302 |
tdb |
1.39 |
System.out.println(" -fm <name> - the name of the filter manager (if there is one configured"); |
303 |
ajm |
1.1 |
System.out.println(" -h - this help screen"); |
304 |
|
|
System.exit(1); |
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
//---CONSTRUCTORS--- |
308 |
|
|
|
309 |
|
|
//---PUBLIC METHODS--- |
310 |
|
|
|
311 |
|
|
//---PRIVATE METHODS--- |
312 |
|
|
|
313 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
314 |
|
|
|
315 |
|
|
//---ATTRIBUTES--- |
316 |
|
|
|
317 |
|
|
//---STATIC ATTRIBUTES--- |
318 |
ajm |
1.32 |
|
319 |
tdb |
1.33 |
private static LinkedList _componentsToStart; |
320 |
ajm |
1.32 |
private static int _startTimeout = 0; |
321 |
ajm |
1.1 |
|
322 |
|
|
} |