1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.core; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.core.*; |
6 |
< |
import org.omg.CORBA.*; |
5 |
> |
import uk.ac.ukc.iscream.util.ReferenceManager; |
6 |
> |
|
7 |
> |
import org.omg.CORBA.ORB; |
8 |
|
import org.omg.CosNaming.*; |
9 |
|
import org.omg.PortableServer.*; |
10 |
< |
import java.util.*; |
9 |
< |
import java.io.*; |
10 |
> |
import uk.ac.ukc.iscream.core.*; |
11 |
|
|
12 |
|
/** |
13 |
|
* The main class for the CORE of the I-Scream system. |
20 |
|
* @author $Author$ |
21 |
|
* @version $Id$ |
22 |
|
*/ |
23 |
< |
class Core { |
23 |
> |
public class Core implements uk.ac.ukc.iscream.util.Component { |
24 |
|
|
25 |
|
//---FINAL ATTRIBUTES--- |
26 |
|
|
42 |
|
|
43 |
|
//---STATIC METHODS--- |
44 |
|
|
45 |
+ |
//---CONSTRUCTORS--- |
46 |
+ |
|
47 |
+ |
//---PUBLIC METHODS--- |
48 |
+ |
|
49 |
|
/** |
50 |
|
* The main method which starts the CORE |
51 |
|
* Currently the args are passed direct to the ORB, |
53 |
|
* |
54 |
|
* @param args the command line arguments |
55 |
|
*/ |
56 |
< |
public static void main(String[] args) { |
57 |
< |
System.out.println("--- I-Scream ---"); |
58 |
< |
|
59 |
< |
// get the command line args |
60 |
< |
String defaultProperties = DEFAULTPROPERTIES; |
61 |
< |
if (args.length > 0) { |
62 |
< |
if (args[0].equals("-l")) { |
63 |
< |
defaultProperties = args[1]; |
64 |
< |
} 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); |
56 |
> |
public boolean start() { |
57 |
> |
// start and bind each server in turn |
58 |
> |
|
59 |
> |
// work out which logger to use |
60 |
> |
String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass"); |
61 |
> |
String loggerPackage = System.getProperty("uk.ac.ukc.iscream.LoggerPackage"); |
62 |
> |
|
63 |
> |
// construct the relevant LoggerImpl |
64 |
> |
LoggerImpl loggerImplRef = null; |
65 |
|
try { |
66 |
< |
Properties initProperties = new Properties(System.getProperties()); |
70 |
< |
initProperties.load(new FileInputStream(new File(defaultProperties))); |
71 |
< |
System.setProperties(initProperties); |
72 |
< |
|
73 |
< |
|
66 |
> |
loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance(); |
67 |
|
} catch (Exception e) { |
68 |
< |
System.err.println(toString + ": ERROR " + e.getMessage()); |
69 |
< |
usage(); |
68 |
> |
System.err.println(toString + ": ERROR Unable to start Logger - " + e.getMessage()); |
69 |
> |
// so return false to indicate failure |
70 |
> |
return false; |
71 |
|
} |
72 |
+ |
|
73 |
+ |
// setup and bind the LoggerServant |
74 |
+ |
LoggerServant loggerRef = new LoggerServant(loggerImplRef); |
75 |
+ |
_refman.bindToOrb(loggerRef, "iscream.Logger"); |
76 |
|
|
77 |
< |
// continue to bring the system up |
78 |
< |
System.out.println(toString + ": coming up"); |
79 |
< |
try { |
80 |
< |
// start the ORB |
81 |
< |
ORB orb = ORB.init(args, null); |
82 |
< |
|
83 |
< |
// get the Root POA |
84 |
< |
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 which logger to use |
96 |
< |
String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass", defaultLogger); |
97 |
< |
|
98 |
< |
// construct the relevant LoggerImpl |
99 |
< |
LoggerImpl loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(whichLogger).newInstance(); |
100 |
< |
|
101 |
< |
// setup and bind the LoggerServant |
102 |
< |
LoggerServant loggerRef = new LoggerServant(loggerImplRef); |
103 |
< |
objRef = poa.servant_to_reference(loggerRef); |
104 |
< |
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
105 |
< |
|
106 |
< |
// get a reference to the servant as a Logger |
107 |
< |
Logger logRef = LoggerHelper.narrow(objRef); |
77 |
> |
// get a reference to the servant as a Logger |
78 |
> |
_logger = _refman.getLogger(); |
79 |
> |
|
80 |
> |
// create the Configurator |
81 |
> |
ConfigurationManagerServant configManRef = new ConfigurationManagerServant(_refman.getRootPOA(), _refman.getLogger()); |
82 |
> |
|
83 |
> |
// and advertise it to the naming context |
84 |
> |
_refman.bindToOrb(configManRef, "iscream.ConfigurationManager"); |
85 |
|
|
86 |
< |
|
87 |
< |
|
88 |
< |
// create the Configurator |
89 |
< |
String configLocation = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation", defaultConfigPath); |
113 |
< |
ConfigurationManagerServant configManRef = new ConfigurationManagerServant(poa, logRef); |
114 |
< |
|
115 |
< |
// and advertise it to the naming context |
116 |
< |
objRef = poa.servant_to_reference(configManRef); |
117 |
< |
ncRef.bind(ncRef.to_name("iscream.ConfigurationManager"), objRef); |
118 |
< |
|
119 |
< |
// start the POA off |
120 |
< |
poa.the_POAManager().activate(); |
121 |
< |
|
122 |
< |
logRef.write(toString, Logger.SYSINIT, "started"); |
123 |
< |
|
124 |
< |
// now we are running, we just need to serve |
125 |
< |
// so we ask the orb to block for us until it has finished |
126 |
< |
orb.run(); |
127 |
< |
|
128 |
< |
// if there was a problem then we'll get to here |
129 |
< |
} catch (Exception e) { |
130 |
< |
|
131 |
< |
// there is already another CORE of the same name registered |
132 |
< |
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
133 |
< |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
134 |
< |
|
135 |
< |
// otherwise we don't know what happened |
136 |
< |
// so print the error and do a stack trace |
137 |
< |
} else { |
138 |
< |
System.err.println("CORE ERROR: " + e); |
139 |
< |
e.printStackTrace(System.out); |
140 |
< |
} |
141 |
< |
} |
86 |
> |
_logger.write(toString, Logger.SYSINIT, "started"); |
87 |
> |
|
88 |
> |
// we were ok starting... |
89 |
> |
return true; |
90 |
|
} |
143 |
– |
|
144 |
– |
/** |
145 |
– |
* A simple method to print the usage of this class. |
146 |
– |
* It never returns, but instead exits to the system |
147 |
– |
* with a value 1, to indicate the system did not start |
148 |
– |
* properly. |
149 |
– |
*/ |
150 |
– |
public static void usage() { |
151 |
– |
System.out.println("USAGE: java Core.java <option>"); |
152 |
– |
System.out.println("WHERE <option>:"); |
153 |
– |
System.out.println(" -l <filename> - the location of initial system properties"); |
154 |
– |
System.out.println(" -h - this help screen"); |
155 |
– |
System.exit(1); |
156 |
– |
} |
91 |
|
|
158 |
– |
//---CONSTRUCTORS--- |
159 |
– |
|
160 |
– |
//---PUBLIC METHODS--- |
161 |
– |
|
92 |
|
//---PRIVATE METHODS--- |
93 |
|
|
94 |
|
//---ACCESSOR/MUTATOR METHODS--- |
95 |
|
|
96 |
|
//---ATTRIBUTES--- |
97 |
|
|
98 |
< |
//---STATIC ATTRIBUTES--- |
99 |
< |
|
170 |
< |
/** |
171 |
< |
* Default logger, to be used when one is not provided |
172 |
< |
* in the configuration. |
173 |
< |
*/ |
174 |
< |
private static final String defaultLogger = "ScreenLogger"; |
98 |
> |
Logger _logger; |
99 |
> |
ReferenceManager _refman = ReferenceManager.getInstance(); |
100 |
|
|
101 |
< |
/** |
177 |
< |
* Default configPath, to be used when one is not provided |
178 |
< |
* in the configuration. |
179 |
< |
*/ |
180 |
< |
private static final String defaultConfigPath = "."; |
101 |
> |
//---STATIC ATTRIBUTES--- |
102 |
|
|
103 |
|
} |