1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
+ |
package uk.org.iscream.cms.server.core; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
< |
import uk.ac.ukc.iscream.core.*; |
25 |
< |
import org.omg.CORBA.*; |
6 |
< |
import org.omg.CosNaming.*; |
7 |
< |
import org.omg.PortableServer.*; |
24 |
> |
import uk.org.iscream.cms.server.util.*; |
25 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
26 |
|
|
27 |
|
/** |
28 |
|
* The main class for the CORE of the I-Scream system. |
29 |
< |
* The main method of this class initialises the ORB |
30 |
< |
* and then starts and registers CORE I-Scream services |
31 |
< |
* with the name service. At which point it essentially |
29 |
> |
* This class is the component for CORE I-Scream services |
30 |
> |
* namely the Logger and the ConfigurationManager. |
31 |
> |
* It registers and starts them, at which point it essentially |
32 |
|
* finishs its role and the started services continue to |
33 |
|
* serve requests from the I-Scream system. |
34 |
|
* |
35 |
|
* @author $Author$ |
36 |
|
* @version $Id$ |
37 |
|
*/ |
38 |
< |
class Core { |
38 |
> |
public class Core implements Component { |
39 |
|
|
40 |
|
//---FINAL ATTRIBUTES--- |
41 |
|
|
44 |
|
*/ |
45 |
|
public static final String REVISION = "$Revision$"; |
46 |
|
|
47 |
+ |
/** |
48 |
+ |
* The friendly name for this component, used by |
49 |
+ |
* all related classes. |
50 |
+ |
*/ |
51 |
+ |
public static final String NAME = "Core"; |
52 |
+ |
|
53 |
|
//---STATIC METHODS--- |
54 |
|
|
55 |
+ |
//---CONSTRUCTORS--- |
56 |
+ |
|
57 |
+ |
//---PUBLIC METHODS--- |
58 |
+ |
|
59 |
|
/** |
60 |
< |
* The main method which starts the CORE |
60 |
> |
* This method starts the CORE |
61 |
|
* Currently the args are passed direct to the ORB, |
62 |
|
* so any ORB paramaters could go there. |
63 |
|
* |
36 |
– |
* @param args the command line arguments |
64 |
|
*/ |
65 |
< |
public static void main(String[] args) { |
66 |
< |
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 ---"); |
65 |
> |
public void start() throws ComponentStartException { |
66 |
> |
// start and bind each server in turn |
67 |
|
|
68 |
< |
// can't have a real toString() :) |
69 |
< |
String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
70 |
< |
|
71 |
< |
System.out.println(toString + ": coming up"); |
72 |
< |
|
68 |
> |
// work out which logger to use |
69 |
> |
String whichLogger = System.getProperty("uk.org.iscream.cms.server.LoggerClass"); |
70 |
> |
String loggerPackage = System.getProperty("uk.org.iscream.cms.server.LoggerPackage"); |
71 |
> |
|
72 |
> |
// construct the relevant LoggerImpl |
73 |
> |
LoggerImpl loggerImplRef = null; |
74 |
|
try { |
75 |
< |
// 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(3); |
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(poa, logRef); |
75 |
< |
// and advertise it to the naming context |
76 |
< |
objRef = poa.servant_to_reference(configuratorRef); |
77 |
< |
ncRef.bind(ncRef.to_name("iscream.Configurator"), objRef); |
78 |
< |
|
79 |
< |
// start the POA off |
80 |
< |
poa.the_POAManager().activate(); |
81 |
< |
|
82 |
< |
logRef.write(toString, "started"); |
83 |
< |
|
84 |
< |
// now we are running, we just need to serve |
85 |
< |
// so we ask the orb to block for us until it has finished |
86 |
< |
orb.run(); |
87 |
< |
|
88 |
< |
// if there was a problem then we'll get to here |
75 |
> |
loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance(); |
76 |
|
} catch (Exception e) { |
77 |
< |
|
78 |
< |
// there is already another CORE of the same name registered |
92 |
< |
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
93 |
< |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
94 |
< |
|
95 |
< |
// otherwise we don't know what happened |
96 |
< |
// so print the error and do a stack trace |
97 |
< |
} else { |
98 |
< |
System.err.println("CORE ERROR: " + e); |
99 |
< |
e.printStackTrace(System.out); |
100 |
< |
} |
77 |
> |
// if anything goes wrong we throw a failed start exception |
78 |
> |
throw new ComponentStartException("unable to load logging class"); |
79 |
|
} |
102 |
– |
} |
80 |
|
|
81 |
< |
//---CONSTRUCTORS--- |
81 |
> |
// setup and bind the LoggerServant |
82 |
> |
LoggerServant loggerRef = new LoggerServant(loggerImplRef); |
83 |
> |
_refman.bindToOrb(loggerRef, "iscream.Logger"); |
84 |
|
|
85 |
< |
//---PUBLIC METHODS--- |
85 |
> |
// get a reference to the servant as a Logger |
86 |
> |
_logger = _refman.getLogger(); |
87 |
> |
|
88 |
> |
// create the Configurator |
89 |
> |
ConfigurationManagerServant configManRef = new ConfigurationManagerServant(); |
90 |
> |
|
91 |
> |
// and advertise it to the naming context |
92 |
> |
_refman.bindToOrb(configManRef, "iscream.ConfigurationManager"); |
93 |
|
|
94 |
+ |
_logger.write(toString(), Logger.SYSINIT, "started"); |
95 |
+ |
} |
96 |
+ |
|
97 |
+ |
/** |
98 |
+ |
* Does a dependency check. Used mainly at startup to |
99 |
+ |
* see if the required dependencies (components) are up |
100 |
+ |
* and running. |
101 |
+ |
* |
102 |
+ |
* @return a boolean value, true if the depdencies are satisfied |
103 |
+ |
*/ |
104 |
+ |
public boolean depCheck() { |
105 |
+ |
// the core has no depedencies |
106 |
+ |
return true; |
107 |
+ |
} |
108 |
+ |
|
109 |
+ |
/** |
110 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
111 |
+ |
* method to provide clean logging (every class should have this). |
112 |
+ |
* |
113 |
+ |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
114 |
+ |
* to format the toString() |
115 |
+ |
* |
116 |
+ |
* @return the name of this class and its CVS revision |
117 |
+ |
*/ |
118 |
+ |
public String toString() { |
119 |
+ |
return FormatName.getName( |
120 |
+ |
_name, |
121 |
+ |
getClass().getName(), |
122 |
+ |
REVISION); |
123 |
+ |
} |
124 |
+ |
|
125 |
|
//---PRIVATE METHODS--- |
126 |
|
|
127 |
|
//---ACCESSOR/MUTATOR METHODS--- |
128 |
|
|
129 |
|
//---ATTRIBUTES--- |
130 |
|
|
131 |
+ |
/** |
132 |
+ |
* This is the friendly identifier of the |
133 |
+ |
* component this class is running in. |
134 |
+ |
* eg, a Filter may be called "filter1", |
135 |
+ |
* If this class does not have an owning |
136 |
+ |
* component, a name from the configuration |
137 |
+ |
* can be placed here. This name could also |
138 |
+ |
* be changed to null for utility classes. |
139 |
+ |
*/ |
140 |
+ |
private String _name = Core.NAME; |
141 |
+ |
|
142 |
+ |
/** |
143 |
+ |
* This holds a reference to the |
144 |
+ |
* system logger that is being used. |
145 |
+ |
*/ |
146 |
+ |
private Logger _logger; |
147 |
+ |
|
148 |
+ |
/** |
149 |
+ |
* A reference to the reference manager in use |
150 |
+ |
*/ |
151 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
152 |
+ |
|
153 |
|
//---STATIC ATTRIBUTES--- |
154 |
|
|
155 |
|
} |