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.24 by ajm, Fri Feb 23 17:56: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, ";");
95        
96
101          ArrayList componentsToStart = new ArrayList();
102          
103          // this could be done using reflection
# Line 120 | Line 124 | public class ComponentManager {
124              }
125              // ###  Add new component constructors in the above section! ###
126              
127 +            // build the list of components to start
128              if (component != null) {
129                  componentsToStart.add(component);    
130              } else {
# Line 127 | Line 132 | public class ComponentManager {
132              }
133          }
134          
135 +        // now we try and start the beast up        
136          boolean tryAgain = true;
137          Component component = null;
138 +
139 +        // get the value for timeout
140 +        int startTimeout;
141 +        try {
142 +            startTimeout = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.ComponentTimeout"));
143 +        } catch (NumberFormatException e) {
144 +            startTimeout = DEFAULT_COMPONENT_START_TIMEOUT;
145 +            System.err.println(toString + ": unable to read uk.ac.ukc.iscream.ComponentTimeout value, using default!");
146 +        }
147 +        System.out.println(toString + ": using component start timeout of " + startTimeout + " seconds");
148 +        
149 +        // keep trying until we've started all the components.
150 +        // maybe add support for a limited number of retries
151          while(tryAgain) {
152              Iterator i = componentsToStart.iterator();
153 +            ArrayList failedComponents = new ArrayList();
154 +            // go through all the components
155              while(i.hasNext()) {
156                  try {
157                      component = (Component) i.next();
158                      System.out.println(toString + ": starting component - " + component.toString());
159 +                    
160 +                    // start the component
161                      component.start();
162 <                    componentsToStart.remove(componentsToStart.indexOf(component));
162 >                    
163 >                // if we get this then there was a problem
164 >                // that we can't recover from
165                  } catch (ComponentStartException e) {
166                      System.err.println(toString + ": ERROR starting component - " + component.toString());
167                      System.err.println(toString + ": component reports - " + e.getMessage());
168                      System.exit(1);
169 +
170 +                // if we get this exception then we've tried
171 +                // to talk to something which may not be up yet
172 +                // so we want to try again in a minute                
173                  } catch(ComponentCORBAException e2) {
174                      System.err.println(toString + ": WARNING Component reported CORBA communications failure");
175                      System.err.println(toString + ": This could be because it can't communicate with components it needs.");
176                      System.err.println(toString + ": component reports - " + e2.getMessage());
177 +                    
178 +                    // make a list of the failed components
179 +                    failedComponents.add(component);
180                  }
181              }
182 <            if (componentsToStart.size() > 0) {
182 >            
183 >            // if we had some failed components that we can retry
184 >            if (failedComponents.size() > 0) {
185                  System.err.println(toString + ": WARNING One or more components failed to start correctly.");
186 <                System.err.println(toString + ": Will try again in 5 seconds");
187 <                Thread.sleep(5000);
188 <            } else {
189 <                try {
190 <                    tryAgain = false;
186 >                System.err.println(toString + ": Will try again in " + startTimeout + " seconds");
187 >            
188 >                // our list is now the failed list
189 >                componentsToStart = failedComponents;
190 >                
191 >                // sleep for a given timeout
192 >                try {    
193 >                    Thread.sleep(startTimeout * 1000);
194                  } catch (InterruptedException e) {
195                      // we're not bothered
196                  }
197 +            // otherwise we started everything
198 +            } else {
199 +                // so we set to exit the loop
200 +                tryAgain = false;
201              }
202          }
203                  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines