1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
|
3 |
|
|
//---IMPORTS--- |
4 |
tdb |
1.4 |
import uk.ac.ukc.iscream.core.*; |
5 |
ajm |
1.1 |
import org.omg.CORBA.*; |
6 |
|
|
import org.omg.CosNaming.*; |
7 |
|
|
import org.omg.PortableServer.*; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* The main class for the CORE of the I-Scream system. |
11 |
|
|
* The main method of this class initialises the ORB |
12 |
|
|
* and then starts and registers CORE I-Scream services |
13 |
|
|
* with the name service. At which point it essentially |
14 |
|
|
* finishs its role and the started services continue to |
15 |
|
|
* serve requests from the I-Scream system. |
16 |
|
|
* |
17 |
tdb |
1.3 |
* @author $Author: tdb1 $ |
18 |
tdb |
1.7 |
* @version $Id: Core.java,v 1.6 2000/11/14 01:09:15 tdb1 Exp $ |
19 |
ajm |
1.1 |
*/ |
20 |
|
|
class Core { |
21 |
|
|
|
22 |
|
|
//---FINAL ATTRIBUTES--- |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* The current CVS revision of this class |
26 |
|
|
*/ |
27 |
tdb |
1.7 |
public static final String REVISION = "$Revision: 1.6 $"; |
28 |
ajm |
1.1 |
|
29 |
|
|
//---STATIC METHODS--- |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* The main method which starts the CORE |
33 |
|
|
* Currently the args are passed direct to the ORB, |
34 |
|
|
* so any ORB paramaters could go there. |
35 |
|
|
* |
36 |
|
|
* @param args the command line arguments |
37 |
|
|
*/ |
38 |
|
|
public static void main(String[] args) { |
39 |
tdb |
1.6 |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
40 |
|
|
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
41 |
|
|
|
42 |
tdb |
1.5 |
System.out.println("--- I-Scream ---"); |
43 |
|
|
|
44 |
|
|
// can't have a real toString() :) |
45 |
|
|
String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
46 |
|
|
|
47 |
|
|
System.out.println(toString + ": coming up"); |
48 |
|
|
|
49 |
ajm |
1.1 |
try { |
50 |
|
|
// start the ORB |
51 |
|
|
ORB orb = ORB.init(args, null); |
52 |
|
|
|
53 |
|
|
// get the Root POA |
54 |
|
|
org.omg.CORBA.Object objRef = orb.resolve_initial_references("RootPOA"); |
55 |
|
|
POA poa = POAHelper.narrow(objRef); |
56 |
|
|
|
57 |
|
|
// get a hook to the name service |
58 |
|
|
objRef = orb.resolve_initial_references("NameService"); |
59 |
|
|
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); |
60 |
|
|
|
61 |
tdb |
1.3 |
// start and bind each server in turn |
62 |
|
|
|
63 |
|
|
// create the logger (either Screen or File) |
64 |
tdb |
1.7 |
ScreenLoggerServant loggerRef = new ScreenLoggerServant(3); |
65 |
tdb |
1.3 |
//FileLoggerServant loggerRef = new FileLoggerServant("core.log"); |
66 |
|
|
// and advertise it to the naming context |
67 |
|
|
objRef = poa.servant_to_reference(loggerRef); |
68 |
|
|
ncRef.bind(ncRef.to_name("iscream.Logger"), objRef); |
69 |
ajm |
1.1 |
|
70 |
tdb |
1.3 |
// get a ref to the logger servant as a Logger reference |
71 |
|
|
Logger logRef = LoggerHelper.narrow(objRef); |
72 |
ajm |
1.1 |
|
73 |
tdb |
1.3 |
// create the Configurator |
74 |
|
|
ConfiguratorServant configuratorRef = new ConfiguratorServant(poa, logRef); |
75 |
|
|
// and advertise it to the naming context |
76 |
ajm |
1.1 |
objRef = poa.servant_to_reference(configuratorRef); |
77 |
|
|
ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef); |
78 |
|
|
|
79 |
|
|
// start the POA off |
80 |
tdb |
1.2 |
poa.the_POAManager().activate(); |
81 |
tdb |
1.5 |
|
82 |
tdb |
1.3 |
logRef.write(toString, "started"); |
83 |
ajm |
1.1 |
|
84 |
|
|
// now we are running, we just need to serve |
85 |
|
|
// so we ask the orb to block for us until it has finished |
86 |
|
|
orb.run(); |
87 |
|
|
|
88 |
|
|
// if there was a problem then we'll get to here |
89 |
|
|
} catch (Exception e) { |
90 |
|
|
|
91 |
|
|
// there is already another CORE of the same name registered |
92 |
|
|
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
93 |
|
|
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
94 |
|
|
|
95 |
|
|
// otherwise we don't know what happened |
96 |
|
|
// so print the error and do a stack trace |
97 |
|
|
} else { |
98 |
|
|
System.err.println("CORE ERROR: " + e); |
99 |
|
|
e.printStackTrace(System.out); |
100 |
|
|
} |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
//---CONSTRUCTORS--- |
105 |
|
|
|
106 |
|
|
//---PUBLIC METHODS--- |
107 |
|
|
|
108 |
|
|
//---PRIVATE METHODS--- |
109 |
|
|
|
110 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
111 |
|
|
|
112 |
|
|
//---ATTRIBUTES--- |
113 |
|
|
|
114 |
|
|
//---STATIC ATTRIBUTES--- |
115 |
|
|
|
116 |
tdb |
1.2 |
} |