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 |
47 |
|
* @param args the command line arguments |
48 |
|
*/ |
49 |
|
public static void main(String[] args) { |
50 |
< |
System.out.println("--- I-Scream System Component Manager ---"); |
50 |
> |
System.out.println("--- i-scream Server Component Manager ---"); |
51 |
|
System.out.println("--- Starting System ---"); |
52 |
|
|
53 |
|
// get the command line args |
54 |
– |
// this is a bit messy and should be looked at |
54 |
|
String defaultProperties = DEFAULTPROPERTIES; |
55 |
|
String filterName = null; |
56 |
< |
if (args.length > 0) { |
57 |
< |
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 { |
56 |
> |
for(int i=0; i < args.length; i++) { |
57 |
> |
if(args[i].equals("-h")) { |
58 |
|
usage(); |
59 |
< |
} |
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 |
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; |
101 |
– |
System.out.println(toString + ": starting component - " + componentName); |
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(); |
121 |
|
// ### Add new component constructors in the above section! ### |
122 |
|
|
123 |
|
if (component != null) { |
124 |
< |
try { |
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 |
> |
while(i.hasNext()) { |
135 |
> |
try { |
136 |
> |
component = (Component) i.next(); |
137 |
> |
System.out.println(toString + ": starting component - " + component.toString()); |
138 |
|
component.start(); |
139 |
+ |
componentsToStart.remove(componentsToStart.indexOf(component)); |
140 |
|
} catch (ComponentStartException e) { |
141 |
< |
System.err.println(toString + ": ERROR starting component - " + componentName); |
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 |
|
} |
149 |
+ |
} |
150 |
+ |
if (componentsToStart.size() > 0) { |
151 |
+ |
System.err.println(toString + ": WARNING One or more components failed to start correctly."); |
152 |
+ |
System.err.println(toString + ": Will try again in 5 seconds"); |
153 |
+ |
try { |
154 |
+ |
Thread.sleep(5000); |
155 |
+ |
} catch (InterruptedException e) { |
156 |
+ |
// we're not bothered |
157 |
+ |
} |
158 |
|
} else { |
159 |
< |
System.err.println(toString + ": WARNING unsupported component not started"); |
159 |
> |
tryAgain = false; |
160 |
|
} |
161 |
|
} |
162 |
+ |
|
163 |
|
System.out.println(toString + ": running"); |
164 |
< |
|
164 |
> |
|
165 |
|
// block on the ORB...in time, management functionality can be placed here. |
166 |
|
refman.getORB().run(); |
167 |
|
} |
174 |
|
*/ |
175 |
|
public static void usage() { |
176 |
|
System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>"); |
177 |
+ |
System.out.println(" or: java -jar iscream.jar <option>"); |
178 |
|
System.out.println("WHERE <option>:"); |
179 |
|
System.out.println(" -l <filename> - the location of initial system properties"); |
180 |
|
System.out.println(" the default is ./etc/default.properties"); |