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.5 by ajm, Tue Dec 12 20:45:56 2000 UTC vs.
Revision 1.35 by tdb, Sat Mar 17 03:57:58 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.componentmanager;
2 > package uk.org.iscream.componentmanager;
3  
4   //---IMPORTS---
5 import uk.ac.ukc.iscream.util.*;
5   import java.util.*;
6   import java.io.*;
7 + import uk.org.iscream.util.*;
8  
9   /**
10   * The component manager is the starting point for all
# Line 12 | 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.ComponentList
16   *
17   * @author  $Author$
18   * @version $Id$
# Line 38 | 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 47 | 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("--- i-scream Server Component Manager ---");
57          System.out.println("---          Starting System          ---");        
58          
59          // get the command line args
54        // this is a bit messy and should be looked at
60          String defaultProperties = DEFAULTPROPERTIES;
61          String filterName = null;
62 <        if (args.length > 0) {
63 <            if (args[0].equals("-l")) {
59 <                defaultProperties = args[1];
60 <            } else if (args[0].equals("-f")) {
61 <                filterName = args[1];
62 <            } else if (args[2].equals("-l")) {
63 <                filterName = args[3];
64 <            } else if (args[2].equals("-f")) {
65 <                filterName = args[3];
66 <            } else {
62 >        for(int i=0; i < args.length; i++) {
63 >            if(args[i].equals("-h")) {
64                  usage();
65 <            }            
65 >            }
66 >            else if(args[i].equals("-f")) {
67 >                i++; filterName = args[i];
68 >            }
69 >            else if(args[i].equals("-l")) {
70 >                i++; defaultProperties = args[i];
71 >            }
72 >            else {
73 >                usage();
74 >            }
75          }
76  
77          // load the default properties file into the system properties
# Line 90 | Line 96 | public class ComponentManager {
96          refman.activatePOA();
97          
98          // get the list of components
99 <        String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList");
99 >        String componentList = System.getProperty("uk.org.iscream.ComponentList");
100          StringTokenizer st = new StringTokenizer(componentList, ";");
101 +        _componentsToStart = new LinkedList();
102          
103          // 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;
101            System.out.println(toString + ": starting component - " + componentName);
108              
109 +            
110              // ### This is where the list of supported components is checked! ###
111              if (componentName.equalsIgnoreCase("core")) {
112 <                component = new uk.ac.ukc.iscream.core.Core();
112 >                component = new uk.org.iscream.core.Core();
113              } else if (componentName.equalsIgnoreCase("filtermanager")) {
114 <                component = new uk.ac.ukc.iscream.filtermanager.FilterManager();
114 >                component = new uk.org.iscream.filtermanager.FilterManager();
115              } else if (componentName.equalsIgnoreCase("rootfilter")) {
116 <                component = new uk.ac.ukc.iscream.rootfilter.RootFilter();
116 >                component = new uk.org.iscream.rootfilter.RootFilter();
117              } else if (componentName.equalsIgnoreCase("dbinterface")) {
118 <                component = new uk.ac.ukc.iscream.dbinterface.DBInterface();
118 >                component = new uk.org.iscream.dbinterface.DBInterface();
119 >            } else if (componentName.equalsIgnoreCase("clientinterface")) {
120 >                component = new uk.org.iscream.clientinterface.ClientInterfaceMain();
121 >            // note the passing of the Filter's name in its constructor
122 >            } else if (componentName.equalsIgnoreCase("filter")) {
123 >                component = new uk.org.iscream.filter.FilterMain(filterName);
124 >            } else if (componentName.equalsIgnoreCase("client")) {
125 >                component = new uk.org.iscream.client.ClientMain();
126              }
127              // ###  Add new component constructors in the above section! ###
128              
129 +            // build the list of components to start
130              if (component != null) {
131 <                try {
117 <                    component.start();
118 <                } catch (ComponentStartException e) {
119 <                    System.err.println(toString + ": ERROR starting component - " + componentName);
120 <                    System.err.println(toString + ": component reports - " + e.getMessage());
121 <                    System.exit(1);
122 <                }
131 >                _componentsToStart.add(component);    
132              } else {
133 <                System.err.println(toString + ": WARNING unsupported component not started");
133 >                System.err.println(toString + ": WARNING unsupported component not started: "+componentName);
134              }
135          }
136 <            System.out.println(toString + ": running");
137 <            
136 >        
137 >        
138 >
139 >        // get the value for timeout
140 >        
141 >        String confTimeout = null;
142 >        try {
143 >            confTimeout = System.getProperty("uk.org.iscream.ComponentTimeout");
144 >            confTimeout.trim();
145 >            _startTimeout = Integer.parseInt(confTimeout);
146 >        } catch (NumberFormatException e) {
147 >            _startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
148 >            System.err.println(toString + ": unable to read uk.org.iscream.ComponentTimeout value (" + confTimeout + "), using default!");
149 >        }
150 >        System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds");
151 >        
152 >        // startup the system components
153 >        startUp();
154 >
155              // block on the ORB...in time, management functionality can be placed here.
156 <        refman.getORB().run();
156 >            // if we detect a CORBA communication error, we'll restart all the components.
157 >            // !! this doesn't appear to work !!
158 >            while(true) {
159 >            try {
160 >                refman.getORB().run();
161 >            } catch (org.omg.CORBA.COMM_FAILURE e) {
162 >                System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage());
163 >                System.out.println(toString + ": WARNING CORBA connections have been lost - attempting to restart!");
164 >            }
165 >            startUp();
166 >        }
167      }
168  
169      /**
170 +     * Starts the components as obtained from the configuration.
171 +     * This method calls the start() methods on all the components.
172 +     * If a component fails to start due to a CORBA communication
173 +     * problem, then it catches this and tries to start it again
174 +     * according to uk.org.iscream.ComponentTimeout time.
175 +     *
176 +     * If the server dies and CORBA connections are lost, this method
177 +     * is called again.
178 +     */
179 +    private static void startUp() {
180 +        // now we try and start the beast up        
181 +        boolean tryAgain = true;
182 +        Component component = null;
183 +        
184 +        // keep trying until we've started all the components.
185 +        // maybe add support for a limited number of retries
186 +        while(tryAgain) {
187 +            Iterator i = _componentsToStart.iterator();
188 +            LinkedList failedComponents = new LinkedList();
189 +            // go through all the components
190 +            while(i.hasNext()) {
191 +                // get a refence to the component
192 +                component = (Component) i.next();
193 +                System.out.println(toString + ": dependency checking component - " + component.toString());
194 +                
195 +                // check it's dependencies
196 +                boolean depOK = component.depCheck();
197 +                if(depOK) {
198 +                    System.out.println(toString + ": starting component - " + component.toString());
199 +                    // it should be ok to start the component
200 +                        try {    
201 +                            // start the component
202 +                        component.start();
203 +                    } catch (ComponentStartException e) {
204 +                        // if we get this then there was a problem
205 +                        // that we can't recover from
206 +                        System.err.println(toString + ": ERROR starting component - " + component.toString());
207 +                        System.err.println(toString + ": component reports - " + e.getMessage());
208 +                        System.exit(1);
209 +                    }
210 +                }
211 +                else {
212 +                    // it seems the depedencies failed
213 +                    // so we want to try again after a delay
214 +                    System.err.println(toString + ": WARNING Component reported dependency failure");
215 +                    System.err.println(toString + ": This could be because it can't communicate with components it needs.");
216 +                    
217 +                    // make a list of the failed components
218 +                    failedComponents.add(component);
219 +                }
220 +            }
221 +            
222 +            // if we had some failed components that we can retry
223 +            if (failedComponents.size() > 0) {
224 +                System.err.println(toString + ": WARNING One or more components failed to start correctly.");
225 +                System.err.println(toString + ": Will try again in " + _startTimeout + " seconds");
226 +            
227 +                // our list is now the failed list
228 +                _componentsToStart = failedComponents;
229 +                
230 +                // sleep for a given timeout
231 +                try {    
232 +                    Thread.sleep(_startTimeout * 1000);
233 +                } catch (InterruptedException e) {
234 +                    // we're not bothered
235 +                }
236 +            // otherwise we started everything
237 +            } else {
238 +                // so we set to exit the loop
239 +                tryAgain = false;
240 +            }
241 +        }
242 +                
243 +            System.out.println(toString + ": running");
244 +        }
245 +
246 +    /**
247       * A simple method to print the usage of this class.
248       * It never returns, but instead exits to the system
249       * with a value 1, to indicate the system did not start
250       * properly.
251       */
252      public static void usage() {
253 <        System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>");
253 >        System.out.println("USAGE: java uk.org.iscream.componentmanager.ComponentManager <option>");
254 >        System.out.println("   or: java -jar iscream.jar <option>");
255          System.out.println("WHERE <option>:");
256          System.out.println("      -l <filename> - the location of initial system properties");
257          System.out.println("                      the default is ./etc/default.properties");
# Line 157 | Line 271 | public class ComponentManager {
271   //---ATTRIBUTES---
272      
273   //---STATIC ATTRIBUTES---
274 +
275 +    private static LinkedList _componentsToStart;
276 +    private static int _startTimeout = 0;
277  
278   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines