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.25 by tdb, Tue May 29 17:02:34 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines