1 |
|
//---PACKAGE DECLARATION--- |
2 |
|
|
3 |
|
//---IMPORTS--- |
4 |
< |
import core.*; |
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. |
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 |
|
/** |
49 |
|
* @param args the command line arguments |
50 |
|
*/ |
51 |
|
public static void main(String[] args) { |
52 |
< |
System.out.println("I-Scream CORE:" + REVISION + " - coming up."); |
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 |
|
|
90 |
|
objRef = orb.resolve_initial_references("NameService"); |
91 |
|
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
92 |
|
|
93 |
< |
// get a ref to our servers |
94 |
< |
// first the Configurator |
95 |
< |
ConfiguratorServant configuratorRef = new ConfiguratorServant(poa); |
93 |
> |
// check we got it |
94 |
> |
if (ncRef == null) { |
95 |
> |
throw new Exception("Unable to locate CORBA Naming Service for configured ORB!"); |
96 |
> |
} |
97 |
|
|
98 |
< |
// then the logger |
57 |
< |
ScreenLoggerServant loggerRef = new ScreenLoggerServant(); |
58 |
< |
// FileLoggerServant loggerRef = new FileLoggerServant(); |
98 |
> |
// start and bind each server in turn |
99 |
|
|
100 |
< |
// advertise them to the naming context |
101 |
< |
// Configurator |
102 |
< |
objRef = poa.servant_to_reference(configuratorRef); |
103 |
< |
ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef); |
100 |
> |
// work out which logger to use |
101 |
> |
String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass", defaultLogger); |
102 |
> |
|
103 |
> |
// construct the relevant LoggerImpl |
104 |
> |
LoggerImpl loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(whichLogger).newInstance(); |
105 |
|
|
106 |
< |
// Logger |
106 |
> |
// setup and bind the LoggerServant |
107 |
> |
LoggerServant loggerRef = new LoggerServant(loggerImplRef); |
108 |
|
objRef = poa.servant_to_reference(loggerRef); |
109 |
|
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
110 |
|
|
111 |
+ |
// get a reference to the servant as a Logger |
112 |
+ |
Logger logRef = LoggerHelper.narrow(objRef); |
113 |
+ |
|
114 |
+ |
// create the Configurator |
115 |
+ |
ConfigurationManagerServant configManRef = new ConfigurationManagerServant(poa, logRef); |
116 |
+ |
|
117 |
+ |
// and advertise it to the naming context |
118 |
+ |
objRef = poa.servant_to_reference(configManRef); |
119 |
+ |
ncRef.bind(ncRef.to_name("iscream.ConfigurationManager"), objRef); |
120 |
+ |
|
121 |
|
// start the POA off |
122 |
|
poa.the_POAManager().activate(); |
123 |
+ |
|
124 |
+ |
logRef.write(toString, Logger.SYSINIT, "started"); |
125 |
|
|
72 |
– |
System.out.println("I-Scream CORE:" + REVISION + " - started."); |
73 |
– |
|
126 |
|
// now we are running, we just need to serve |
127 |
|
// so we ask the orb to block for us until it has finished |
128 |
|
orb.run(); |
132 |
|
|
133 |
|
// there is already another CORE of the same name registered |
134 |
|
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
135 |
< |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
135 |
> |
System.err.println("CORE ERROR: Another I-Scream CORE is already registered under the same name."); |
136 |
|
|
137 |
|
// otherwise we don't know what happened |
138 |
< |
// so print the error and do a stack trace |
138 |
> |
// so print the error and do a stack trace if debug is enabled |
139 |
|
} else { |
140 |
< |
System.err.println("CORE ERROR: " + e); |
141 |
< |
e.printStackTrace(System.out); |
140 |
> |
System.err.println("CORE ERROR: " + e.getMessage()); |
141 |
> |
if (Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")) == Logger.DEBUG) { |
142 |
> |
System.err.println("*** DEBUG ENABLED - printing stack trace ***"); |
143 |
> |
e.printStackTrace(System.out); |
144 |
> |
} |
145 |
|
} |
146 |
|
} |
147 |
|
} |
148 |
+ |
|
149 |
+ |
/** |
150 |
+ |
* A simple method to print the usage of this class. |
151 |
+ |
* It never returns, but instead exits to the system |
152 |
+ |
* with a value 1, to indicate the system did not start |
153 |
+ |
* properly. |
154 |
+ |
*/ |
155 |
+ |
public static void usage() { |
156 |
+ |
System.out.println("USAGE: java Core.java <option>"); |
157 |
+ |
System.out.println("WHERE <option>:"); |
158 |
+ |
System.out.println(" -l <filename> - the location of initial system properties"); |
159 |
+ |
System.out.println(" -h - this help screen"); |
160 |
+ |
System.exit(1); |
161 |
+ |
} |
162 |
|
|
163 |
|
//---CONSTRUCTORS--- |
164 |
|
|
169 |
|
//---ACCESSOR/MUTATOR METHODS--- |
170 |
|
|
171 |
|
//---ATTRIBUTES--- |
172 |
< |
|
172 |
> |
|
173 |
|
//---STATIC ATTRIBUTES--- |
174 |
+ |
|
175 |
+ |
/** |
176 |
+ |
* Default logger, to be used when one is not provided |
177 |
+ |
* in the configuration. |
178 |
+ |
*/ |
179 |
+ |
private static final String defaultLogger = "ScreenLogger"; |
180 |
+ |
|
181 |
+ |
/** |
182 |
+ |
* Default configPath, to be used when one is not provided |
183 |
+ |
* in the configuration. |
184 |
+ |
*/ |
185 |
+ |
private static final String defaultConfigPath = "."; |
186 |
|
|
187 |
|
} |