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 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 |
|
|
29 |
|
*/ |
30 |
|
public static final String REVISION = "$Revision$"; |
31 |
|
|
32 |
+ |
/** |
33 |
+ |
* The toString() of this class |
34 |
+ |
* As it won't be instatiated, this is needed. |
35 |
+ |
*/ |
36 |
+ |
public static final String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
37 |
+ |
|
38 |
+ |
/** |
39 |
+ |
* The default location of the properties file for the system |
40 |
+ |
*/ |
41 |
+ |
public static final String DEFAULTPROPERTIES = "default.properties"; |
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 ---"); |
56 |
> |
public boolean start() { |
57 |
> |
// start and bind each server in turn |
58 |
|
|
59 |
< |
// can't have a real toString() :) |
60 |
< |
String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
61 |
< |
|
62 |
< |
System.out.println(toString + ": coming up"); |
63 |
< |
|
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 |
< |
// start the ORB |
48 |
< |
ORB orb = ORB.init(args, null); |
49 |
< |
|
50 |
< |
// get the Root POA |
51 |
< |
org.omg.CORBA.Object objRef = orb.resolve_initial_references("RootPOA"); |
52 |
< |
POA poa = POAHelper.narrow(objRef); |
53 |
< |
|
54 |
< |
// get a hook to the name service |
55 |
< |
objRef = orb.resolve_initial_references("NameService"); |
56 |
< |
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
57 |
< |
|
58 |
< |
// start and bind each server in turn |
59 |
< |
|
60 |
< |
// create the logger (either Screen or File) |
61 |
< |
ScreenLoggerServant loggerRef = new ScreenLoggerServant(); |
62 |
< |
//FileLoggerServant loggerRef = new FileLoggerServant("core.log"); |
63 |
< |
// and advertise it to the naming context |
64 |
< |
objRef = poa.servant_to_reference(loggerRef); |
65 |
< |
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
66 |
< |
|
67 |
< |
// get a ref to the logger servant as a Logger reference |
68 |
< |
Logger logRef = LoggerHelper.narrow(objRef); |
69 |
< |
|
70 |
< |
// create the Configurator |
71 |
< |
ConfiguratorServant configuratorRef = new ConfiguratorServant(poa, logRef); |
72 |
< |
// and advertise it to the naming context |
73 |
< |
objRef = poa.servant_to_reference(configuratorRef); |
74 |
< |
ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef); |
75 |
< |
|
76 |
< |
// start the POA off |
77 |
< |
poa.the_POAManager().activate(); |
78 |
< |
|
79 |
< |
logRef.write(toString, "started"); |
80 |
< |
|
81 |
< |
// now we are running, we just need to serve |
82 |
< |
// so we ask the orb to block for us until it has finished |
83 |
< |
orb.run(); |
84 |
< |
|
85 |
< |
// if there was a problem then we'll get to here |
66 |
> |
loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance(); |
67 |
|
} catch (Exception e) { |
68 |
< |
|
69 |
< |
// there is already another CORE of the same name registered |
70 |
< |
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
90 |
< |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
91 |
< |
|
92 |
< |
// otherwise we don't know what happened |
93 |
< |
// so print the error and do a stack trace |
94 |
< |
} else { |
95 |
< |
System.err.println("CORE ERROR: " + e); |
96 |
< |
e.printStackTrace(System.out); |
97 |
< |
} |
68 |
> |
System.err.println(toString + ": ERROR Unable to start Logger - " + e.getMessage()); |
69 |
> |
// so return false to indicate failure |
70 |
> |
return false; |
71 |
|
} |
72 |
< |
} |
72 |
> |
|
73 |
> |
// setup and bind the LoggerServant |
74 |
> |
LoggerServant loggerRef = new LoggerServant(loggerImplRef); |
75 |
> |
_refman.bindToOrb(loggerRef, "iscream.Logger"); |
76 |
|
|
77 |
< |
//---CONSTRUCTORS--- |
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 |
< |
//---PUBLIC METHODS--- |
86 |
> |
_logger.write(toString, Logger.SYSINIT, "started"); |
87 |
> |
|
88 |
> |
// we were ok starting... |
89 |
> |
return true; |
90 |
> |
} |
91 |
|
|
92 |
|
//---PRIVATE METHODS--- |
93 |
|
|
94 |
|
//---ACCESSOR/MUTATOR METHODS--- |
95 |
|
|
96 |
|
//---ATTRIBUTES--- |
97 |
< |
|
97 |
> |
|
98 |
> |
Logger _logger; |
99 |
> |
ReferenceManager _refman = ReferenceManager.getInstance(); |
100 |
> |
|
101 |
|
//---STATIC ATTRIBUTES--- |
102 |
|
|
103 |
|
} |