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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/componentmanager/ComponentManager.java (file contents):
Revision 1.9 by tdb, Thu Jan 18 23:01:50 2001 UTC vs.
Revision 1.39 by tdb, Wed Mar 20 13:40:29 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.componentmanager;
2 > package uk.org.iscream.cms.server.componentmanager;
3  
4   //---IMPORTS---
5   import java.util.*;
6   import java.io.*;
7 + import uk.org.iscream.cms.server.util.*;
8  
9   /**
10   * The component manager is the starting point for all
# Line 11 | Line 12 | import java.io.*;
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
15 > * uk.org.iscream.cms.server.ComponentList
16   *
17   * @author  $Author$
18   * @version $Id$
# Line 37 | Line 38 | public class ComponentManager {
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      /**
# Line 46 | Line 53 | public class ComponentManager {
53       * @param args the command line arguments
54       */
55      public static void main(String[] args) {
56 <        System.out.println("--- I-Scream System Component Manager ---");
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
53        // this is a bit messy and should be looked at
64          String defaultProperties = DEFAULTPROPERTIES;
65          String filterName = null;
66 <        if (args.length > 0) {
67 <            if (args[0].equals("-l")) {
68 <                defaultProperties = args[1];
59 <            } else if (args[0].equals("-f")) {
60 <                filterName = args[1];
61 <            } else if (args[2].equals("-l")) {
62 <                filterName = args[3];
63 <            } else if (args[2].equals("-f")) {
64 <                filterName = args[3];
65 <            } else {
66 >        String filterManagerName = null;
67 >        for(int i=0; i < args.length; i++) {
68 >            if(args[i].equals("-h")) {
69                  usage();
70 <            }            
70 >            }
71 >            else if(args[i].equals("-f")) {
72 >                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 >            }
87 >            else if(args[i].equals("-l")) {
88 >                if(++i < args.length) {
89 >                    defaultProperties = args[i];
90 >                }
91 >                else {
92 >                    usage();
93 >                }
94 >            }
95 >            else {
96 >                usage();
97 >            }
98          }
99  
100          // load the default properties file into the system properties
# Line 89 | Line 119 | public class ComponentManager {
119          refman.activatePOA();
120          
121          // get the list of components
122 <        String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList");
122 >        String componentList = System.getProperty("uk.org.iscream.cms.server.ComponentList");
123          StringTokenizer st = new StringTokenizer(componentList, ";");
124 +        _componentsToStart = new LinkedList();
125          
126          // 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;
100            System.out.println(toString + ": starting component - " + componentName);
131              
132 +            
133              // ### This is where the list of supported components is checked! ###
134              if (componentName.equalsIgnoreCase("core")) {
135 <                component = new uk.ac.ukc.iscream.core.Core();
135 >                component = new uk.org.iscream.cms.server.core.Core();
136 >            // note the passing of the FilterManagers's name in its constructor
137              } else if (componentName.equalsIgnoreCase("filtermanager")) {
138 <                component = new uk.ac.ukc.iscream.filtermanager.FilterManager();
138 >                component = new uk.org.iscream.cms.server.filtermanager.FilterManager(filterManagerName);
139              } else if (componentName.equalsIgnoreCase("rootfilter")) {
140 <                component = new uk.ac.ukc.iscream.rootfilter.RootFilter();
140 >                component = new uk.org.iscream.cms.server.rootfilter.RootFilter();
141              } else if (componentName.equalsIgnoreCase("dbinterface")) {
142 <                component = new uk.ac.ukc.iscream.dbinterface.DBInterface();
142 >                component = new uk.org.iscream.cms.server.dbinterface.DBInterface();
143              } else if (componentName.equalsIgnoreCase("clientinterface")) {
144 <                component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain();
144 >                component = new uk.org.iscream.cms.server.clientinterface.ClientInterfaceMain();
145              // note the passing of the Filter's name in its constructor
146              } else if (componentName.equalsIgnoreCase("filter")) {
147 <                component = new uk.ac.ukc.iscream.filter.FilterMain(filterName);
147 >                component = new uk.org.iscream.cms.server.filter.FilterMain(filterName);
148 >            } else if (componentName.equalsIgnoreCase("client")) {
149 >                component = new uk.org.iscream.cms.server.client.ClientMain();
150              }
151              // ###  Add new component constructors in the above section! ###
152              
153 +            // build the list of components to start
154              if (component != null) {
155 <                try {
121 <                    component.start();
122 <                } catch (ComponentStartException e) {
123 <                    System.err.println(toString + ": ERROR starting component - " + componentName);
124 <                    System.err.println(toString + ": component reports - " + e.getMessage());
125 <                    System.exit(1);
126 <                }
155 >                _componentsToStart.add(component);    
156              } else {
157 <                System.err.println(toString + ": WARNING unsupported component not started");
157 >                System.err.println(toString + ": WARNING unsupported component not started: "+componentName);
158              }
159          }
160 <            System.out.println(toString + ": running");
161 <            
160 >        
161 >        
162 >
163 >        // get the value for timeout
164 >        
165 >        String confTimeout = null;
166 >        try {
167 >            confTimeout = System.getProperty("uk.org.iscream.cms.server.ComponentTimeout");
168 >            confTimeout.trim();
169 >            _startTimeout = Integer.parseInt(confTimeout);
170 >        } catch (NumberFormatException e) {
171 >            _startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
172 >            System.err.println(toString + ": unable to read uk.org.iscream.cms.server.ComponentTimeout value (" + confTimeout + "), using default!");
173 >        }
174 >        System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds");
175 >        
176 >        // startup the system components
177 >        startUp();
178 >
179              // block on the ORB...in time, management functionality can be placed here.
180 <        refman.getORB().run();
180 >            // if we detect a CORBA communication error, we'll restart all the components.
181 >            // !! this doesn't appear to work !!
182 >            while(true) {
183 >            try {
184 >                refman.getORB().run();
185 >            } catch (org.omg.CORBA.COMM_FAILURE e) {
186 >                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 +     * according to uk.org.iscream.cms.server.ComponentTimeout time.
199 +     *
200 +     * If the server dies and CORBA connections are lost, this method
201 +     * is called again.
202 +     */
203 +    private static void startUp() {
204 +        // now we try and start the beast up        
205 +        boolean tryAgain = true;
206 +        Component component = null;
207 +        
208 +        // keep trying until we've started all the components.
209 +        // maybe add support for a limited number of retries
210 +        while(tryAgain) {
211 +            Iterator i = _componentsToStart.iterator();
212 +            LinkedList failedComponents = new LinkedList();
213 +            // go through all the components
214 +            while(i.hasNext()) {
215 +                // get a refence to the component
216 +                component = (Component) i.next();
217 +                System.out.println(toString + ": dependency checking component - " + component.toString());
218 +                
219 +                // check it's dependencies
220 +                boolean depOK = component.depCheck();
221 +                if(depOK) {
222 +                    System.out.println(toString + ": starting component - " + component.toString());
223 +                    // 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 +                    System.err.println(toString + ": This could be because it can't communicate with components it needs.");
240 +                    
241 +                    // make a list of the failed components
242 +                    failedComponents.add(component);
243 +                }
244 +            }
245 +            
246 +            // if we had some failed components that we can retry
247 +            if (failedComponents.size() > 0) {
248 +                System.err.println(toString + ": WARNING One or more components failed to start correctly.");
249 +                System.err.println(toString + ": Will try again in " + _startTimeout + " seconds");
250 +            
251 +                // our list is now the failed list
252 +                _componentsToStart = failedComponents;
253 +                
254 +                // sleep for a given timeout
255 +                try {    
256 +                    Thread.sleep(_startTimeout * 1000);
257 +                } catch (InterruptedException e) {
258 +                    // we're not bothered
259 +                }
260 +            // otherwise we started everything
261 +            } else {
262 +                // so we set to exit the loop
263 +                tryAgain = false;
264 +            }
265 +        }
266 +                
267 +            System.out.println(toString + ": running");
268 +        }
269 +
270 +    /**
271       * 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 <        System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>");
277 >        System.out.println("USAGE: java uk.org.iscream.cms.server.componentmanager.ComponentManager <option>");
278          System.out.println("   or: java -jar iscream.jar <option>");
279          System.out.println("WHERE <option>:");
280          System.out.println("      -l <filename> - the location of initial system properties");
281          System.out.println("                      the default is ./etc/default.properties");
282          System.out.println("      -f <name>     - the name of the filter (if there is one configured");
283 +        System.out.println("      -fm <name>    - the name of the filter manager (if there is one configured");
284          System.out.println("      -h            - this help screen");
285          System.exit(1);
286      }
# Line 162 | Line 296 | public class ComponentManager {
296   //---ATTRIBUTES---
297      
298   //---STATIC ATTRIBUTES---
299 +
300 +    private static LinkedList _componentsToStart;
301 +    private static int _startTimeout = 0;
302  
303   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines