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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/Core.java (file contents):
Revision 1.15 by tdb, Tue Nov 21 15:08:42 2000 UTC vs.
Revision 1.20 by ajm, Tue Dec 12 19:56:08 2000 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.core;
3  
4   //---IMPORTS---
5 < 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.*;
5 > import uk.ac.ukc.iscream.util.*;
6  
7   /**
8   * The main class for the CORE of the I-Scream system.
9 < * The main method of this class initialises the ORB
10 < * and then starts and registers CORE I-Scream services
11 < * with the name service.  At which point it essentially
9 > * This class is the component for CORE I-Scream services
10 > * namely the Logger and the ConfigurationManager.
11 > * It registers and starts them, at which point it essentially
12   * finishs its role and the started services continue to
13   * serve requests from the I-Scream system.
14   *
15   * @author  $Author$
16   * @version $Id$
17   */
18 < class Core {
18 > public class Core implements uk.ac.ukc.iscream.util.Component {
19  
20   //---FINAL ATTRIBUTES---
21  
# Line 29 | Line 25 | class Core {
25      public static final String REVISION = "$Revision$";
26      
27      /**
28 <     * The toString() of this class
29 <     * As it won't be instatiated, this is needed.
28 >     * The friendly name for this component, used by
29 >     * all related classes.
30       */
31 <    public static final String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")";
31 >    public static final String NAME = "Core";
32      
37    /**
38     * The default location of the properties file for the system
39     */
40    public static final String DEFAULTPROPERTIES = "default.properties";
41    
33   //---STATIC METHODS---
34  
35 + //---CONSTRUCTORS---
36 +
37 + //---PUBLIC METHODS---
38 +
39      /**
40 <     * The main method which starts the CORE
40 >     * This method starts the CORE
41       * Currently the args are passed direct to the ORB,
42       * so any ORB paramaters could go there.
43       *
49     * @param args the command line arguments
44       */
45 <    public static void main(String[] args) {
46 <        System.out.println("--- I-Scream ---");
47 <                
48 <        // get the command line args
49 <        String defaultProperties = DEFAULTPROPERTIES;
50 <        if (args.length > 0) {
51 <            if (args[0].equals("-l")) {
52 <                defaultProperties = args[1];
53 <            } 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);
45 >    public void start() throws ComponentStartException {
46 >        // start and bind each server in turn
47 >        
48 >        // work out which logger to use
49 >        String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass");
50 >        String loggerPackage = System.getProperty("uk.ac.ukc.iscream.LoggerPackage");
51 >      
52 >        // construct the relevant LoggerImpl
53 >        LoggerImpl loggerImplRef = null;
54          try {
55 <            Properties initProperties = new Properties(System.getProperties());
70 <            initProperties.load(new FileInputStream(new File(defaultProperties)));
71 <            System.setProperties(initProperties);
72 <
73 <
55 >            loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance();
56          } catch (Exception e) {
57 <            System.err.println(toString + ": ERROR " + e.getMessage());
58 <            usage();
57 >            // if anything goes wrong we throw a failed start exception
58 >            throw new ComponentStartException("unable to load logging class");
59          }
60  
61 <        // continue to bring the system up
62 <        System.out.println(toString + ": coming up");        
63 <        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 <            // check we got it
94 <            if (ncRef == null) {
95 <                throw new Exception("Unable to locate CORBA Naming Service for configured ORB!");
96 <            }
97 <            
98 <            // start and bind each server in turn
99 <            
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 <            // 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);
61 >        // setup and bind the LoggerServant
62 >        LoggerServant loggerRef = new LoggerServant(loggerImplRef);
63 >        _refman.bindToOrb(loggerRef, "iscream.Logger");
64  
65 <            // create the Configurator
66 <            ConfigurationManagerServant configManRef = new ConfigurationManagerServant(poa, logRef);
67 <            
68 <            // and advertise it to the naming context
69 <            objRef = poa.servant_to_reference(configManRef);
70 <            ncRef.bind(ncRef.to_name("iscream.ConfigurationManager"), objRef);
71 <            
72 <            // start the POA off
73 <            poa.the_POAManager().activate();
74 <                        
124 <            logRef.write(toString, Logger.SYSINIT, "started");
125 <            
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();
129 <            
130 <        // if there was a problem then we'll get to here    
131 <        } catch (Exception e) {
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("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 if debug is enabled
139 <            } else {
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 <        }
65 >        // get a reference to the servant as a Logger
66 >        _logger = _refman.getLogger();          
67 >    
68 >        // create the Configurator
69 >        ConfigurationManagerServant configManRef = new ConfigurationManagerServant();
70 >        
71 >        // and advertise it to the naming context
72 >        _refman.bindToOrb(configManRef, "iscream.ConfigurationManager");
73 >
74 >        _logger.write(toString(), Logger.SYSINIT, "started");
75      }
76      
77 <    /**
78 <     * A simple method to print the usage of this class.
79 <     * It never returns, but instead exits to the system
80 <     * with a value 1, to indicate the system did not start
81 <     * properly.
77 >    /**
78 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
79 >     * method to provide clean logging (every class should have this).
80 >     *
81 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
82 >     * to format the toString()
83 >     *
84 >     * @return the name of this class and its CVS revision
85       */
86 <    public static void usage() {
87 <        System.out.println("USAGE: java Core <option>");
88 <        System.out.println("WHERE <option>:");
89 <        System.out.println("      -l <filename> - the location of initial system properties");
90 <        System.out.println("      -h            - this help screen");
160 <        System.exit(1);
86 >    public String toString() {
87 >        return FormatName.getName(
88 >            _name,
89 >            getClass().getName(),
90 >            REVISION);
91      }
92  
163 //---CONSTRUCTORS---
164
165 //---PUBLIC METHODS---
166
93   //---PRIVATE METHODS---
94  
95   //---ACCESSOR/MUTATOR METHODS---
96  
97   //---ATTRIBUTES---
98 <    
173 < //---STATIC ATTRIBUTES---
174 <  
98 >
99      /**
100 <     * Default logger, to be used when one is not provided
101 <     * in the configuration.
100 >     * This is the friendly identifier of the
101 >     * component this class is running in.
102 >     * eg, a Filter may be called "filter1",
103 >     * If this class does not have an owning
104 >     * component,  a name from the configuration
105 >     * can be placed here.  This name could also
106 >     * be changed to null for utility classes.
107       */
108 <    private static final String defaultLogger = "ScreenLogger";
109 <    
108 >    private String _name = Core.NAME;
109 >
110      /**
111 <     * Default configPath, to be used when one is not provided
112 <     * in the configuration.
111 >     * This holds a reference to the
112 >     * system logger that is being used.
113       */
114 <    private static final String defaultConfigPath = ".";
114 >    private Logger _logger;
115 >
116 >    /**
117 >     * A reference to the reference manager in use
118 >     */
119 >    private ReferenceManager _refman = ReferenceManager.getInstance();
120 >    
121 > //---STATIC ATTRIBUTES---
122  
123   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines