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 |
|
/** |
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 |
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 { |
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 + ": invalid value for ComponentTimeout, using default value of " + startTimeout + " seconds!"); |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
// keep trying until we've started all the components. |
149 |
+ |
// maybe add support for a limited number of retries |
150 |
|
while(tryAgain) { |
151 |
|
Iterator i = componentsToStart.iterator(); |
152 |
+ |
ArrayList failedComponents = new ArrayList(); |
153 |
+ |
// go through all the components |
154 |
|
while(i.hasNext()) { |
155 |
|
try { |
156 |
|
component = (Component) i.next(); |
157 |
|
System.out.println(toString + ": starting component - " + component.toString()); |
158 |
+ |
|
159 |
+ |
// start the component |
160 |
|
component.start(); |
161 |
< |
componentsToStart.remove(componentsToStart.indexOf(component)); |
161 |
> |
|
162 |
> |
// if we get this then there was a problem |
163 |
> |
// that we can't recover from |
164 |
|
} catch (ComponentStartException e) { |
165 |
|
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
166 |
|
System.err.println(toString + ": component reports - " + e.getMessage()); |
167 |
|
System.exit(1); |
168 |
+ |
|
169 |
+ |
// if we get this exception then we've tried |
170 |
+ |
// to talk to something which may not be up yet |
171 |
+ |
// so we want to try again in a minute |
172 |
|
} catch(ComponentCORBAException e2) { |
173 |
|
System.err.println(toString + ": WARNING Component reported CORBA communications failure"); |
174 |
|
System.err.println(toString + ": This could be because it can't communicate with components it needs."); |
175 |
|
System.err.println(toString + ": component reports - " + e2.getMessage()); |
176 |
+ |
|
177 |
+ |
// make a list of the failed components |
178 |
+ |
failedComponents.add(component); |
179 |
|
} |
180 |
|
} |
181 |
< |
if (componentsToStart.size() > 0) { |
181 |
> |
|
182 |
> |
// if we had some failed components that we can retry |
183 |
> |
if (failedComponents.size() > 0) { |
184 |
|
System.err.println(toString + ": WARNING One or more components failed to start correctly."); |
185 |
< |
System.err.println(toString + ": Will try again in 5 seconds"); |
185 |
> |
System.err.println(toString + ": Will try again in " + startTimeout + " seconds"); |
186 |
> |
|
187 |
> |
// our list is now the failed list |
188 |
> |
componentsToStart = failedComponents; |
189 |
> |
|
190 |
> |
// sleep for a given timeout |
191 |
|
try { |
192 |
< |
Thread.sleep(5000); |
192 |
> |
Thread.sleep(startTimeout * 1000); |
193 |
|
} catch (InterruptedException e) { |
194 |
|
// we're not bothered |
195 |
|
} |
196 |
+ |
// otherwise we started everything |
197 |
|
} else { |
198 |
+ |
// so we set to exit the loop |
199 |
|
tryAgain = false; |
200 |
|
} |
201 |
|
} |