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.10 by tdb, Thu Jan 18 23:22:22 2001 UTC vs.
Revision 1.32 by ajm, Thu Mar 1 16:49:49 2001 UTC

# 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 92 | Line 98 | public class ComponentManager {
98          // get the list of components
99          String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList");
100          StringTokenizer st = new StringTokenizer(componentList, ";");
101 +        _componentsToStart = new ArrayList();
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();
# Line 114 | Line 121 | public class ComponentManager {
121              // note the passing of the Filter's name in its constructor
122              } else if (componentName.equalsIgnoreCase("filter")) {
123                  component = new uk.ac.ukc.iscream.filter.FilterMain(filterName);
124 +            } else if (componentName.equalsIgnoreCase("client")) {
125 +                component = new uk.ac.ukc.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 {
131 >                _componentsToStart.add(component);    
132 >            } else {
133 >                System.err.println(toString + ": WARNING unsupported component not started");
134 >            }
135 >        }
136 >        
137 >        
138 >
139 >        // get the value for timeout
140 >        
141 >        String confTimeout = null;
142 >        try {
143 >            confTimeout = System.getProperty("uk.ac.ukc.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.ac.ukc.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 >            // if we detect a CORBA communication error, we'll restart all the components.
157 >            while(true) {
158 >            try {
159 >                refman.getORB().run();
160 >            } catch (org.omg.CORBA.COMM_FAILURE e) {
161 >                System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage());
162 >                System.out.println(toString + ": WARNING CORBA connections have been lost - attempting to restart!");
163 >            }
164 >            startUp();
165 >        }
166 >    }
167 >
168 >    /**
169 >     * Starts the components as obtained from the configuration.
170 >     * This method calls the start() methods on all the components.
171 >     * If a component fails to start due to a CORBA communication
172 >     * problem, then it catches this and tries to start it again
173 >     * according to uk.ac.ukc.iscream.ComponentTimeout time.
174 >     *
175 >     * If the server dies and CORBA connections are lost, this method
176 >     * is called again.
177 >     */
178 >    private static void startUp() {
179 >        // now we try and start the beast up        
180 >        boolean tryAgain = true;
181 >        Component component = null;
182 >        
183 >        // keep trying until we've started all the components.
184 >        // maybe add support for a limited number of retries
185 >        while(tryAgain) {
186 >            Iterator i = _componentsToStart.iterator();
187 >            ArrayList failedComponents = new ArrayList();
188 >            // go through all the components
189 >            while(i.hasNext()) {
190 >                try {
191 >                    component = (Component) i.next();
192 >                    System.out.println(toString + ": starting component - " + component.toString());
193 >                    
194 >                    // start the component
195                      component.start();
196 +                    
197 +                // if we get this then there was a problem
198 +                // that we can't recover from
199                  } catch (ComponentStartException e) {
200 <                    System.err.println(toString + ": ERROR starting component - " + componentName);
200 >                    System.err.println(toString + ": ERROR starting component - " + component.toString());
201                      System.err.println(toString + ": component reports - " + e.getMessage());
202                      System.exit(1);
203 +
204 +                // if we get this exception then we've tried
205 +                // to talk to something which may not be up yet
206 +                // so we want to try again in a minute                
207 +                } catch(ComponentCORBAException e2) {
208 +                    System.err.println(toString + ": WARNING Component reported CORBA communications failure");
209 +                    System.err.println(toString + ": This could be because it can't communicate with components it needs.");
210 +                    System.err.println(toString + ": component reports - " + e2.getMessage());
211 +                    
212 +                    // make a list of the failed components
213 +                    failedComponents.add(component);
214                  }
215 +            }
216 +            
217 +            // if we had some failed components that we can retry
218 +            if (failedComponents.size() > 0) {
219 +                System.err.println(toString + ": WARNING One or more components failed to start correctly.");
220 +                System.err.println(toString + ": Will try again in " + _startTimeout + " seconds");
221 +            
222 +                // our list is now the failed list
223 +                _componentsToStart = failedComponents;
224 +                
225 +                // sleep for a given timeout
226 +                try {    
227 +                    Thread.sleep(_startTimeout * 1000);
228 +                } catch (InterruptedException e) {
229 +                    // we're not bothered
230 +                }
231 +            // otherwise we started everything
232              } else {
233 <                System.err.println(toString + ": WARNING unsupported component not started");
233 >                // so we set to exit the loop
234 >                tryAgain = false;
235              }
236          }
237 +                
238              System.out.println(toString + ": running");
239 <            
134 <            // block on the ORB...in time, management functionality can be placed here.
135 <        refman.getORB().run();
136 <    }
239 >        }
240  
241      /**
242       * A simple method to print the usage of this class.
# Line 163 | Line 266 | public class ComponentManager {
266   //---ATTRIBUTES---
267      
268   //---STATIC ATTRIBUTES---
269 +
270 +    private static ArrayList _componentsToStart;
271 +    private static int _startTimeout = 0;
272  
273   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines