1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.componentmanager; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import java.util.*; |
6 |
|
|
import java.io.*; |
7 |
|
|
|
8 |
|
|
/** |
9 |
ajm |
1.2 |
* The component manager is the starting point for all |
10 |
|
|
* server side components of the iscream system. |
11 |
|
|
* It loads its initial system configuration from the |
12 |
|
|
* default properties file, it then starts all the iscream |
13 |
|
|
* components as specified in the default.properties under |
14 |
|
|
* uk.ac.ukc.iscream.ComponentList |
15 |
ajm |
1.1 |
* |
16 |
tdb |
1.9 |
* @author $Author: tdb1 $ |
17 |
|
|
* @version $Id: ComponentManager.java,v 1.8 2001/01/08 13:07:48 tdb1 Exp $ |
18 |
ajm |
1.1 |
*/ |
19 |
|
|
public class ComponentManager { |
20 |
|
|
|
21 |
|
|
//---FINAL ATTRIBUTES--- |
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* The current CVS revision of this class |
25 |
|
|
*/ |
26 |
tdb |
1.9 |
public static final String REVISION = "$Revision: 1.8 $"; |
27 |
ajm |
1.1 |
|
28 |
|
|
/** |
29 |
|
|
* The toString() of this class |
30 |
|
|
* As it won't be instatiated, this is needed. |
31 |
ajm |
1.2 |
* Not also that we pass a null as the class name (as we are static) |
32 |
ajm |
1.1 |
*/ |
33 |
ajm |
1.2 |
public static final String toString = FormatName.getName("ComponentManager", null, REVISION); |
34 |
ajm |
1.1 |
|
35 |
|
|
/** |
36 |
|
|
* The default location of the properties file for the system |
37 |
|
|
*/ |
38 |
ajm |
1.2 |
public static final String DEFAULTPROPERTIES = "./etc/default.properties"; |
39 |
ajm |
1.1 |
|
40 |
|
|
//---STATIC METHODS--- |
41 |
|
|
|
42 |
|
|
/** |
43 |
ajm |
1.2 |
* The main method which starts the components as |
44 |
|
|
* listed in the default.properties file. |
45 |
ajm |
1.1 |
* |
46 |
|
|
* @param args the command line arguments |
47 |
|
|
*/ |
48 |
|
|
public static void main(String[] args) { |
49 |
|
|
System.out.println("--- I-Scream System Component Manager ---"); |
50 |
ajm |
1.2 |
System.out.println("--- Starting System ---"); |
51 |
|
|
|
52 |
ajm |
1.1 |
// get the command line args |
53 |
|
|
// 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")) { |
58 |
|
|
defaultProperties = args[1]; |
59 |
|
|
} else if (args[0].equals("-f")) { |
60 |
|
|
filterName = args[1]; |
61 |
|
|
} else if (args[2].equals("-l")) { |
62 |
|
|
filterName = args[3]; |
63 |
|
|
} else if (args[2].equals("-f")) { |
64 |
|
|
filterName = args[3]; |
65 |
|
|
} else { |
66 |
|
|
usage(); |
67 |
|
|
} |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
// load the default properties file into the system properties |
71 |
|
|
System.out.println(toString + ": initialising - using " + defaultProperties); |
72 |
|
|
try { |
73 |
|
|
Properties initProperties = new Properties(System.getProperties()); |
74 |
|
|
initProperties.load(new FileInputStream(new File(defaultProperties))); |
75 |
|
|
System.setProperties(initProperties); |
76 |
|
|
} catch (Exception e) { |
77 |
|
|
System.err.println(toString + ": ERROR " + e.getMessage()); |
78 |
|
|
usage(); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
// continue to bring the system up |
82 |
|
|
System.out.println(toString + ": coming up"); |
83 |
|
|
|
84 |
|
|
// start the ORB by initialising the ReferenceManager |
85 |
ajm |
1.2 |
ReferenceManager refman = ReferenceManager.getInstance(); |
86 |
ajm |
1.1 |
|
87 |
ajm |
1.2 |
// now the ORB is running, we need to activate our RootPOA |
88 |
|
|
// so that we can start serving requests once servants start up |
89 |
ajm |
1.1 |
refman.activatePOA(); |
90 |
|
|
|
91 |
ajm |
1.2 |
// get the list of components |
92 |
ajm |
1.1 |
String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList"); |
93 |
|
|
StringTokenizer st = new StringTokenizer(componentList, ";"); |
94 |
|
|
|
95 |
|
|
// this could be done using reflection |
96 |
|
|
// but..well..we don't ;-p |
97 |
|
|
while (st.hasMoreTokens()){ |
98 |
|
|
String componentName = st.nextToken(); |
99 |
|
|
Component component = null; |
100 |
|
|
System.out.println(toString + ": starting component - " + componentName); |
101 |
ajm |
1.2 |
|
102 |
|
|
// ### This is where the list of supported components is checked! ### |
103 |
|
|
if (componentName.equalsIgnoreCase("core")) { |
104 |
ajm |
1.1 |
component = new uk.ac.ukc.iscream.core.Core(); |
105 |
ajm |
1.3 |
} else if (componentName.equalsIgnoreCase("filtermanager")) { |
106 |
|
|
component = new uk.ac.ukc.iscream.filtermanager.FilterManager(); |
107 |
ajm |
1.4 |
} else if (componentName.equalsIgnoreCase("rootfilter")) { |
108 |
|
|
component = new uk.ac.ukc.iscream.rootfilter.RootFilter(); |
109 |
ajm |
1.5 |
} else if (componentName.equalsIgnoreCase("dbinterface")) { |
110 |
|
|
component = new uk.ac.ukc.iscream.dbinterface.DBInterface(); |
111 |
ajm |
1.6 |
} else if (componentName.equalsIgnoreCase("clientinterface")) { |
112 |
|
|
component = new uk.ac.ukc.iscream.clientinterface.ClientInterfaceMain(); |
113 |
ajm |
1.7 |
// note the passing of the Filter's name in its constructor |
114 |
|
|
} else if (componentName.equalsIgnoreCase("filter")) { |
115 |
|
|
component = new uk.ac.ukc.iscream.filter.FilterMain(filterName); |
116 |
ajm |
1.1 |
} |
117 |
ajm |
1.2 |
// ### Add new component constructors in the above section! ### |
118 |
ajm |
1.3 |
|
119 |
ajm |
1.1 |
if (component != null) { |
120 |
ajm |
1.2 |
try { |
121 |
|
|
component.start(); |
122 |
|
|
} catch (ComponentStartException e) { |
123 |
ajm |
1.1 |
System.err.println(toString + ": ERROR starting component - " + componentName); |
124 |
ajm |
1.2 |
System.err.println(toString + ": component reports - " + e.getMessage()); |
125 |
ajm |
1.1 |
System.exit(1); |
126 |
|
|
} |
127 |
|
|
} else { |
128 |
|
|
System.err.println(toString + ": WARNING unsupported component not started"); |
129 |
|
|
} |
130 |
|
|
} |
131 |
ajm |
1.3 |
System.out.println(toString + ": running"); |
132 |
ajm |
1.2 |
|
133 |
|
|
// block on the ORB...in time, management functionality can be placed here. |
134 |
ajm |
1.1 |
refman.getORB().run(); |
135 |
|
|
} |
136 |
ajm |
1.3 |
|
137 |
|
|
/** |
138 |
ajm |
1.1 |
* A simple method to print the usage of this class. |
139 |
|
|
* It never returns, but instead exits to the system |
140 |
|
|
* with a value 1, to indicate the system did not start |
141 |
|
|
* properly. |
142 |
|
|
*/ |
143 |
|
|
public static void usage() { |
144 |
|
|
System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>"); |
145 |
tdb |
1.8 |
System.out.println(" or: java -jar iscream.jar <option>"); |
146 |
ajm |
1.1 |
System.out.println("WHERE <option>:"); |
147 |
|
|
System.out.println(" -l <filename> - the location of initial system properties"); |
148 |
ajm |
1.2 |
System.out.println(" the default is ./etc/default.properties"); |
149 |
ajm |
1.1 |
System.out.println(" -f <name> - the name of the filter (if there is one configured"); |
150 |
|
|
System.out.println(" -h - this help screen"); |
151 |
|
|
System.exit(1); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
//---CONSTRUCTORS--- |
155 |
|
|
|
156 |
|
|
//---PUBLIC METHODS--- |
157 |
|
|
|
158 |
|
|
//---PRIVATE METHODS--- |
159 |
|
|
|
160 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
161 |
|
|
|
162 |
|
|
//---ATTRIBUTES--- |
163 |
|
|
|
164 |
|
|
//---STATIC ATTRIBUTES--- |
165 |
|
|
|
166 |
|
|
} |