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.31 by ajm, Thu Mar 1 16:36:52 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, ";");
95        
96
101          ArrayList componentsToStart = new ArrayList();
102          
103          // this could be done using reflection
# 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);    
132              } else {
# Line 127 | Line 134 | public class ComponentManager {
134              }
135          }
136          
137 +        // now we try and start the beast up        
138          boolean tryAgain = true;
139          Component component = null;
140 +
141 +        // get the value for timeout
142 +        int startTimeout = 0;
143 +        String confTimeout = null;
144 +        try {
145 +            confTimeout = System.getProperty("uk.ac.ukc.iscream.ComponentTimeout");
146 +            confTimeout.trim();
147 +            startTimeout = Integer.parseInt(confTimeout);
148 +        } catch (NumberFormatException e) {
149 +            startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
150 +            System.err.println(toString + ": unable to read uk.ac.ukc.iscream.ComponentTimeout value (" + confTimeout + "), using default!");
151 +        }
152 +        System.out.println(toString + ": using component start timeout of " + startTimeout + " seconds");
153 +        
154 +        // startup the system components
155 +        startUp();
156 +
157 +            // block on the ORB...in time, management functionality can be placed here.
158 +            // if we detect a CORBA communication error, we'll restart all the components.
159 +            while(true) {
160 +            try {
161 +                refman.getORB().run();
162 +            } catch (org.omg.CORBA.COMM_FAILURE e) (
163 +                System.out.println(toString + ": WARNING CORBA communications failure - " + e.getMessage());
164 +                System.out.println(toString + ": WARNING CORBA connections have been lost - attempting to restart!");
165 +            }
166 +            startUp();
167 +        }
168 +    }
169 +
170 +    /**
171 +     * Starts the components as obtained from the configuration.
172 +     * This method calls the start() methods on all the components.
173 +     * If a component fails to start due to a CORBA communication
174 +     * problem, then it catches this and tries to start it again
175 +     * according to uk.ac.ukc.iscream.ComponentTimeout time.
176 +     *
177 +     * If the server dies and CORBA connections are lost, this method
178 +     * is called again.
179 +     */
180 +    private static void startUp() {
181 +        // keep trying until we've started all the components.
182 +        // maybe add support for a limited number of retries
183          while(tryAgain) {
184              Iterator i = componentsToStart.iterator();
185 +            ArrayList failedComponents = new ArrayList();
186 +            // go through all the components
187              while(i.hasNext()) {
188                  try {
189                      component = (Component) i.next();
190                      System.out.println(toString + ": starting component - " + component.toString());
191 +                    
192 +                    // start the component
193                      component.start();
194 <                    componentsToStart.remove(componentsToStart.indexOf(component));
194 >                    
195 >                // if we get this then there was a problem
196 >                // that we can't recover from
197                  } catch (ComponentStartException e) {
198                      System.err.println(toString + ": ERROR starting component - " + component.toString());
199                      System.err.println(toString + ": component reports - " + e.getMessage());
200                      System.exit(1);
201 +
202 +                // if we get this exception then we've tried
203 +                // to talk to something which may not be up yet
204 +                // so we want to try again in a minute                
205                  } catch(ComponentCORBAException e2) {
206                      System.err.println(toString + ": WARNING Component reported CORBA communications failure");
207                      System.err.println(toString + ": This could be because it can't communicate with components it needs.");
208                      System.err.println(toString + ": component reports - " + e2.getMessage());
209 +                    
210 +                    // make a list of the failed components
211 +                    failedComponents.add(component);
212                  }
213              }
214 <            if (componentsToStart.size() > 0) {
214 >            
215 >            // if we had some failed components that we can retry
216 >            if (failedComponents.size() > 0) {
217                  System.err.println(toString + ": WARNING One or more components failed to start correctly.");
218 <                System.err.println(toString + ": Will try again in 5 seconds");
219 <                Thread.sleep(5000);
220 <            } else {
221 <                try {
222 <                    tryAgain = false;
218 >                System.err.println(toString + ": Will try again in " + startTimeout + " seconds");
219 >            
220 >                // our list is now the failed list
221 >                componentsToStart = failedComponents;
222 >                
223 >                // sleep for a given timeout
224 >                try {    
225 >                    Thread.sleep(startTimeout * 1000);
226                  } catch (InterruptedException e) {
227                      // we're not bothered
228                  }
229 +            // otherwise we started everything
230 +            } else {
231 +                // so we set to exit the loop
232 +                tryAgain = false;
233              }
234          }
235                  
236              System.out.println(toString + ": running");
237 <
165 <            // block on the ORB...in time, management functionality can be placed here.
166 <        refman.getORB().run();
167 <    }
237 >        }
238  
239      /**
240       * A simple method to print the usage of this class.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines