| 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.*; |
| 8 |
< |
import java.util.*; |
| 9 |
< |
import java.io.*; |
| 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 |
|
|
| 45 |
|
public static final String REVISION = "$Revision$"; |
| 46 |
|
|
| 47 |
|
/** |
| 48 |
< |
* The toString() of this class |
| 49 |
< |
* As it won't be instatiated, this is needed. |
| 48 |
> |
* The friendly name for this component, used by |
| 49 |
> |
* all related classes. |
| 50 |
|
*/ |
| 51 |
< |
public static final String toString = "CORE(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
| 51 |
> |
public static final String NAME = "Core"; |
| 52 |
|
|
| 37 |
– |
/** |
| 38 |
– |
* The default location of the properties file for the system |
| 39 |
– |
*/ |
| 40 |
– |
public static final String DEFAULTPROPERTIES = "default.properties"; |
| 41 |
– |
|
| 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 |
|
* |
| 49 |
– |
* @param args the command line arguments |
| 64 |
|
*/ |
| 65 |
< |
public static void main(String[] args) { |
| 66 |
< |
System.out.println("--- I-Scream ---"); |
| 67 |
< |
|
| 68 |
< |
// get the command line args |
| 69 |
< |
String defaultProperties = DEFAULTPROPERTIES; |
| 70 |
< |
if (args.length > 0) { |
| 71 |
< |
if (args[0].equals("-l")) { |
| 72 |
< |
defaultProperties = args[1]; |
| 73 |
< |
} 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); |
| 65 |
> |
public void start() throws ComponentStartException { |
| 66 |
> |
// start and bind each server in turn |
| 67 |
> |
|
| 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 |
< |
Properties initProperties = new Properties(System.getProperties()); |
| 70 |
< |
initProperties.load(new FileInputStream(new File(defaultProperties))); |
| 71 |
< |
System.setProperties(initProperties); |
| 72 |
< |
|
| 73 |
< |
|
| 75 |
> |
loggerImplRef = (LoggerImpl) ClassLoader.getSystemClassLoader().loadClass(loggerPackage + "." + whichLogger).newInstance(); |
| 76 |
|
} catch (Exception e) { |
| 77 |
< |
System.err.println(toString + ": ERROR " + e.getMessage()); |
| 78 |
< |
usage(); |
| 77 |
> |
// if anything goes wrong we throw a failed start exception |
| 78 |
> |
throw new ComponentStartException("unable to load logging class"); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
< |
// continue to bring the system up |
| 82 |
< |
System.out.println(toString + ": coming up"); |
| 83 |
< |
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 |
< |
// 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 reference to the servant as a Logger |
| 107 |
< |
Logger logRef = LoggerHelper.narrow(objRef); |
| 81 |
> |
// setup and bind the LoggerServant |
| 82 |
> |
LoggerServant loggerRef = new LoggerServant(loggerImplRef); |
| 83 |
> |
_refman.bindToOrb(loggerRef, "iscream.Logger"); |
| 84 |
|
|
| 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 |
< |
|
| 111 |
< |
// create the Configurator |
| 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(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, 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 |
| 126 |
< |
orb.run(); |
| 127 |
< |
|
| 128 |
< |
// if there was a problem then we'll get to here |
| 129 |
< |
} catch (Exception e) { |
| 130 |
< |
|
| 131 |
< |
// there is already another CORE of the same name registered |
| 132 |
< |
if ( e instanceof org.omg.CosNaming.NamingContextPackage.AlreadyBound) { |
| 133 |
< |
System.err.println("ERROR: Another I-Scream CORE is already registered under the same name."); |
| 134 |
< |
|
| 135 |
< |
// otherwise we don't know what happened |
| 136 |
< |
// so print the error and do a stack trace |
| 137 |
< |
} else { |
| 138 |
< |
System.err.println("CORE ERROR: " + e); |
| 139 |
< |
e.printStackTrace(System.out); |
| 140 |
< |
} |
| 141 |
< |
} |
| 94 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
< |
/** |
| 98 |
< |
* A simple method to print the usage of this class. |
| 99 |
< |
* It never returns, but instead exits to the system |
| 100 |
< |
* with a value 1, to indicate the system did not start |
| 101 |
< |
* properly. |
| 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 static void usage() { |
| 105 |
< |
System.out.println("USAGE: java Core.java <option>"); |
| 106 |
< |
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); |
| 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 |
|
|
| 158 |
– |
//---CONSTRUCTORS--- |
| 159 |
– |
|
| 160 |
– |
//---PUBLIC METHODS--- |
| 161 |
– |
|
| 125 |
|
//---PRIVATE METHODS--- |
| 126 |
|
|
| 127 |
|
//---ACCESSOR/MUTATOR METHODS--- |
| 128 |
|
|
| 129 |
|
//---ATTRIBUTES--- |
| 130 |
< |
|
| 168 |
< |
//---STATIC ATTRIBUTES--- |
| 169 |
< |
|
| 130 |
> |
|
| 131 |
|
/** |
| 132 |
< |
* Default logger, to be used when one is not provided |
| 133 |
< |
* in the configuration. |
| 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 static final String defaultLogger = "ScreenLogger"; |
| 141 |
< |
|
| 140 |
> |
private String _name = Core.NAME; |
| 141 |
> |
|
| 142 |
|
/** |
| 143 |
< |
* Default configPath, to be used when one is not provided |
| 144 |
< |
* in the configuration. |
| 143 |
> |
* This holds a reference to the |
| 144 |
> |
* system logger that is being used. |
| 145 |
|
*/ |
| 146 |
< |
private static final String defaultConfigPath = "."; |
| 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 |
|
} |