1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.componentmanager; |
2 |
> |
package uk.org.iscream.componentmanager; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.util.*; |
6 |
|
import java.io.*; |
7 |
< |
import uk.ac.ukc.iscream.util.*; |
7 |
> |
import uk.org.iscream.util.*; |
8 |
|
|
9 |
|
/** |
10 |
|
* The component manager is the starting point for all |
12 |
|
* It loads its initial system configuration from the |
13 |
|
* default properties file, it then starts all the iscream |
14 |
|
* components as specified in the default.properties under |
15 |
< |
* uk.ac.ukc.iscream.ComponentList |
15 |
> |
* uk.org.iscream.ComponentList |
16 |
|
* |
17 |
|
* @author $Author$ |
18 |
|
* @version $Id$ |
96 |
|
refman.activatePOA(); |
97 |
|
|
98 |
|
// get the list of components |
99 |
< |
String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList"); |
99 |
> |
String componentList = System.getProperty("uk.org.iscream.ComponentList"); |
100 |
|
StringTokenizer st = new StringTokenizer(componentList, ";"); |
101 |
< |
_componentsToStart = new ArrayList(); |
101 |
> |
_componentsToStart = new LinkedList(); |
102 |
|
|
103 |
|
// this could be done using reflection |
104 |
|
// but..well..we don't ;-p |
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(); |
112 |
> |
component = new uk.org.iscream.core.Core(); |
113 |
|
} else if (componentName.equalsIgnoreCase("filtermanager")) { |
114 |
< |
component = new uk.ac.ukc.iscream.filtermanager.FilterManager(); |
114 |
> |
component = new uk.org.iscream.filtermanager.FilterManager(); |
115 |
|
} else if (componentName.equalsIgnoreCase("rootfilter")) { |
116 |
< |
component = new uk.ac.ukc.iscream.rootfilter.RootFilter(); |
116 |
> |
component = new uk.org.iscream.rootfilter.RootFilter(); |
117 |
|
} else if (componentName.equalsIgnoreCase("dbinterface")) { |
118 |
< |
component = new uk.ac.ukc.iscream.dbinterface.DBInterface(); |
118 |
> |
component = new uk.org.iscream.dbinterface.DBInterface(); |
119 |
|
} else if (componentName.equalsIgnoreCase("clientinterface")) { |
120 |
< |
component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain(); |
120 |
> |
component = new uk.org.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); |
123 |
> |
component = new uk.org.iscream.filter.FilterMain(filterName); |
124 |
|
} else if (componentName.equalsIgnoreCase("client")) { |
125 |
< |
component = new uk.ac.ukc.iscream.client.ClientMain(); |
125 |
> |
component = new uk.org.iscream.client.ClientMain(); |
126 |
|
} |
127 |
|
// ### Add new component constructors in the above section! ### |
128 |
|
|
130 |
|
if (component != null) { |
131 |
|
_componentsToStart.add(component); |
132 |
|
} else { |
133 |
< |
System.err.println(toString + ": WARNING unsupported component not started"); |
133 |
> |
System.err.println(toString + ": WARNING unsupported component not started: "+componentName); |
134 |
|
} |
135 |
|
} |
136 |
|
|
140 |
|
|
141 |
|
String confTimeout = null; |
142 |
|
try { |
143 |
< |
confTimeout = System.getProperty("uk.ac.ukc.iscream.ComponentTimeout"); |
143 |
> |
confTimeout = System.getProperty("uk.org.iscream.ComponentTimeout"); |
144 |
|
confTimeout.trim(); |
145 |
|
_startTimeout = Integer.parseInt(confTimeout); |
146 |
|
} catch (NumberFormatException e) { |
147 |
|
_startTimeout = DEFAULT_COMPONENT_START_TIMEOUT; |
148 |
< |
System.err.println(toString + ": unable to read uk.ac.ukc.iscream.ComponentTimeout value (" + confTimeout + "), using default!"); |
148 |
> |
System.err.println(toString + ": unable to read uk.org.iscream.ComponentTimeout value (" + confTimeout + "), using default!"); |
149 |
|
} |
150 |
|
System.out.println(toString + ": using component start timeout of " + _startTimeout + " seconds"); |
151 |
|
|
154 |
|
|
155 |
|
// block on the ORB...in time, management functionality can be placed here. |
156 |
|
// if we detect a CORBA communication error, we'll restart all the components. |
157 |
+ |
// !! this doesn't appear to work !! |
158 |
|
while(true) { |
159 |
|
try { |
160 |
|
refman.getORB().run(); |
171 |
|
* This method calls the start() methods on all the components. |
172 |
|
* If a component fails to start due to a CORBA communication |
173 |
|
* problem, then it catches this and tries to start it again |
174 |
< |
* according to uk.ac.ukc.iscream.ComponentTimeout time. |
174 |
> |
* according to uk.org.iscream.ComponentTimeout time. |
175 |
|
* |
176 |
|
* If the server dies and CORBA connections are lost, this method |
177 |
|
* is called again. |
185 |
|
// maybe add support for a limited number of retries |
186 |
|
while(tryAgain) { |
187 |
|
Iterator i = _componentsToStart.iterator(); |
188 |
< |
ArrayList failedComponents = new ArrayList(); |
188 |
> |
LinkedList failedComponents = new LinkedList(); |
189 |
|
// go through all the components |
190 |
|
while(i.hasNext()) { |
191 |
< |
try { |
192 |
< |
component = (Component) i.next(); |
193 |
< |
System.out.println(toString + ": starting component - " + component.toString()); |
194 |
< |
|
195 |
< |
// start the component |
196 |
< |
component.start(); |
197 |
< |
|
198 |
< |
// if we get this then there was a problem |
199 |
< |
// that we can't recover from |
200 |
< |
} catch (ComponentStartException e) { |
201 |
< |
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
202 |
< |
System.err.println(toString + ": component reports - " + e.getMessage()); |
203 |
< |
System.exit(1); |
204 |
< |
|
205 |
< |
// if we get this exception then we've tried |
206 |
< |
// to talk to something which may not be up yet |
207 |
< |
// so we want to try again in a minute |
208 |
< |
} catch(ComponentCORBAException e2) { |
209 |
< |
System.err.println(toString + ": WARNING Component reported CORBA communications failure"); |
191 |
> |
// get a refence to the component |
192 |
> |
component = (Component) i.next(); |
193 |
> |
System.out.println(toString + ": starting component - " + component.toString()); |
194 |
> |
|
195 |
> |
// check it's dependencies |
196 |
> |
boolean depOK = component.depCheck(); |
197 |
> |
if(depOK) { |
198 |
> |
// it should be ok to start the component |
199 |
> |
try { |
200 |
> |
// start the component |
201 |
> |
component.start(); |
202 |
> |
} catch (ComponentStartException e) { |
203 |
> |
// if we get this then there was a problem |
204 |
> |
// that we can't recover from |
205 |
> |
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
206 |
> |
System.err.println(toString + ": component reports - " + e.getMessage()); |
207 |
> |
System.exit(1); |
208 |
> |
} |
209 |
> |
} |
210 |
> |
else { |
211 |
> |
// it seems the depedencies failed |
212 |
> |
// so we want to try again after a delay |
213 |
> |
System.err.println(toString + ": WARNING Component reported dependency failure"); |
214 |
|
System.err.println(toString + ": This could be because it can't communicate with components it needs."); |
210 |
– |
System.err.println(toString + ": component reports - " + e2.getMessage()); |
215 |
|
|
216 |
|
// make a list of the failed components |
217 |
|
failedComponents.add(component); |
249 |
|
* properly. |
250 |
|
*/ |
251 |
|
public static void usage() { |
252 |
< |
System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>"); |
252 |
> |
System.out.println("USAGE: java uk.org.iscream.componentmanager.ComponentManager <option>"); |
253 |
|
System.out.println(" or: java -jar iscream.jar <option>"); |
254 |
|
System.out.println("WHERE <option>:"); |
255 |
|
System.out.println(" -l <filename> - the location of initial system properties"); |
271 |
|
|
272 |
|
//---STATIC ATTRIBUTES--- |
273 |
|
|
274 |
< |
private static ArrayList _componentsToStart; |
274 |
> |
private static LinkedList _componentsToStart; |
275 |
|
private static int _startTimeout = 0; |
276 |
|
|
277 |
|
} |