ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/componentmanager/ComponentManager.java
Revision: 1.39
Committed: Wed Mar 20 13:40:29 2002 UTC (22 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.38: +27 -6 lines
Log Message:
FilterManager's can now have their own individual configurations. I want to
run more than one, and I want them to have different setups. Specifying a
name for a FilterManager is similar to that of a Filter. There is a "-fm"
flag to the startup which allows you to set it. It will then request a
configuration of "FilterManager.<name>".

File Contents

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