1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.componentmanager; |
3 |
|
4 |
//---IMPORTS--- |
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 |
11 |
* server side components of the iscream system. |
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 |
16 |
* |
17 |
* @author $Author: ajm4 $ |
18 |
* @version $Id: ComponentManager.java,v 1.20 2001/02/23 17:21:22 ajm4 Exp $ |
19 |
*/ |
20 |
public class ComponentManager { |
21 |
|
22 |
//---FINAL ATTRIBUTES--- |
23 |
|
24 |
/** |
25 |
* The current CVS revision of this class |
26 |
*/ |
27 |
public static final String REVISION = "$Revision: 1.20 $"; |
28 |
|
29 |
/** |
30 |
* The toString() of this class |
31 |
* As it won't be instatiated, this is needed. |
32 |
* Not also that we pass a null as the class name (as we are static) |
33 |
*/ |
34 |
public static final String toString = FormatName.getName("ComponentManager", null, REVISION); |
35 |
|
36 |
/** |
37 |
* The default location of the properties file for the system |
38 |
*/ |
39 |
public static final String DEFAULTPROPERTIES = "./etc/default.properties"; |
40 |
|
41 |
//---STATIC METHODS--- |
42 |
|
43 |
/** |
44 |
* The main method which starts the components as |
45 |
* listed in the default.properties file. |
46 |
* |
47 |
* @param args the command line arguments |
48 |
*/ |
49 |
public static void main(String[] args) { |
50 |
System.out.println("--- i-scream Server Component Manager ---"); |
51 |
System.out.println("--- Starting System ---"); |
52 |
|
53 |
// get the command line args |
54 |
String defaultProperties = DEFAULTPROPERTIES; |
55 |
String filterName = null; |
56 |
for(int i=0; i < args.length; i++) { |
57 |
if(args[i].equals("-h")) { |
58 |
usage(); |
59 |
} |
60 |
else if(args[i].equals("-f")) { |
61 |
i++; filterName = args[i]; |
62 |
} |
63 |
else if(args[i].equals("-l")) { |
64 |
i++; defaultProperties = args[i]; |
65 |
} |
66 |
else { |
67 |
usage(); |
68 |
} |
69 |
} |
70 |
|
71 |
// load the default properties file into the system properties |
72 |
System.out.println(toString + ": initialising - using " + defaultProperties); |
73 |
try { |
74 |
Properties initProperties = new Properties(System.getProperties()); |
75 |
initProperties.load(new FileInputStream(new File(defaultProperties))); |
76 |
System.setProperties(initProperties); |
77 |
} catch (Exception e) { |
78 |
System.err.println(toString + ": ERROR " + e.getMessage()); |
79 |
usage(); |
80 |
} |
81 |
|
82 |
// continue to bring the system up |
83 |
System.out.println(toString + ": coming up"); |
84 |
|
85 |
// start the ORB by initialising the ReferenceManager |
86 |
ReferenceManager refman = ReferenceManager.getInstance(); |
87 |
|
88 |
// now the ORB is running, we need to activate our RootPOA |
89 |
// so that we can start serving requests once servants start up |
90 |
refman.activatePOA(); |
91 |
|
92 |
// get the list of components |
93 |
String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList"); |
94 |
StringTokenizer st = new StringTokenizer(componentList, ";"); |
95 |
|
96 |
|
97 |
ArrayList componentsToStart = new ArrayList(); |
98 |
|
99 |
// this could be done using reflection |
100 |
// but..well..we don't ;-p |
101 |
while (st.hasMoreTokens()){ |
102 |
String componentName = st.nextToken(); |
103 |
Component component = null; |
104 |
|
105 |
|
106 |
// ### This is where the list of supported components is checked! ### |
107 |
if (componentName.equalsIgnoreCase("core")) { |
108 |
component = new uk.ac.ukc.iscream.core.Core(); |
109 |
} else if (componentName.equalsIgnoreCase("filtermanager")) { |
110 |
component = new uk.ac.ukc.iscream.filtermanager.FilterManager(); |
111 |
} else if (componentName.equalsIgnoreCase("rootfilter")) { |
112 |
component = new uk.ac.ukc.iscream.rootfilter.RootFilter(); |
113 |
} else if (componentName.equalsIgnoreCase("dbinterface")) { |
114 |
component = new uk.ac.ukc.iscream.dbinterface.DBInterface(); |
115 |
} else if (componentName.equalsIgnoreCase("clientinterface")) { |
116 |
component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain(); |
117 |
// note the passing of the Filter's name in its constructor |
118 |
} else if (componentName.equalsIgnoreCase("filter")) { |
119 |
component = new uk.ac.ukc.iscream.filter.FilterMain(filterName); |
120 |
} |
121 |
// ### Add new component constructors in the above section! ### |
122 |
|
123 |
if (component != null) { |
124 |
componentsToStart.add(component); |
125 |
} else { |
126 |
System.err.println(toString + ": WARNING unsupported component not started"); |
127 |
} |
128 |
} |
129 |
|
130 |
boolean tryAgain = true; |
131 |
Component component = null; |
132 |
while(tryAgain) { |
133 |
Iterator i = componentsToStart.iterator(); |
134 |
ArrayList failedComponents = new ArrayList(); |
135 |
while(i.hasNext()) { |
136 |
try { |
137 |
component = (Component) i.next(); |
138 |
System.out.println(toString + ": starting component - " + component.toString()); |
139 |
component.start(); |
140 |
} catch (ComponentStartException e) { |
141 |
System.err.println(toString + ": ERROR starting component - " + component.toString()); |
142 |
System.err.println(toString + ": component reports - " + e.getMessage()); |
143 |
System.exit(1); |
144 |
} catch(ComponentCORBAException e2) { |
145 |
System.err.println(toString + ": WARNING Component reported CORBA communications failure"); |
146 |
System.err.println(toString + ": This could be because it can't communicate with components it needs."); |
147 |
System.err.println(toString + ": component reports - " + e2.getMessage()); |
148 |
failedComponents.add(component); |
149 |
} |
150 |
} |
151 |
if (failedComponents.size() > 0) { |
152 |
System.err.println(toString + ": WARNING One or more components failed to start correctly."); |
153 |
System.err.println(toString + ": Will try again in 5 seconds"); |
154 |
try { |
155 |
Thread.sleep(5000); |
156 |
} catch (InterruptedException e) { |
157 |
// we're not bothered |
158 |
} |
159 |
} else { |
160 |
tryAgain = false; |
161 |
} |
162 |
componentsToStart = failedComponents; |
163 |
} |
164 |
|
165 |
System.out.println(toString + ": running"); |
166 |
|
167 |
// block on the ORB...in time, management functionality can be placed here. |
168 |
refman.getORB().run(); |
169 |
} |
170 |
|
171 |
/** |
172 |
* A simple method to print the usage of this class. |
173 |
* It never returns, but instead exits to the system |
174 |
* with a value 1, to indicate the system did not start |
175 |
* properly. |
176 |
*/ |
177 |
public static void usage() { |
178 |
System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>"); |
179 |
System.out.println(" or: java -jar iscream.jar <option>"); |
180 |
System.out.println("WHERE <option>:"); |
181 |
System.out.println(" -l <filename> - the location of initial system properties"); |
182 |
System.out.println(" the default is ./etc/default.properties"); |
183 |
System.out.println(" -f <name> - the name of the filter (if there is one configured"); |
184 |
System.out.println(" -h - this help screen"); |
185 |
System.exit(1); |
186 |
} |
187 |
|
188 |
//---CONSTRUCTORS--- |
189 |
|
190 |
//---PUBLIC METHODS--- |
191 |
|
192 |
//---PRIVATE METHODS--- |
193 |
|
194 |
//---ACCESSOR/MUTATOR METHODS--- |
195 |
|
196 |
//---ATTRIBUTES--- |
197 |
|
198 |
//---STATIC ATTRIBUTES--- |
199 |
|
200 |
} |