ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/Core.java
Revision: 1.16
Committed: Wed Nov 29 21:27:08 2000 UTC (23 years, 6 months ago) by ajm
Branch: MAIN
Branch point for: SERVER_PACKAGEBUILD
Changes since 1.15: +7 -18 lines
Log Message:
Update for package move.

File Contents

# User Rev Content
1 tdb 1.13 //---PACKAGE DECLARATION---
2 ajm 1.16 package uk.ac.ukc.iscream.core;
3 tdb 1.13
4     //---IMPORTS---
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 ajm 1.16 * @author $Author: tdb1 $
20     * @version $Id: Core.java,v 1.15 2000/11/21 15:08:42 tdb1 Exp $
21 tdb 1.13 */
22     class Core {
23    
24     //---FINAL ATTRIBUTES---
25    
26     /**
27     * The current CVS revision of this class
28     */
29 ajm 1.16 public static final String REVISION = "$Revision: 1.15 $";
30 tdb 1.13
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 ajm 1.14 // check we got it
94     if (ncRef == null) {
95     throw new Exception("Unable to locate CORBA Naming Service for configured ORB!");
96     }
97    
98 tdb 1.13 // start and bind each server in turn
99    
100     // work out which logger to use
101 ajm 1.16 String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass");
102     String loggerPackage = System.getProperty("uk.ac.ukc.iscream.LoggerPackage");
103 tdb 1.13
104     // construct the relevant LoggerImpl
105 ajm 1.16 LoggerImpl loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance();
106 tdb 1.13
107     // setup and bind the LoggerServant
108     LoggerServant loggerRef = new LoggerServant(loggerImplRef);
109     objRef = poa.servant_to_reference(loggerRef);
110     ncRef.bind(ncRef.to_name("iscream.Logger"), objRef);
111    
112     // get a reference to the servant as a Logger
113     Logger logRef = LoggerHelper.narrow(objRef);
114    
115     // create the Configurator
116     ConfigurationManagerServant configManRef = new ConfigurationManagerServant(poa, logRef);
117    
118     // and advertise it to the naming context
119     objRef = poa.servant_to_reference(configManRef);
120     ncRef.bind(ncRef.to_name("iscream.ConfigurationManager"), objRef);
121    
122     // start the POA off
123     poa.the_POAManager().activate();
124    
125     logRef.write(toString, Logger.SYSINIT, "started");
126    
127     // now we are running, we just need to serve
128     // so we ask the orb to block for us until it has finished
129     orb.run();
130    
131     // if there was a problem then we'll get to here
132     } catch (Exception e) {
133    
134     // there is already another CORE of the same name registered
135     if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) {
136 ajm 1.14 System.err.println("CORE ERROR: Another I-Scream CORE is already registered under the same name.");
137 tdb 1.13
138     // otherwise we don't know what happened
139 ajm 1.14 // so print the error and do a stack trace if debug is enabled
140 tdb 1.13 } else {
141 ajm 1.14 System.err.println("CORE ERROR: " + e.getMessage());
142     if (Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")) == Logger.DEBUG) {
143     System.err.println("*** DEBUG ENABLED - printing stack trace ***");
144     e.printStackTrace(System.out);
145     }
146 tdb 1.13 }
147     }
148     }
149    
150     /**
151     * A simple method to print the usage of this class.
152     * It never returns, but instead exits to the system
153     * with a value 1, to indicate the system did not start
154     * properly.
155     */
156     public static void usage() {
157 tdb 1.15 System.out.println("USAGE: java Core <option>");
158 tdb 1.13 System.out.println("WHERE <option>:");
159     System.out.println(" -l <filename> - the location of initial system properties");
160     System.out.println(" -h - this help screen");
161     System.exit(1);
162     }
163    
164     //---CONSTRUCTORS---
165    
166     //---PUBLIC METHODS---
167    
168     //---PRIVATE METHODS---
169    
170     //---ACCESSOR/MUTATOR METHODS---
171    
172     //---ATTRIBUTES---
173    
174     //---STATIC ATTRIBUTES---
175    
176     }