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.23
Committed: Fri Feb 23 17:48:36 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.22: +3 -3 lines
Log Message:
bug fix

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.componentmanager;
3    
4     //---IMPORTS---
5     import java.util.*;
6     import java.io.*;
7 tdb 1.10 import uk.ac.ukc.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     * uk.ac.ukc.iscream.ComponentList
16 ajm 1.1 *
17 ajm 1.14 * @author $Author: ajm4 $
18 ajm 1.23 * @version $Id: ComponentManager.java,v 1.22 2001/02/23 17:47:21 ajm4 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 ajm 1.23 public static final String REVISION = "$Revision: 1.22 $";
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 ajm 1.1 String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList");
100     StringTokenizer st = new StringTokenizer(componentList, ";");
101 ajm 1.13 ArrayList componentsToStart = new ArrayList();
102    
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 ajm 1.1 component = new uk.ac.ukc.iscream.core.Core();
113 ajm 1.3 } else if (componentName.equalsIgnoreCase("filtermanager")) {
114     component = new uk.ac.ukc.iscream.filtermanager.FilterManager();
115 ajm 1.4 } else if (componentName.equalsIgnoreCase("rootfilter")) {
116     component = new uk.ac.ukc.iscream.rootfilter.RootFilter();
117 ajm 1.5 } else if (componentName.equalsIgnoreCase("dbinterface")) {
118     component = new uk.ac.ukc.iscream.dbinterface.DBInterface();
119 ajm 1.6 } else if (componentName.equalsIgnoreCase("clientinterface")) {
120     component = new uk.ac.ukc.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     component = new uk.ac.ukc.iscream.filter.FilterMain(filterName);
124 ajm 1.1 }
125 ajm 1.2 // ### Add new component constructors in the above section! ###
126 ajm 1.3
127 ajm 1.22 // build the list of components to start
128 ajm 1.1 if (component != null) {
129 ajm 1.13 componentsToStart.add(component);
130     } else {
131     System.err.println(toString + ": WARNING unsupported component not started");
132     }
133     }
134    
135 ajm 1.22 // now we try and start the beast up
136 ajm 1.13 boolean tryAgain = true;
137 ajm 1.15 Component component = null;
138 ajm 1.22
139     // get the value for timeout
140     int startTimeout;
141     try {
142     startTimeout = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.ComponentTimeout"));
143     } catch (NumberFormatException e) {
144     startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
145 ajm 1.23 System.err.println(toString + ": invalid value for ComponentTimeout, using default value of " + startTimeout + " seconds!");
146 ajm 1.22 }
147    
148     // keep trying until we've started all the components.
149     // maybe add support for a limited number of retries
150 ajm 1.13 while(tryAgain) {
151     Iterator i = componentsToStart.iterator();
152 ajm 1.19 ArrayList failedComponents = new ArrayList();
153 ajm 1.22 // go through all the components
154 ajm 1.13 while(i.hasNext()) {
155     try {
156 ajm 1.16 component = (Component) i.next();
157 ajm 1.13 System.out.println(toString + ": starting component - " + component.toString());
158 ajm 1.22
159     // start the component
160 ajm 1.2 component.start();
161 ajm 1.22
162     // if we get this then there was a problem
163     // that we can't recover from
164 ajm 1.2 } catch (ComponentStartException e) {
165 ajm 1.14 System.err.println(toString + ": ERROR starting component - " + component.toString());
166 ajm 1.2 System.err.println(toString + ": component reports - " + e.getMessage());
167 ajm 1.1 System.exit(1);
168 ajm 1.22
169     // if we get this exception then we've tried
170     // to talk to something which may not be up yet
171     // so we want to try again in a minute
172 ajm 1.14 } catch(ComponentCORBAException e2) {
173     System.err.println(toString + ": WARNING Component reported CORBA communications failure");
174     System.err.println(toString + ": This could be because it can't communicate with components it needs.");
175 ajm 1.13 System.err.println(toString + ": component reports - " + e2.getMessage());
176 ajm 1.22
177     // make a list of the failed components
178 ajm 1.20 failedComponents.add(component);
179 ajm 1.1 }
180 ajm 1.13 }
181 ajm 1.22
182     // if we had some failed components that we can retry
183 ajm 1.21 if (failedComponents.size() > 0) {
184 ajm 1.14 System.err.println(toString + ": WARNING One or more components failed to start correctly.");
185 ajm 1.22 System.err.println(toString + ": Will try again in " + startTimeout + " seconds");
186    
187     // our list is now the failed list
188     componentsToStart = failedComponents;
189    
190     // sleep for a given timeout
191 ajm 1.18 try {
192 ajm 1.22 Thread.sleep(startTimeout * 1000);
193 ajm 1.17 } catch (InterruptedException e) {
194     // we're not bothered
195     }
196 ajm 1.22 // otherwise we started everything
197 ajm 1.18 } else {
198 ajm 1.22 // so we set to exit the loop
199 ajm 1.18 tryAgain = false;
200 ajm 1.1 }
201     }
202 ajm 1.13
203 ajm 1.3 System.out.println(toString + ": running");
204 ajm 1.13
205 ajm 1.2 // block on the ORB...in time, management functionality can be placed here.
206 ajm 1.1 refman.getORB().run();
207     }
208 ajm 1.3
209     /**
210 ajm 1.1 * A simple method to print the usage of this class.
211     * It never returns, but instead exits to the system
212     * with a value 1, to indicate the system did not start
213     * properly.
214     */
215     public static void usage() {
216     System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>");
217 tdb 1.8 System.out.println(" or: java -jar iscream.jar <option>");
218 ajm 1.1 System.out.println("WHERE <option>:");
219     System.out.println(" -l <filename> - the location of initial system properties");
220 ajm 1.2 System.out.println(" the default is ./etc/default.properties");
221 ajm 1.1 System.out.println(" -f <name> - the name of the filter (if there is one configured");
222     System.out.println(" -h - this help screen");
223     System.exit(1);
224     }
225    
226     //---CONSTRUCTORS---
227    
228     //---PUBLIC METHODS---
229    
230     //---PRIVATE METHODS---
231    
232     //---ACCESSOR/MUTATOR METHODS---
233    
234     //---ATTRIBUTES---
235    
236     //---STATIC ATTRIBUTES---
237    
238     }