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