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.40 by tdb, Sat May 18 18:16:01 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines