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.33 by tdb, Wed Mar 14 01:34:25 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 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 LinkedList();
102          
96
97        ArrayList componentsToStart = new ArrayList();
98        
103          // this could be done using reflection
104          // but..well..we don't ;-p
105          while (st.hasMoreTokens()){
# Line 117 | 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 <                componentsToStart.add(component);    
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          
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 +            // !! 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.ac.ukc.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();
187 >            Iterator i = _componentsToStart.iterator();
188 >            LinkedList failedComponents = new LinkedList();
189 >            // go through all the components
190              while(i.hasNext()) {
191 <                try {
192 <                    component = (Component) i.next();
193 <                    System.out.println(toString + ": starting component - " + component.toString());
194 <                    component.start();
195 <                    componentsToStart.remove(componentsToStart.indexOf(component));
196 <                } catch (ComponentStartException e) {
197 <                    System.err.println(toString + ": ERROR starting component - " + component.toString());
198 <                    System.err.println(toString + ": component reports - " + e.getMessage());
199 <                    System.exit(1);
200 <                } catch(ComponentCORBAException e2) {
201 <                    System.err.println(toString + ": WARNING Component reported CORBA communications failure");
191 >                // get a refence to the component
192 >                component = (Component) i.next();
193 >                System.out.println(toString + ": starting component - " + component.toString());
194 >                
195 >                // check it's dependencies
196 >                boolean depOK = component.depCheck();
197 >                if(depOK) {
198 >                    // it should be ok to start the component
199 >                        try {    
200 >                            // start the component
201 >                        component.start();
202 >                    } catch (ComponentStartException e) {
203 >                        // if we get this then there was a problem
204 >                        // that we can't recover from
205 >                        System.err.println(toString + ": ERROR starting component - " + component.toString());
206 >                        System.err.println(toString + ": component reports - " + e.getMessage());
207 >                        System.exit(1);
208 >                    }
209 >                }
210 >                else {
211 >                    // it seems the depedencies failed
212 >                    // so we want to try again after a delay
213 >                    System.err.println(toString + ": WARNING Component reported dependency failure");
214                      System.err.println(toString + ": This could be because it can't communicate with components it needs.");
215 <                    System.err.println(toString + ": component reports - " + e2.getMessage());
215 >                    
216 >                    // make a list of the failed components
217 >                    failedComponents.add(component);
218                  }
219              }
220 <            if (componentsToStart.size() > 0) {
220 >            
221 >            // if we had some failed components that we can retry
222 >            if (failedComponents.size() > 0) {
223                  System.err.println(toString + ": WARNING One or more components failed to start correctly.");
224 <                System.err.println(toString + ": Will try again in 5 seconds");
225 <                Thread.sleep(5000);
226 <            } else {
227 <                try {
228 <                    tryAgain = false;
224 >                System.err.println(toString + ": Will try again in " + _startTimeout + " seconds");
225 >            
226 >                // our list is now the failed list
227 >                _componentsToStart = failedComponents;
228 >                
229 >                // sleep for a given timeout
230 >                try {    
231 >                    Thread.sleep(_startTimeout * 1000);
232                  } catch (InterruptedException e) {
233                      // we're not bothered
234                  }
235 +            // otherwise we started everything
236 +            } else {
237 +                // so we set to exit the loop
238 +                tryAgain = false;
239              }
240          }
241                  
242              System.out.println(toString + ": running");
243 +        }
244  
165            // block on the ORB...in time, management functionality can be placed here.
166        refman.getORB().run();
167    }
168
245      /**
246       * A simple method to print the usage of this class.
247       * It never returns, but instead exits to the system
# Line 194 | Line 270 | public class ComponentManager {
270   //---ATTRIBUTES---
271      
272   //---STATIC ATTRIBUTES---
273 +
274 +    private static LinkedList _componentsToStart;
275 +    private static int _startTimeout = 0;
276  
277   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines