1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.componentmanager; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
ajm |
1.2 |
import uk.ac.ukc.iscream.util.*; |
6 |
ajm |
1.1 |
import java.util.*; |
7 |
|
|
import java.io.*; |
8 |
|
|
|
9 |
|
|
/** |
10 |
ajm |
1.2 |
* 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 |
ajm |
1.1 |
* |
17 |
|
|
* @author $Author: ajm4 $ |
18 |
ajm |
1.5 |
* @version $Id: ComponentManager.java,v 1.4 2000/12/12 19:56:52 ajm4 Exp $ |
19 |
ajm |
1.1 |
*/ |
20 |
|
|
public class ComponentManager { |
21 |
|
|
|
22 |
|
|
//---FINAL ATTRIBUTES--- |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* The current CVS revision of this class |
26 |
|
|
*/ |
27 |
ajm |
1.5 |
public static final String REVISION = "$Revision: 1.4 $"; |
28 |
ajm |
1.1 |
|
29 |
|
|
/** |
30 |
|
|
* The toString() of this class |
31 |
|
|
* As it won't be instatiated, this is needed. |
32 |
ajm |
1.2 |
* Not also that we pass a null as the class name (as we are static) |
33 |
ajm |
1.1 |
*/ |
34 |
ajm |
1.2 |
public static final String toString = FormatName.getName("ComponentManager", null, REVISION); |
35 |
ajm |
1.1 |
|
36 |
|
|
/** |
37 |
|
|
* The default location of the properties file for the system |
38 |
|
|
*/ |
39 |
ajm |
1.2 |
public static final String DEFAULTPROPERTIES = "./etc/default.properties"; |
40 |
ajm |
1.1 |
|
41 |
|
|
//---STATIC METHODS--- |
42 |
|
|
|
43 |
|
|
/** |
44 |
ajm |
1.2 |
* The main method which starts the components as |
45 |
|
|
* listed in the default.properties file. |
46 |
ajm |
1.1 |
* |
47 |
|
|
* @param args the command line arguments |
48 |
|
|
*/ |
49 |
|
|
public static void main(String[] args) { |
50 |
|
|
System.out.println("--- I-Scream System Component Manager ---"); |
51 |
ajm |
1.2 |
System.out.println("--- Starting System ---"); |
52 |
|
|
|
53 |
ajm |
1.1 |
// get the command line args |
54 |
|
|
// this is a bit messy and should be looked at |
55 |
|
|
String defaultProperties = DEFAULTPROPERTIES; |
56 |
|
|
String filterName = null; |
57 |
|
|
if (args.length > 0) { |
58 |
|
|
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 { |
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 |
ajm |
1.2 |
ReferenceManager refman = ReferenceManager.getInstance(); |
87 |
ajm |
1.1 |
|
88 |
ajm |
1.2 |
// now the ORB is running, we need to activate our RootPOA |
89 |
|
|
// so that we can start serving requests once servants start up |
90 |
ajm |
1.1 |
refman.activatePOA(); |
91 |
|
|
|
92 |
ajm |
1.2 |
// get the list of components |
93 |
ajm |
1.1 |
String componentList = System.getProperty("uk.ac.ukc.iscream.ComponentList"); |
94 |
|
|
StringTokenizer st = new StringTokenizer(componentList, ";"); |
95 |
|
|
|
96 |
|
|
// this could be done using reflection |
97 |
|
|
// but..well..we don't ;-p |
98 |
|
|
while (st.hasMoreTokens()){ |
99 |
|
|
String componentName = st.nextToken(); |
100 |
|
|
Component component = null; |
101 |
|
|
System.out.println(toString + ": starting component - " + componentName); |
102 |
ajm |
1.2 |
|
103 |
|
|
// ### This is where the list of supported components is checked! ### |
104 |
|
|
if (componentName.equalsIgnoreCase("core")) { |
105 |
ajm |
1.1 |
component = new uk.ac.ukc.iscream.core.Core(); |
106 |
ajm |
1.3 |
} else if (componentName.equalsIgnoreCase("filtermanager")) { |
107 |
|
|
component = new uk.ac.ukc.iscream.filtermanager.FilterManager(); |
108 |
ajm |
1.4 |
} else if (componentName.equalsIgnoreCase("rootfilter")) { |
109 |
|
|
component = new uk.ac.ukc.iscream.rootfilter.RootFilter(); |
110 |
ajm |
1.5 |
} else if (componentName.equalsIgnoreCase("dbinterface")) { |
111 |
|
|
component = new uk.ac.ukc.iscream.dbinterface.DBInterface(); |
112 |
ajm |
1.1 |
} |
113 |
ajm |
1.2 |
// ### Add new component constructors in the above section! ### |
114 |
ajm |
1.3 |
|
115 |
ajm |
1.1 |
if (component != null) { |
116 |
ajm |
1.2 |
try { |
117 |
|
|
component.start(); |
118 |
|
|
} catch (ComponentStartException e) { |
119 |
ajm |
1.1 |
System.err.println(toString + ": ERROR starting component - " + componentName); |
120 |
ajm |
1.2 |
System.err.println(toString + ": component reports - " + e.getMessage()); |
121 |
ajm |
1.1 |
System.exit(1); |
122 |
|
|
} |
123 |
|
|
} else { |
124 |
|
|
System.err.println(toString + ": WARNING unsupported component not started"); |
125 |
|
|
} |
126 |
|
|
} |
127 |
ajm |
1.3 |
System.out.println(toString + ": running"); |
128 |
ajm |
1.2 |
|
129 |
|
|
// block on the ORB...in time, management functionality can be placed here. |
130 |
ajm |
1.1 |
refman.getORB().run(); |
131 |
|
|
} |
132 |
ajm |
1.3 |
|
133 |
|
|
/** |
134 |
ajm |
1.1 |
* A simple method to print the usage of this class. |
135 |
|
|
* It never returns, but instead exits to the system |
136 |
|
|
* with a value 1, to indicate the system did not start |
137 |
|
|
* properly. |
138 |
|
|
*/ |
139 |
|
|
public static void usage() { |
140 |
|
|
System.out.println("USAGE: java uk.ac.ukc.iscream.componentmanager.ComponentManager <option>"); |
141 |
|
|
System.out.println("WHERE <option>:"); |
142 |
|
|
System.out.println(" -l <filename> - the location of initial system properties"); |
143 |
ajm |
1.2 |
System.out.println(" the default is ./etc/default.properties"); |
144 |
ajm |
1.1 |
System.out.println(" -f <name> - the name of the filter (if there is one configured"); |
145 |
|
|
System.out.println(" -h - this help screen"); |
146 |
|
|
System.exit(1); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
//---CONSTRUCTORS--- |
150 |
|
|
|
151 |
|
|
//---PUBLIC METHODS--- |
152 |
|
|
|
153 |
|
|
//---PRIVATE METHODS--- |
154 |
|
|
|
155 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
156 |
|
|
|
157 |
|
|
//---ATTRIBUTES--- |
158 |
|
|
|
159 |
|
|
//---STATIC ATTRIBUTES--- |
160 |
|
|
|
161 |
|
|
} |