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.17 by ajm, Fri Feb 23 16:36:38 2001 UTC vs.
Revision 1.42 by tdb, Wed Feb 5 16:43:46 2003 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
4 + * Copyright (C) 2000-2002 i-scream
5 + *
6 + * This program is free software; you can redistribute it and/or
7 + * modify it under the terms of the GNU General Public License
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21   //---PACKAGE DECLARATION---
22 < package uk.ac.ukc.iscream.componentmanager;
22 > package uk.org.iscream.cms.server.componentmanager;
23  
24   //---IMPORTS---
25   import java.util.*;
26   import java.io.*;
27 < import uk.ac.ukc.iscream.util.*;
27 > import uk.org.iscream.cms.util.*;
28  
29   /**
30   * The component manager is the starting point for all
# Line 12 | Line 32 | import uk.ac.ukc.iscream.util.*;
32   * It loads its initial system configuration from the
33   * default properties file, it then starts all the iscream
34   * components as specified in the default.properties under
35 < * uk.ac.ukc.iscream.ComponentList
35 > * uk.org.iscream.cms.server.ComponentList
36   *
37   * @author  $Author$
38   * @version $Id$
# Line 38 | Line 58 | public class ComponentManager {
58       */
59      public static final String DEFAULTPROPERTIES = "./etc/default.properties";
60      
61 +    /**
62 +     * The default time to wait before retrying
63 +     * component.
64 +     */
65 +    public static final int DEFAULT_COMPONENT_START_TIMEOUT = 5;
66 +    
67   //---STATIC METHODS---
68  
69      /**
# Line 47 | Line 73 | public class ComponentManager {
73       * @param args the command line arguments
74       */
75      public static void main(String[] args) {
76 +        System.out.println("-----------------------------------------");
77          System.out.println("--- i-scream Server Component Manager ---");
78 +        System.out.println("---   (c) 2001 The i-scream Project   ---");
79 +        System.out.println("---    (http://www.i-scream.org.uk)   ---");
80 +        System.out.println("-----------------------------------------");
81          System.out.println("---          Starting System          ---");        
82          
83          // get the command line args
84          String defaultProperties = DEFAULTPROPERTIES;
85          String filterName = null;
86 +        String filterManagerName = null;
87          for(int i=0; i < args.length; i++) {
88              if(args[i].equals("-h")) {
89                  usage();
90              }
91              else if(args[i].equals("-f")) {
92 <                i++; filterName = args[i];
92 >                if(++i < args.length) {
93 >                    filterName = args[i];
94 >                }
95 >                else {
96 >                    usage();
97 >                }
98              }
99 +            else if(args[i].equals("-fm")) {
100 +                if(++i < args.length) {
101 +                    filterManagerName = args[i];
102 +                }
103 +                else {
104 +                    usage();
105 +                }
106 +            }
107              else if(args[i].equals("-l")) {
108 <                i++; defaultProperties = args[i];
108 >                if(++i < args.length) {
109 >                    defaultProperties = args[i];
110 >                }
111 >                else {
112 >                    usage();
113 >                }
114              }
115              else {
116                  usage();
# Line 90 | Line 139 | public class ComponentManager {
139          refman.activatePOA();
140          
141          // get the list of components
142 <        String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList");
142 >        String componentList = System.getProperty("uk.org.iscream.cms.server.ComponentList");
143          StringTokenizer st = new StringTokenizer(componentList, ";");
144 +        _componentsToStart = new LinkedList();
145          
96
97        ArrayList componentsToStart = new ArrayList();
98        
146          // this could be done using reflection
147          // but..well..we don't ;-p
148          while (st.hasMoreTokens()){
# Line 105 | Line 152 | public class ComponentManager {
152              
153              // ### This is where the list of supported components is checked! ###
154              if (componentName.equalsIgnoreCase("core")) {
155 <                component = new uk.ac.ukc.iscream.core.Core();
155 >                component = new uk.org.iscream.cms.server.core.Core();
156 >            // note the passing of the FilterManagers's name in its constructor
157              } else if (componentName.equalsIgnoreCase("filtermanager")) {
158 <                component = new uk.ac.ukc.iscream.filtermanager.FilterManager();
158 >                component = new uk.org.iscream.cms.server.filtermanager.FilterManager(filterManagerName);
159              } else if (componentName.equalsIgnoreCase("rootfilter")) {
160 <                component = new uk.ac.ukc.iscream.rootfilter.RootFilter();
160 >                component = new uk.org.iscream.cms.server.rootfilter.RootFilter();
161              } else if (componentName.equalsIgnoreCase("dbinterface")) {
162 <                component = new uk.ac.ukc.iscream.dbinterface.DBInterface();
162 >                component = new uk.org.iscream.cms.server.dbinterface.DBInterface();
163              } else if (componentName.equalsIgnoreCase("clientinterface")) {
164 <                component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain();
164 >                component = new uk.org.iscream.cms.server.clientinterface.ClientInterfaceMain();
165              // note the passing of the Filter's name in its constructor
166              } else if (componentName.equalsIgnoreCase("filter")) {
167 <                component = new uk.ac.ukc.iscream.filter.FilterMain(filterName);
167 >                component = new uk.org.iscream.cms.server.filter.FilterMain(filterName);
168 >            } else if (componentName.equalsIgnoreCase("client")) {
169 >                component = new uk.org.iscream.cms.server.client.ClientMain();
170              }
171              // ###  Add new component constructors in the above section! ###
172              
173 +            // build the list of components to start
174              if (component != null) {
175 <                componentsToStart.add(component);    
175 >                _componentsToStart.add(component);    
176              } else {
177 <                System.err.println(toString + ": WARNING unsupported component not started");
177 >                System.err.println(toString + ": WARNING unsupported component not started: "+componentName);
178              }
179          }
180          
181 +        
182 +
183 +        // get the value for timeout
184 +        
185 +        String confTimeout = null;
186 +        try {
187 +            confTimeout = System.getProperty("uk.org.iscream.cms.server.ComponentTimeout");
188 +            confTimeout.trim();
189 +            _startTimeout = Integer.parseInt(confTimeout);
190 +        } catch (NumberFormatException e) {
191 +            _startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
192 +            System.err.println(toString + ": unable to read uk.org.iscream.cms.server.ComponentTimeout value (" + confTimeout + "), using default!");
193 +        }
194 +        System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds");
195 +        
196 +        // startup the system components
197 +        startUp();
198 +
199 +            // block on the ORB...in time, management functionality can be placed here.
200 +            // if we detect a CORBA communication error, we'll restart all the components.
201 +            // !! this doesn't appear to work !!
202 +            while(true) {
203 +            try {
204 +                refman.getORB().run();
205 +            } catch (org.omg.CORBA.COMM_FAILURE e) {
206 +                System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage());
207 +                System.out.println(toString + ": WARNING CORBA connections have been lost - attempting to restart!");
208 +            }
209 +            startUp();
210 +        }
211 +    }
212 +
213 +    /**
214 +     * Starts the components as obtained from the configuration.
215 +     * This method calls the start() methods on all the components.
216 +     * If a component fails to start due to a CORBA communication
217 +     * problem, then it catches this and tries to start it again
218 +     * according to uk.org.iscream.cms.server.ComponentTimeout time.
219 +     *
220 +     * If the server dies and CORBA connections are lost, this method
221 +     * is called again.
222 +     */
223 +    private static void startUp() {
224 +        // now we try and start the beast up        
225          boolean tryAgain = true;
226          Component component = null;
227 +        
228 +        // keep trying until we've started all the components.
229 +        // maybe add support for a limited number of retries
230          while(tryAgain) {
231 <            Iterator i = componentsToStart.iterator();
231 >            Iterator i = _componentsToStart.iterator();
232 >            LinkedList failedComponents = new LinkedList();
233 >            // go through all the components
234              while(i.hasNext()) {
235 <                try {
236 <                    component = (Component) i.next();
235 >                // get a refence to the component
236 >                component = (Component) i.next();
237 >                System.out.println(toString + ": dependency checking component - " + component.toString());
238 >                
239 >                // check it's dependencies
240 >                boolean depOK = component.depCheck();
241 >                if(depOK) {
242                      System.out.println(toString + ": starting component - " + component.toString());
243 <                    component.start();
244 <                    componentsToStart.remove(componentsToStart.indexOf(component));
245 <                } catch (ComponentStartException e) {
246 <                    System.err.println(toString + ": ERROR starting component - " + component.toString());
247 <                    System.err.println(toString + ": component reports - " + e.getMessage());
248 <                    System.exit(1);
249 <                } catch(ComponentCORBAException e2) {
250 <                    System.err.println(toString + ": WARNING Component reported CORBA communications failure");
243 >                    // it should be ok to start the component
244 >                        try {    
245 >                            // start the component
246 >                        component.start();
247 >                    } catch (ComponentStartException e) {
248 >                        // if we get this then there was a problem
249 >                        // that we can't recover from
250 >                        System.err.println(toString + ": ERROR starting component - " + component.toString());
251 >                        System.err.println(toString + ": component reports - " + e.getMessage());
252 >                        System.exit(1);
253 >                    }
254 >                }
255 >                else {
256 >                    // it seems the depedencies failed
257 >                    // so we want to try again after a delay
258 >                    System.err.println(toString + ": WARNING Component reported dependency failure");
259                      System.err.println(toString + ": This could be because it can't communicate with components it needs.");
260 <                    System.err.println(toString + ": component reports - " + e2.getMessage());
260 >                    
261 >                    // make a list of the failed components
262 >                    failedComponents.add(component);
263                  }
264              }
265 <            if (componentsToStart.size() > 0) {
265 >            
266 >            // if we had some failed components that we can retry
267 >            if (failedComponents.size() > 0) {
268                  System.err.println(toString + ": WARNING One or more components failed to start correctly.");
269 <                System.err.println(toString + ": Will try again in 5 seconds");
270 <                Thread.sleep(5000);
271 <            } else {
272 <                try {
273 <                    tryAgain = false;
269 >                System.err.println(toString + ": Will try again in " + _startTimeout + " seconds");
270 >            
271 >                // our list is now the failed list
272 >                _componentsToStart = failedComponents;
273 >                
274 >                // sleep for a given timeout
275 >                try {    
276 >                    Thread.sleep(_startTimeout * 1000);
277                  } catch (InterruptedException e) {
278                      // we're not bothered
279                  }
280 +            // otherwise we started everything
281 +            } else {
282 +                // so we set to exit the loop
283 +                tryAgain = false;
284              }
285          }
286                  
287              System.out.println(toString + ": running");
288 +        }
289  
165            // block on the ORB...in time, management functionality can be placed here.
166        refman.getORB().run();
167    }
168
290      /**
291       * A simple method to print the usage of this class.
292       * It never returns, but instead exits to the system
# Line 173 | Line 294 | public class ComponentManager {
294       * properly.
295       */
296      public static void usage() {
297 <        System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>");
297 >        System.out.println("USAGE: java uk.org.iscream.cms.server.componentmanager.ComponentManager <option>");
298          System.out.println("   or: java -jar iscream.jar <option>");
299          System.out.println("WHERE <option>:");
300          System.out.println("      -l <filename> - the location of initial system properties");
301          System.out.println("                      the default is ./etc/default.properties");
302          System.out.println("      -f <name>     - the name of the filter (if there is one configured");
303 +        System.out.println("      -fm <name>    - the name of the filter manager (if there is one configured");
304          System.out.println("      -h            - this help screen");
305          System.exit(1);
306      }
# Line 194 | Line 316 | public class ComponentManager {
316   //---ATTRIBUTES---
317      
318   //---STATIC ATTRIBUTES---
319 +
320 +    private static LinkedList _componentsToStart;
321 +    private static int _startTimeout = 0;
322  
323   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines