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.37
Committed: Mon Mar 19 19:14:25 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.36: +4 -4 lines
Log Message:
Changed a funny character (c) to a plain text (c).

File Contents

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