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.9 by tdb, Thu Nov 16 18:00:36 2000 UTC vs.
Revision 1.10 by ajm, Thu Nov 16 19:28:03 2000 UTC

# Line 1 | Line 1
1 < //---PACKAGE DECLARATION---
2 <
3 < //---IMPORTS---
4 < import uk.ac.ukc.iscream.core.*;
5 < import org.omg.CORBA.*;
6 < import org.omg.CosNaming.*;
7 < import org.omg.PortableServer.*;
8 <
9 < /**
10 < * The main class for the CORE of the I-Scream system.
11 < * The main method of this class initialises the ORB
12 < * and then starts and registers CORE I-Scream services
13 < * with the name service.  At which point it essentially
14 < * finishs its role and the started services continue to
15 < * serve requests from the I-Scream system.
16 < *
17 < * @author  $Author$
18 < * @version $Id$
19 < */
20 < class Core {
21 <
22 < //---FINAL ATTRIBUTES---
23 <
24 <    /**
25 <     * The current CVS revision of this class
26 <     */
27 <    public static final String REVISION = "$Revision$";
28 <    
29 < //---STATIC METHODS---
30 <
31 <    /**
32 <     * The main method which starts the CORE
33 <     * Currently the args are passed direct to the ORB,
34 <     * so any ORB paramaters could go there.
35 <     *
36 <     * @param args the command line arguments
37 <     */
38 <    public static void main(String[] args) {
39 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
40 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
41 <
42 <        System.out.println("--- I-Scream ---");
43 <        
44 <        // can't have a real toString() :)
45 <        String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")";
46 <        
47 <        System.out.println(toString + ": coming up");
48 <        
49 <        try {
50 <            // start the ORB
51 <            ORB orb = ORB.init(args, null);
52 <            
53 <            // get the Root POA
54 <            org.omg.CORBA.Object objRef = orb.resolve_initial_references("RootPOA");
55 <            POA poa = POAHelper.narrow(objRef);
56 <            
57 <            // get a hook to the name service
58 <            objRef = orb.resolve_initial_references("NameService");
59 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
60 <            
61 <            // start and bind each server in turn
62 <
63 <            // create the logger (either Screen or File)
64 <            ScreenLoggerServant loggerRef = new ScreenLoggerServant(Logger.SYSINIT);
65 <            //FileLoggerServant loggerRef = new FileLoggerServant("core.log");
66 <            // and advertise it to the naming context
67 <            objRef = poa.servant_to_reference(loggerRef);
68 <            ncRef.bind(ncRef.to_name("iscream.Logger"), objRef);
69 <            
70 <            // get a ref to the logger servant as a Logger reference
71 <            Logger logRef = LoggerHelper.narrow(objRef);
72 <            
73 <            // create the Configurator
74 <            ConfiguratorServant configuratorRef = new ConfiguratorServant("../configuration/", poa, logRef);
75 <            
76 <            // and advertise it to the naming context
77 <            objRef = poa.servant_to_reference(configuratorRef);
78 <            ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef);
79 <            
80 <            // start the POA off
81 <            poa.the_POAManager().activate();
82 <                        
83 <            logRef.write(toString, Logger.SYSINIT, "started");
84 <            
85 <            // now we are running, we just need to serve
86 <            // so we ask the orb to block for us until it has finished
87 <            orb.run();
88 <            
89 <        // if there was a problem then we'll get to here    
90 <        } catch (Exception e) {
91 <            
92 <            // there is already another CORE of the same name registered
93 <            if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) {
94 <                System.err.println("ERROR: Another I-Scream CORE is already registered under the same name.");
95 <            
96 <            // otherwise we don't know what happened
97 <            // so print the error and do a stack trace
98 <            } else {
99 <                System.err.println("CORE ERROR: " + e);
100 <                e.printStackTrace(System.out);
101 <            }
102 <        }
103 <    }
104 <
105 < //---CONSTRUCTORS---
106 <
107 < //---PUBLIC METHODS---
108 <
109 < //---PRIVATE METHODS---
110 <
111 < //---ACCESSOR/MUTATOR METHODS---
112 <
113 < //---ATTRIBUTES---
114 <
115 < //---STATIC ATTRIBUTES---
116 <
117 < }
1 > //---PACKAGE DECLARATION---
2 >
3 > //---IMPORTS---
4 > 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.
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 > * @author  $Author$
20 > * @version $Id$
21 > */
22 > class Core {
23 >
24 > //---FINAL ATTRIBUTES---
25 >
26 >    /**
27 >     * The current CVS revision of this class
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 >    /**
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 >            // start and bind each server in turn
94 >
95 >            // create the logger (either Screen or File)
96 >            ScreenLoggerServant loggerRef = new ScreenLoggerServant(Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")));
97 >            //FileLoggerServant loggerRef = new FileLoggerServant("core.log");
98 >            // and advertise it to the naming context
99 >            objRef = poa.servant_to_reference(loggerRef);
100 >            ncRef.bind(ncRef.to_name("iscream.Logger"), objRef);
101 >            
102 >            // get a ref to the logger servant as a Logger reference
103 >            Logger logRef = LoggerHelper.narrow(objRef);
104 >            
105 >            // create the Configurator
106 >            ConfiguratorServant configuratorRef = new ConfiguratorServant(System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation"), poa, logRef);
107 >            
108 >            // and advertise it to the naming context
109 >            objRef = poa.servant_to_reference(configuratorRef);
110 >            ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef);
111 >            
112 >            // start the POA off
113 >            poa.the_POAManager().activate();
114 >                        
115 >            logRef.write(toString, Logger.SYSINIT, "started");
116 >            
117 >            // now we are running, we just need to serve
118 >            // so we ask the orb to block for us until it has finished
119 >            orb.run();
120 >            
121 >        // if there was a problem then we'll get to here    
122 >        } catch (Exception e) {
123 >            
124 >            // there is already another CORE of the same name registered
125 >            if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) {
126 >                System.err.println("ERROR: Another I-Scream CORE is already registered under the same name.");
127 >            
128 >            // otherwise we don't know what happened
129 >            // so print the error and do a stack trace
130 >            } else {
131 >                System.err.println("CORE ERROR: " + e);
132 >                e.printStackTrace(System.out);
133 >            }
134 >        }
135 >    }
136 >    
137 >    /**
138 >     * A simple method to print the usage of this class.
139 >     * It never returns, but instead exits to the system
140 >     * with a value 1, to indicate the system did not start
141 >     * properly.
142 >     */
143 >    public static void usage() {
144 >        System.out.println("USAGE: java Core.java <option>");
145 >        System.out.println("WHERE <option>:");
146 >        System.out.println("      -l <filename> - the location of initial system properties");
147 >        System.out.println("      -h            - this help screen");
148 >        System.exit(1);
149 >    }
150 >
151 > //---CONSTRUCTORS---
152 >
153 > //---PUBLIC METHODS---
154 >
155 > //---PRIVATE METHODS---
156 >
157 > //---ACCESSOR/MUTATOR METHODS---
158 >
159 > //---ATTRIBUTES---
160 >
161 > //---STATIC ATTRIBUTES---
162 >
163 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines