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.1 by ajm, Wed Nov 8 21:24:33 2000 UTC vs.
Revision 1.18 by ajm, Tue Dec 12 18:26:52 2000 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.core;
3  
4   //---IMPORTS---
5 < import core.*;
5 < import org.omg.CORBA.*;
6 < import org.omg.CosNaming.*;
7 < import org.omg.PortableServer.*;
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 26 | Line 24 | class Core {
24       */
25      public static final String REVISION = "$Revision$";
26      
27 +    /**
28 +     * The friendly name for the Core, used by
29 +     * all related classes.
30 +     */
31 +    public static final String NAME = "CORE";
32 +    
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       *
44       * @param args the command line arguments
45       */
46 <    public static void main(String[] args) {
47 <        System.out.println("I-Scream CORE:" + REVISION + " - coming up.");
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.ac.ukc.iscream.LoggerClass");
51 >        String loggerPackage = System.getProperty("uk.ac.ukc.iscream.LoggerPackage");
52 >      
53 >        // construct the relevant LoggerImpl
54 >        LoggerImpl loggerImplRef = null;
55          try {
56 <            // start the ORB
42 <            ORB orb = ORB.init(args, null);
43 <            
44 <            // get the Root POA
45 <            org.omg.CORBA.Object objRef = orb.resolve_initial_references("RootPOA");
46 <            POA poa = POAHelper.narrow(objRef);
47 <            
48 <            // get a hook to the name service
49 <            objRef = orb.resolve_initial_references("NameService");
50 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
51 <            
52 <            // get a ref to our servers
53 <            // first the Configurator
54 <            ConfiguratorServant configuratorRef = new ConfiguratorServant(poa);
55 <            
56 <            // then the logger
57 <            // **** PUT THE LOGGER HERE TIM ****
58 <            
59 <            // advertise them to the naming context
60 <            // Configurator
61 <            objRef = poa.servant_to_reference(configuratorRef);
62 <            ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef);
63 <            
64 <            // Logger
65 <            // **** REGISTER THE LOGGER WITH THE NAME SERVICE TIM ****
66 <            
67 <            // start the POA off
68 <            poa.the_POAManager().activate();            
69 <            
70 <            
71 <            System.out.println("I-Scream CORE:" + REVISION + " - started.");
72 <            
73 <            // now we are running, we just need to serve
74 <            // so we ask the orb to block for us until it has finished
75 <            orb.run();
76 <            
77 <        // if there was a problem then we'll get to here    
56 >            loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance();
57          } catch (Exception e) {
58 <            
59 <            // there is already another CORE of the same name registered
81 <            if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) {
82 <                System.err.println("ERROR: Another I-Scream CORE is already registered under the same name.");
83 <            
84 <            // otherwise we don't know what happened
85 <            // so print the error and do a stack trace
86 <            } else {
87 <                System.err.println("CORE ERROR: " + e);
88 <                e.printStackTrace(System.out);
89 <            }
58 >            // if anything goes wrong we throw a failed start exception
59 >            throw new ComponentStartException("unable to load logging class");
60          }
61 <    }
61 >        
62 >        // setup and bind the LoggerServant
63 >        LoggerServant loggerRef = new LoggerServant(loggerImplRef);
64 >        _refman.bindToOrb(loggerRef, "iscream.Logger");
65  
66 < //---CONSTRUCTORS---
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 < //---PUBLIC METHODS---
75 >        _logger.write(toString(), Logger.SYSINIT, "started");
76 >    }
77 >    
78 >    /**
79 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
80 >     * method to provide clean logging (every class should have this).
81 >     *
82 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
83 >     * to format the toString()
84 >     *
85 >     * @return the name of this class and its CVS revision
86 >     */
87 >    public String toString() {
88 >        return FormatName.getName(
89 >            _name,
90 >            this.getClass().getName(),
91 >            REVISION);
92 >    }
93  
94   //---PRIVATE METHODS---
95  
# Line 100 | Line 97 | class Core {
97  
98   //---ATTRIBUTES---
99  
100 +    /**
101 +     * This is the friendly identifier of the
102 +     * component this class is running in.
103 +     * eg, a Filter may be called "filter1",
104 +     * If this class does not have an owning
105 +     * component,  a name from the configuration
106 +     * can be placed here.  This name could also
107 +     * be changed to null for utility classes.
108 +     */
109 +    private String _name = Core.NAME;
110 +
111 +    /**
112 +     * This holds a reference to the
113 +     * system logger that is being used.
114 +     */
115 +    private Logger _logger;
116 +
117 +    /**
118 +     * A reference to the reference manager in use
119 +     */
120 +    private ReferenceManager _refman = ReferenceManager.getInstance();
121 +    
122   //---STATIC ATTRIBUTES---
123  
124 < }
124 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines