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.18 by ajm, Fri Feb 23 16:38:03 2001 UTC vs.
Revision 1.43 by tdb, Mon May 5 22:05:09 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("---          Starting System          ---");        
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 +        String clientInterfaceName = null;
88          for(int i=0; i < args.length; i++) {
89              if(args[i].equals("-h")) {
90                  usage();
91              }
92              else if(args[i].equals("-f")) {
93 <                i++; filterName = args[i];
93 >                if(++i < args.length) {
94 >                    filterName = args[i];
95 >                }
96 >                else {
97 >                    usage();
98 >                }
99              }
100 +            else if(args[i].equals("-fm")) {
101 +                if(++i < args.length) {
102 +                    filterManagerName = args[i];
103 +                }
104 +                else {
105 +                    usage();
106 +                }
107 +            }
108 +            else if(args[i].equals("-ci")) {
109 +                if(++i < args.length) {
110 +                    clientInterfaceName = args[i];
111 +                }
112 +                else {
113 +                    usage();
114 +                }
115 +            }
116              else if(args[i].equals("-l")) {
117 <                i++; defaultProperties = args[i];
117 >                if(++i < args.length) {
118 >                    defaultProperties = args[i];
119 >                }
120 >                else {
121 >                    usage();
122 >                }
123              }
124              else {
125                  usage();
# Line 90 | Line 148 | public class ComponentManager {
148          refman.activatePOA();
149          
150          // get the list of components
151 <        String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList");
151 >        String componentList = System.getProperty("uk.org.iscream.cms.server.ComponentList");
152          StringTokenizer st = new StringTokenizer(componentList, ";");
153 +        _componentsToStart = new LinkedList();
154          
96
97        ArrayList componentsToStart = new ArrayList();
98        
155          // this could be done using reflection
156          // but..well..we don't ;-p
157          while (st.hasMoreTokens()){
# Line 105 | Line 161 | public class ComponentManager {
161              
162              // ### This is where the list of supported components is checked! ###
163              if (componentName.equalsIgnoreCase("core")) {
164 <                component = new uk.ac.ukc.iscream.core.Core();
164 >                component = new uk.org.iscream.cms.server.core.Core();
165 >            // note the passing of the FilterManagers's name in its constructor
166              } else if (componentName.equalsIgnoreCase("filtermanager")) {
167 <                component = new uk.ac.ukc.iscream.filtermanager.FilterManager();
167 >                component = new uk.org.iscream.cms.server.filtermanager.FilterManager(filterManagerName);
168              } else if (componentName.equalsIgnoreCase("rootfilter")) {
169 <                component = new uk.ac.ukc.iscream.rootfilter.RootFilter();
113 <            } else if (componentName.equalsIgnoreCase("dbinterface")) {
114 <                component = new uk.ac.ukc.iscream.dbinterface.DBInterface();
169 >                component = new uk.org.iscream.cms.server.rootfilter.RootFilter();
170              } else if (componentName.equalsIgnoreCase("clientinterface")) {
171 <                component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain();
171 >                component = new uk.org.iscream.cms.server.clientinterface.ClientInterfaceMain(clientInterfaceName);
172              // note the passing of the Filter's name in its constructor
173              } else if (componentName.equalsIgnoreCase("filter")) {
174 <                component = new uk.ac.ukc.iscream.filter.FilterMain(filterName);
174 >                component = new uk.org.iscream.cms.server.filter.FilterMain(filterName);
175 >            } else if (componentName.equalsIgnoreCase("client")) {
176 >                component = new uk.org.iscream.cms.server.client.ClientMain();
177              }
178              // ###  Add new component constructors in the above section! ###
179              
180 +            // build the list of components to start
181              if (component != null) {
182 <                componentsToStart.add(component);    
182 >                _componentsToStart.add(component);
183              } else {
184 <                System.err.println(toString + ": WARNING unsupported component not started");
184 >                System.err.println(toString + ": WARNING unsupported component not started: "+componentName);
185              }
186          }
187          
188 +        
189 +
190 +        // get the value for timeout
191 +        
192 +        String confTimeout = null;
193 +        try {
194 +            confTimeout = System.getProperty("uk.org.iscream.cms.server.ComponentTimeout");
195 +            confTimeout.trim();
196 +            _startTimeout = Integer.parseInt(confTimeout);
197 +        } catch (NumberFormatException e) {
198 +            _startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
199 +            System.err.println(toString + ": unable to read uk.org.iscream.cms.server.ComponentTimeout value (" + confTimeout + "), using default!");
200 +        }
201 +        System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds");
202 +        
203 +        // startup the system components
204 +        startUp();
205 +
206 +        // block on the ORB...in time, management functionality can be placed here.
207 +        // if we detect a CORBA communication error, we'll restart all the components.
208 +        // !! this doesn't appear to work !!
209 +        while(true) {
210 +            try {
211 +                refman.getORB().run();
212 +            } catch (org.omg.CORBA.COMM_FAILURE e) {
213 +                System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage());
214 +                System.out.println(toString + ": WARNING CORBA connections have been lost - attempting to restart!");
215 +            }
216 +            startUp();
217 +        }
218 +    }
219 +
220 +    /**
221 +     * Starts the components as obtained from the configuration.
222 +     * This method calls the start() methods on all the components.
223 +     * If a component fails to start due to a CORBA communication
224 +     * problem, then it catches this and tries to start it again
225 +     * according to uk.org.iscream.cms.server.ComponentTimeout time.
226 +     *
227 +     * If the server dies and CORBA connections are lost, this method
228 +     * is called again.
229 +     */
230 +    private static void startUp() {
231 +        // now we try and start the beast up
232          boolean tryAgain = true;
233          Component component = null;
234 +        
235 +        // keep trying until we've started all the components.
236 +        // maybe add support for a limited number of retries
237          while(tryAgain) {
238 <            Iterator i = componentsToStart.iterator();
238 >            Iterator i = _componentsToStart.iterator();
239 >            LinkedList failedComponents = new LinkedList();
240 >            // go through all the components
241              while(i.hasNext()) {
242 <                try {
243 <                    component = (Component) i.next();
244 <                    System.out.println(toString + ": starting component - " + component.toString());
245 <                    component.start();
246 <                    componentsToStart.remove(componentsToStart.indexOf(component));
247 <                } catch (ComponentStartException e) {
248 <                    System.err.println(toString + ": ERROR starting component - " + component.toString());
249 <                    System.err.println(toString + ": component reports - " + e.getMessage());
250 <                    System.exit(1);
251 <                } catch(ComponentCORBAException e2) {
252 <                    System.err.println(toString + ": WARNING Component reported CORBA communications failure");
242 >                // get a refence to the component
243 >                component = (Component) i.next();
244 >                System.out.println(toString + ": dependency checking component - " + component.toString());
245 >                
246 >                // check it's dependencies
247 >                boolean depOK = component.depCheck();
248 >                if(depOK) {
249 >                    System.out.println(toString + ": starting component - " + component.toString());
250 >                    // it should be ok to start the component
251 >                    try {    
252 >                        // start the component
253 >                        component.start();
254 >                    } catch (ComponentStartException e) {
255 >                        // if we get this then there was a problem
256 >                        // that we can't recover from
257 >                        System.err.println(toString + ": ERROR starting component - " + component.toString());
258 >                        System.err.println(toString + ": component reports - " + e.getMessage());
259 >                        System.exit(1);
260 >                    }
261 >                }
262 >                else {
263 >                    // it seems the depedencies failed
264 >                    // so we want to try again after a delay
265 >                    System.err.println(toString + ": WARNING Component reported dependency failure");
266                      System.err.println(toString + ": This could be because it can't communicate with components it needs.");
267 <                    System.err.println(toString + ": component reports - " + e2.getMessage());
267 >                    
268 >                    // make a list of the failed components
269 >                    failedComponents.add(component);
270                  }
271              }
272 <            if (componentsToStart.size() > 0) {
272 >            
273 >            // if we had some failed components that we can retry
274 >            if (failedComponents.size() > 0) {
275                  System.err.println(toString + ": WARNING One or more components failed to start correctly.");
276 <                System.err.println(toString + ": Will try again in 5 seconds");
277 <                try {    
278 <                    Thread.sleep(5000);
276 >                System.err.println(toString + ": Will try again in " + _startTimeout + " seconds");
277 >            
278 >                // our list is now the failed list
279 >                _componentsToStart = failedComponents;
280 >                
281 >                // sleep for a given timeout
282 >                try {
283 >                    Thread.sleep(_startTimeout * 1000);
284                  } catch (InterruptedException e) {
285                      // we're not bothered
286                  }
287 +            // otherwise we started everything
288              } else {
289 +                // so we set to exit the loop
290                  tryAgain = false;
291              }
292          }
293 <                
294 <            System.out.println(toString + ": running");
164 <
165 <            // block on the ORB...in time, management functionality can be placed here.
166 <        refman.getORB().run();
293 >        
294 >        System.out.println(toString + ": running");
295      }
296  
297      /**
# Line 173 | Line 301 | public class ComponentManager {
301       * properly.
302       */
303      public static void usage() {
304 <        System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>");
304 >        System.out.println("USAGE: java uk.org.iscream.cms.server.componentmanager.ComponentManager <option>");
305          System.out.println("   or: java -jar iscream.jar <option>");
306          System.out.println("WHERE <option>:");
307          System.out.println("      -l <filename> - the location of initial system properties");
308          System.out.println("                      the default is ./etc/default.properties");
309          System.out.println("      -f <name>     - the name of the filter (if there is one configured");
310 +        System.out.println("      -fm <name>    - the name of the filter manager (if there is one configured");
311 +        System.out.println("      -ci <name>    - the name of the client interface (if there is one configured");
312          System.out.println("      -h            - this help screen");
313          System.exit(1);
314      }
# Line 194 | Line 324 | public class ComponentManager {
324   //---ATTRIBUTES---
325      
326   //---STATIC ATTRIBUTES---
327 +
328 +    private static LinkedList _componentsToStart;
329 +    private static int _startTimeout = 0;
330  
331   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines