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.30 by tdb, Sun Feb 25 21:00:37 2001 UTC

# Line 2 | Line 2
2   package uk.ac.ukc.iscream.componentmanager;
3  
4   //---IMPORTS---
5 import uk.ac.ukc.iscream.util.*;
5   import java.util.*;
6   import java.io.*;
7 + import uk.ac.ukc.iscream.util.*;
8  
9   /**
10   * The component manager is the starting point for all
# 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 +        ArrayList 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 109 | Line 116 | public class ComponentManager {
116                  component = new uk.ac.ukc.iscream.rootfilter.RootFilter();
117              } else if (componentName.equalsIgnoreCase("dbinterface")) {
118                  component = new uk.ac.ukc.iscream.dbinterface.DBInterface();
119 +            } else if (componentName.equalsIgnoreCase("clientinterface")) {
120 +                component = new uk.ac.ukc.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.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 >        // 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 >        // keep trying until we've started all the components.
155 >        // maybe add support for a limited number of retries
156 >        while(tryAgain) {
157 >            Iterator i = componentsToStart.iterator();
158 >            ArrayList failedComponents = new ArrayList();
159 >            // go through all the components
160 >            while(i.hasNext()) {
161 >                try {
162 >                    component = (Component) i.next();
163 >                    System.out.println(toString + ": starting component - " + component.toString());
164 >                    
165 >                    // start the component
166                      component.start();
167 +                    
168 +                // if we get this then there was a problem
169 +                // that we can't recover from
170                  } catch (ComponentStartException e) {
171 <                    System.err.println(toString + ": ERROR starting component - " + componentName);
171 >                    System.err.println(toString + ": ERROR starting component - " + component.toString());
172                      System.err.println(toString + ": component reports - " + e.getMessage());
173                      System.exit(1);
174 +
175 +                // if we get this exception then we've tried
176 +                // to talk to something which may not be up yet
177 +                // so we want to try again in a minute                
178 +                } catch(ComponentCORBAException e2) {
179 +                    System.err.println(toString + ": WARNING Component reported CORBA communications failure");
180 +                    System.err.println(toString + ": This could be because it can't communicate with components it needs.");
181 +                    System.err.println(toString + ": component reports - " + e2.getMessage());
182 +                    
183 +                    // make a list of the failed components
184 +                    failedComponents.add(component);
185                  }
186 +            }
187 +            
188 +            // if we had some failed components that we can retry
189 +            if (failedComponents.size() > 0) {
190 +                System.err.println(toString + ": WARNING One or more components failed to start correctly.");
191 +                System.err.println(toString + ": Will try again in " + startTimeout + " seconds");
192 +            
193 +                // our list is now the failed list
194 +                componentsToStart = failedComponents;
195 +                
196 +                // sleep for a given timeout
197 +                try {    
198 +                    Thread.sleep(startTimeout * 1000);
199 +                } catch (InterruptedException e) {
200 +                    // we're not bothered
201 +                }
202 +            // otherwise we started everything
203              } else {
204 <                System.err.println(toString + ": WARNING unsupported component not started");
204 >                // so we set to exit the loop
205 >                tryAgain = false;
206              }
207          }
208 +                
209              System.out.println(toString + ": running");
210 <            
210 >
211              // block on the ORB...in time, management functionality can be placed here.
212          refman.getORB().run();
213      }
# Line 138 | Line 220 | public class ComponentManager {
220       */
221      public static void usage() {
222          System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>");
223 +        System.out.println("   or: java -jar iscream.jar <option>");
224          System.out.println("WHERE <option>:");
225          System.out.println("      -l <filename> - the location of initial system properties");
226          System.out.println("                      the default is ./etc/default.properties");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines