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.35
Committed: Sat Mar 17 03:57:58 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.34: +4 -3 lines
Log Message:
Slightly more accurate output.

File Contents

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