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