1 |
< |
//---PACKAGE DECLARATION--- |
2 |
< |
|
3 |
< |
//---IMPORTS--- |
4 |
< |
import uk.ac.ukc.iscream.core.*; |
5 |
< |
import org.omg.CORBA.*; |
6 |
< |
import org.omg.CosNaming.*; |
7 |
< |
import org.omg.PortableServer.*; |
8 |
< |
import java.util.*; |
9 |
< |
import java.io.*; |
10 |
< |
|
11 |
< |
/** |
12 |
< |
* The main class for the CORE of the I-Scream system. |
13 |
< |
* The main method of this class initialises the ORB |
14 |
< |
* and then starts and registers CORE I-Scream services |
15 |
< |
* with the name service. At which point it essentially |
16 |
< |
* finishs its role and the started services continue to |
17 |
< |
* serve requests from the I-Scream system. |
18 |
< |
* |
19 |
< |
* @author $Author$ |
20 |
< |
* @version $Id$ |
21 |
< |
*/ |
22 |
< |
class Core { |
23 |
< |
|
24 |
< |
//---FINAL ATTRIBUTES--- |
25 |
< |
|
26 |
< |
/** |
27 |
< |
* The current CVS revision of this class |
28 |
< |
*/ |
29 |
< |
public static final String REVISION = "$Revision$"; |
30 |
< |
|
31 |
< |
/** |
32 |
< |
* The toString() of this class |
33 |
< |
* As it won't be instatiated, this is needed. |
34 |
< |
*/ |
35 |
< |
public static final String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
36 |
< |
|
37 |
< |
/** |
38 |
< |
* The default location of the properties file for the system |
39 |
< |
*/ |
40 |
< |
public static final String DEFAULTPROPERTIES = "default.properties"; |
41 |
< |
|
42 |
< |
//---STATIC METHODS--- |
43 |
< |
|
44 |
< |
/** |
45 |
< |
* The main method which starts the CORE |
46 |
< |
* Currently the args are passed direct to the ORB, |
47 |
< |
* so any ORB paramaters could go there. |
48 |
< |
* |
49 |
< |
* @param args the command line arguments |
50 |
< |
*/ |
51 |
< |
public static void main(String[] args) { |
52 |
< |
System.out.println("--- I-Scream ---"); |
53 |
< |
|
54 |
< |
// get the command line args |
55 |
< |
String defaultProperties = DEFAULTPROPERTIES; |
56 |
< |
if (args.length > 0) { |
57 |
< |
if (args[0].equals("-l")) { |
58 |
< |
defaultProperties = args[1]; |
59 |
< |
} else if (args[0].equals("-h")) { |
60 |
< |
usage(); |
61 |
< |
} else { |
62 |
< |
usage(); |
63 |
< |
} |
64 |
< |
} |
65 |
< |
|
66 |
< |
// load the default properties file into the system properties |
67 |
< |
System.out.println(toString + ": initialising - using " + defaultProperties); |
68 |
< |
try { |
69 |
< |
Properties initProperties = new Properties(System.getProperties()); |
70 |
< |
initProperties.load(new FileInputStream(new File(defaultProperties))); |
71 |
< |
System.setProperties(initProperties); |
72 |
< |
|
73 |
< |
|
74 |
< |
} catch (Exception e) { |
75 |
< |
System.err.println(toString + ": ERROR " + e.getMessage()); |
76 |
< |
usage(); |
77 |
< |
} |
78 |
< |
|
79 |
< |
// continue to bring the system up |
80 |
< |
System.out.println(toString + ": coming up"); |
81 |
< |
try { |
82 |
< |
// start the ORB |
83 |
< |
ORB orb = ORB.init(args, null); |
84 |
< |
|
85 |
< |
// get the Root POA |
86 |
< |
org.omg.CORBA.Object objRef = orb.resolve_initial_references("RootPOA"); |
87 |
< |
POA poa = POAHelper.narrow(objRef); |
88 |
< |
|
89 |
< |
// get a hook to the name service |
90 |
< |
objRef = orb.resolve_initial_references("NameService"); |
91 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
92 |
< |
|
93 |
< |
// start and bind each server in turn |
94 |
< |
|
95 |
< |
// work out the verbosity setting & which logger to use |
96 |
< |
int verbosity = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity", defaultVerbosity)); |
97 |
< |
String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass", defaultLogger); |
98 |
< |
String loggerParams = System.getProperty("uk.ac.ukc.iscream.LoggerClassParams"); |
99 |
< |
|
100 |
< |
Logger logRef = null; |
101 |
< |
// create the logger (either Screen or File), and bind it |
102 |
< |
if(whichLogger.equals("ScreenLogger")){ |
103 |
< |
ScreenLoggerServant loggerRef = new ScreenLoggerServant(verbosity); |
104 |
< |
objRef = poa.servant_to_reference(loggerRef); |
105 |
< |
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
106 |
< |
logRef = LoggerHelper.narrow(objRef); |
107 |
< |
} |
108 |
< |
else if(whichLogger.equals("FileLogger")){ |
109 |
< |
FileLoggerServant loggerRef = new FileLoggerServant(loggerParams, verbosity); |
110 |
< |
objRef = poa.servant_to_reference(loggerRef); |
111 |
< |
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
112 |
< |
logRef = LoggerHelper.narrow(objRef); |
113 |
< |
} |
114 |
< |
else { |
115 |
< |
//need to deal with this |
116 |
< |
} |
117 |
< |
|
118 |
< |
// and advertise it to the naming context |
119 |
< |
//objRef = poa.servant_to_reference(loggerRef); |
120 |
< |
//ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
121 |
< |
|
122 |
< |
// get a ref to the logger servant as a Logger reference |
123 |
< |
//Logger logRef = LoggerHelper.narrow(objRef); |
124 |
< |
|
125 |
< |
// create the Configurator |
126 |
< |
String configLocation = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation", defaultConfigPath); |
127 |
< |
ConfiguratorServant configuratorRef = new ConfiguratorServant(configLocation, poa, logRef); |
128 |
< |
|
129 |
< |
// and advertise it to the naming context |
130 |
< |
objRef = poa.servant_to_reference(configuratorRef); |
131 |
< |
ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef); |
132 |
< |
|
133 |
< |
// start the POA off |
134 |
< |
poa.the_POAManager().activate(); |
135 |
< |
|
136 |
< |
logRef.write(toString, Logger.SYSINIT, "started"); |
137 |
< |
|
138 |
< |
// now we are running, we just need to serve |
139 |
< |
// so we ask the orb to block for us until it has finished |
140 |
< |
orb.run(); |
141 |
< |
|
142 |
< |
// if there was a problem then we'll get to here |
143 |
< |
} catch (Exception e) { |
144 |
< |
|
145 |
< |
// there is already another CORE of the same name registered |
146 |
< |
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
147 |
< |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
148 |
< |
|
149 |
< |
// otherwise we don't know what happened |
150 |
< |
// so print the error and do a stack trace |
151 |
< |
} else { |
152 |
< |
System.err.println("CORE ERROR: " + e); |
153 |
< |
e.printStackTrace(System.out); |
154 |
< |
} |
155 |
< |
} |
156 |
< |
} |
157 |
< |
|
158 |
< |
/** |
159 |
< |
* A simple method to print the usage of this class. |
160 |
< |
* It never returns, but instead exits to the system |
161 |
< |
* with a value 1, to indicate the system did not start |
162 |
< |
* properly. |
163 |
< |
*/ |
164 |
< |
public static void usage() { |
165 |
< |
System.out.println("USAGE: java Core.java <option>"); |
166 |
< |
System.out.println("WHERE <option>:"); |
167 |
< |
System.out.println(" -l <filename> - the location of initial system properties"); |
168 |
< |
System.out.println(" -h - this help screen"); |
169 |
< |
System.exit(1); |
170 |
< |
} |
171 |
< |
|
172 |
< |
//---CONSTRUCTORS--- |
173 |
< |
|
174 |
< |
//---PUBLIC METHODS--- |
175 |
< |
|
176 |
< |
//---PRIVATE METHODS--- |
177 |
< |
|
178 |
< |
//---ACCESSOR/MUTATOR METHODS--- |
179 |
< |
|
180 |
< |
//---ATTRIBUTES--- |
181 |
< |
|
182 |
< |
//---STATIC ATTRIBUTES--- |
183 |
< |
|
184 |
< |
/** |
185 |
< |
* Default verbosity setting, to be used when one is |
186 |
< |
* not provided in the configuration. |
187 |
< |
*/ |
188 |
< |
private static final String defaultVerbosity = "3"; |
189 |
< |
|
190 |
< |
/** |
191 |
< |
* Default logger, to be used when one is not provided |
192 |
< |
* in the configuration. |
193 |
< |
*/ |
194 |
< |
private static final String defaultLogger = "ScreenLogger"; |
195 |
< |
|
196 |
< |
/** |
197 |
< |
* Default configPath, to be used when one is not provided |
198 |
< |
* in the configuration. |
199 |
< |
*/ |
200 |
< |
private static final String defaultConfigPath = "."; |
201 |
< |
|
202 |
< |
} |
1 |
> |
//---PACKAGE DECLARATION--- |
2 |
> |
|
3 |
> |
//---IMPORTS--- |
4 |
> |
import uk.ac.ukc.iscream.core.*; |
5 |
> |
import org.omg.CORBA.*; |
6 |
> |
import org.omg.CosNaming.*; |
7 |
> |
import org.omg.PortableServer.*; |
8 |
> |
import java.util.*; |
9 |
> |
import java.io.*; |
10 |
> |
|
11 |
> |
/** |
12 |
> |
* The main class for the CORE of the I-Scream system. |
13 |
> |
* The main method of this class initialises the ORB |
14 |
> |
* and then starts and registers CORE I-Scream services |
15 |
> |
* with the name service. At which point it essentially |
16 |
> |
* finishs its role and the started services continue to |
17 |
> |
* serve requests from the I-Scream system. |
18 |
> |
* |
19 |
> |
* @author $Author$ |
20 |
> |
* @version $Id$ |
21 |
> |
*/ |
22 |
> |
class Core { |
23 |
> |
|
24 |
> |
//---FINAL ATTRIBUTES--- |
25 |
> |
|
26 |
> |
/** |
27 |
> |
* The current CVS revision of this class |
28 |
> |
*/ |
29 |
> |
public static final String REVISION = "$Revision$"; |
30 |
> |
|
31 |
> |
/** |
32 |
> |
* The toString() of this class |
33 |
> |
* As it won't be instatiated, this is needed. |
34 |
> |
*/ |
35 |
> |
public static final String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
36 |
> |
|
37 |
> |
/** |
38 |
> |
* The default location of the properties file for the system |
39 |
> |
*/ |
40 |
> |
public static final String DEFAULTPROPERTIES = "default.properties"; |
41 |
> |
|
42 |
> |
//---STATIC METHODS--- |
43 |
> |
|
44 |
> |
/** |
45 |
> |
* The main method which starts the CORE |
46 |
> |
* Currently the args are passed direct to the ORB, |
47 |
> |
* so any ORB paramaters could go there. |
48 |
> |
* |
49 |
> |
* @param args the command line arguments |
50 |
> |
*/ |
51 |
> |
public static void main(String[] args) { |
52 |
> |
System.out.println("--- I-Scream ---"); |
53 |
> |
|
54 |
> |
// get the command line args |
55 |
> |
String defaultProperties = DEFAULTPROPERTIES; |
56 |
> |
if (args.length > 0) { |
57 |
> |
if (args[0].equals("-l")) { |
58 |
> |
defaultProperties = args[1]; |
59 |
> |
} else if (args[0].equals("-h")) { |
60 |
> |
usage(); |
61 |
> |
} else { |
62 |
> |
usage(); |
63 |
> |
} |
64 |
> |
} |
65 |
> |
|
66 |
> |
// load the default properties file into the system properties |
67 |
> |
System.out.println(toString + ": initialising - using " + defaultProperties); |
68 |
> |
try { |
69 |
> |
Properties initProperties = new Properties(System.getProperties()); |
70 |
> |
initProperties.load(new FileInputStream(new File(defaultProperties))); |
71 |
> |
System.setProperties(initProperties); |
72 |
> |
|
73 |
> |
|
74 |
> |
} catch (Exception e) { |
75 |
> |
System.err.println(toString + ": ERROR " + e.getMessage()); |
76 |
> |
usage(); |
77 |
> |
} |
78 |
> |
|
79 |
> |
// continue to bring the system up |
80 |
> |
System.out.println(toString + ": coming up"); |
81 |
> |
try { |
82 |
> |
// start the ORB |
83 |
> |
ORB orb = ORB.init(args, null); |
84 |
> |
|
85 |
> |
// get the Root POA |
86 |
> |
org.omg.CORBA.Object objRef = orb.resolve_initial_references("RootPOA"); |
87 |
> |
POA poa = POAHelper.narrow(objRef); |
88 |
> |
|
89 |
> |
// get a hook to the name service |
90 |
> |
objRef = orb.resolve_initial_references("NameService"); |
91 |
> |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
92 |
> |
|
93 |
> |
// start and bind each server in turn |
94 |
> |
|
95 |
> |
// work out the verbosity setting & which logger to use |
96 |
> |
int verbosity = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity", defaultVerbosity)); |
97 |
> |
String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass", defaultLogger); |
98 |
> |
String loggerParams = System.getProperty("uk.ac.ukc.iscream.LoggerClassParams"); |
99 |
> |
|
100 |
> |
Logger logRef = null; |
101 |
> |
// create the logger (either Screen or File), and bind it |
102 |
> |
if(whichLogger.equals("ScreenLogger")){ |
103 |
> |
ScreenLoggerServant loggerRef = new ScreenLoggerServant(verbosity); |
104 |
> |
objRef = poa.servant_to_reference(loggerRef); |
105 |
> |
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
106 |
> |
logRef = LoggerHelper.narrow(objRef); |
107 |
> |
} |
108 |
> |
else if(whichLogger.equals("FileLogger")){ |
109 |
> |
FileLoggerServant loggerRef = new FileLoggerServant(loggerParams, verbosity); |
110 |
> |
objRef = poa.servant_to_reference(loggerRef); |
111 |
> |
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
112 |
> |
logRef = LoggerHelper.narrow(objRef); |
113 |
> |
} |
114 |
> |
else { |
115 |
> |
//need to deal with this |
116 |
> |
} |
117 |
> |
|
118 |
> |
// and advertise it to the naming context |
119 |
> |
//objRef = poa.servant_to_reference(loggerRef); |
120 |
> |
//ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
121 |
> |
|
122 |
> |
// get a ref to the logger servant as a Logger reference |
123 |
> |
//Logger logRef = LoggerHelper.narrow(objRef); |
124 |
> |
|
125 |
> |
// create the Configurator |
126 |
> |
String configLocation = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation", defaultConfigPath); |
127 |
> |
ConfigurationManagerServant configManRef = new ConfigurationManagerServant(poa, logRef); |
128 |
> |
|
129 |
> |
// and advertise it to the naming context |
130 |
> |
objRef = poa.servant_to_reference(configManRef); |
131 |
> |
ncRef.bind(ncRef.to_name("iscream.ConfigurationManager"), objRef); |
132 |
> |
|
133 |
> |
// start the POA off |
134 |
> |
poa.the_POAManager().activate(); |
135 |
> |
|
136 |
> |
logRef.write(toString, Logger.SYSINIT, "started"); |
137 |
> |
|
138 |
> |
// now we are running, we just need to serve |
139 |
> |
// so we ask the orb to block for us until it has finished |
140 |
> |
orb.run(); |
141 |
> |
|
142 |
> |
// if there was a problem then we'll get to here |
143 |
> |
} catch (Exception e) { |
144 |
> |
|
145 |
> |
// there is already another CORE of the same name registered |
146 |
> |
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
147 |
> |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
148 |
> |
|
149 |
> |
// otherwise we don't know what happened |
150 |
> |
// so print the error and do a stack trace |
151 |
> |
} else { |
152 |
> |
System.err.println("CORE ERROR: " + e); |
153 |
> |
e.printStackTrace(System.out); |
154 |
> |
} |
155 |
> |
} |
156 |
> |
} |
157 |
> |
|
158 |
> |
/** |
159 |
> |
* A simple method to print the usage of this class. |
160 |
> |
* It never returns, but instead exits to the system |
161 |
> |
* with a value 1, to indicate the system did not start |
162 |
> |
* properly. |
163 |
> |
*/ |
164 |
> |
public static void usage() { |
165 |
> |
System.out.println("USAGE: java Core.java <option>"); |
166 |
> |
System.out.println("WHERE <option>:"); |
167 |
> |
System.out.println(" -l <filename> - the location of initial system properties"); |
168 |
> |
System.out.println(" -h - this help screen"); |
169 |
> |
System.exit(1); |
170 |
> |
} |
171 |
> |
|
172 |
> |
//---CONSTRUCTORS--- |
173 |
> |
|
174 |
> |
//---PUBLIC METHODS--- |
175 |
> |
|
176 |
> |
//---PRIVATE METHODS--- |
177 |
> |
|
178 |
> |
//---ACCESSOR/MUTATOR METHODS--- |
179 |
> |
|
180 |
> |
//---ATTRIBUTES--- |
181 |
> |
|
182 |
> |
//---STATIC ATTRIBUTES--- |
183 |
> |
|
184 |
> |
/** |
185 |
> |
* Default verbosity setting, to be used when one is |
186 |
> |
* not provided in the configuration. |
187 |
> |
*/ |
188 |
> |
private static final String defaultVerbosity = "3"; |
189 |
> |
|
190 |
> |
/** |
191 |
> |
* Default logger, to be used when one is not provided |
192 |
> |
* in the configuration. |
193 |
> |
*/ |
194 |
> |
private static final String defaultLogger = "ScreenLogger"; |
195 |
> |
|
196 |
> |
/** |
197 |
> |
* Default configPath, to be used when one is not provided |
198 |
> |
* in the configuration. |
199 |
> |
*/ |
200 |
> |
private static final String defaultConfigPath = "."; |
201 |
> |
|
202 |
> |
} |