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.5 by tdb, Mon Nov 13 18:21:15 2000 UTC vs.
Revision 1.13 by tdb, Mon Nov 20 18:44:49 2000 UTC

# Line 5 | Line 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.*;
10  
11   /**
12   * The main class for the CORE of the I-Scream system.
# Line 26 | Line 28 | class Core {
28       */
29      public static final String REVISION = "$Revision$";
30      
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      /**
# Line 37 | Line 50 | class Core {
50       */
51      public static void main(String[] args) {
52          System.out.println("--- I-Scream ---");
53 <        
54 <        // can't have a real toString() :)
55 <        String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")";
56 <        
57 <        System.out.println(toString + ": coming up");
58 <        
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              
# Line 56 | Line 91 | class Core {
91              NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
92              
93              // start and bind each server in turn
94 <
95 <            // create the logger (either Screen or File)
96 <            ScreenLoggerServant loggerRef = new ScreenLoggerServant();
97 <            //FileLoggerServant loggerRef = new FileLoggerServant("core.log");
98 <            // and advertise it to the naming context
94 >            
95 >            // work out which logger to use
96 >            String whichLogger = System.getProperty("uk.ac.ukc.iscream.LoggerClass", defaultLogger);
97 >          
98 >            // construct the relevant LoggerImpl
99 >            LoggerImpl loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(whichLogger).newInstance();
100 >            
101 >            // setup and bind the LoggerServant
102 >            LoggerServant loggerRef = new LoggerServant(loggerImplRef);
103              objRef = poa.servant_to_reference(loggerRef);
104              ncRef.bind(ncRef.to_name("iscream.Logger"), objRef);
105              
106 <            // get a ref to the logger servant as a Logger reference
106 >            // get a reference to the servant as a Logger
107              Logger logRef = LoggerHelper.narrow(objRef);
108 <            
108 >
109 >
110 >
111              // create the Configurator
112 <            ConfiguratorServant configuratorRef = new ConfiguratorServant(poa, logRef);
112 >            String configLocation = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation", defaultConfigPath);
113 >            ConfigurationManagerServant configManRef = new ConfigurationManagerServant(poa, logRef);
114 >            
115              // and advertise it to the naming context
116 <            objRef = poa.servant_to_reference(configuratorRef);
117 <            ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef);
116 >            objRef = poa.servant_to_reference(configManRef);
117 >            ncRef.bind(ncRef.to_name("iscream.ConfigurationManager"), objRef);
118              
119              // start the POA off
120              poa.the_POAManager().activate();
121                          
122 <            logRef.write(toString, "started");
122 >            logRef.write(toString, Logger.SYSINIT, "started");
123              
124              // now we are running, we just need to serve
125              // so we ask the orb to block for us until it has finished
# Line 97 | Line 140 | class Core {
140              }
141          }
142      }
143 +    
144 +    /**
145 +     * A simple method to print the usage of this class.
146 +     * It never returns, but instead exits to the system
147 +     * with a value 1, to indicate the system did not start
148 +     * properly.
149 +     */
150 +    public static void usage() {
151 +        System.out.println("USAGE: java Core.java <option>");
152 +        System.out.println("WHERE <option>:");
153 +        System.out.println("      -l <filename> - the location of initial system properties");
154 +        System.out.println("      -h            - this help screen");
155 +        System.exit(1);
156 +    }
157  
158   //---CONSTRUCTORS---
159  
# Line 107 | Line 164 | class Core {
164   //---ACCESSOR/MUTATOR METHODS---
165  
166   //---ATTRIBUTES---
167 <
167 >    
168   //---STATIC ATTRIBUTES---
169 +  
170 +    /**
171 +     * Default logger, to be used when one is not provided
172 +     * in the configuration.
173 +     */
174 +    private static final String defaultLogger = "ScreenLogger";
175 +    
176 +    /**
177 +     * Default configPath, to be used when one is not provided
178 +     * in the configuration.
179 +     */
180 +    private static final String defaultConfigPath = ".";
181  
182   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines