--- projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/FilterManager.java 2000/12/07 12:30:15 1.11 +++ projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/FilterManager.java 2000/12/12 19:17:02 1.12 @@ -2,78 +2,117 @@ package uk.ac.ukc.iscream.filtermanager; //---IMPORTS--- -import uk.ac.ukc.iscream.core.*; import uk.ac.ukc.iscream.util.*; +import uk.ac.ukc.iscream.core.*; /** - * The FilterManager handles assignment of Filters to hosts. + * The FilterManager handles initialisation + * of hosts with the system, allowing hosts to + * gain their configuration and a hook to a Filter + * to talk to. * - * @author $Author: tdb $ - * @version $Id: FilterManager.java,v 1.11 2000/12/07 12:30:15 tdb Exp $ + * @author $Author: ajm $ + * @version $Id: FilterManager.java,v 1.12 2000/12/12 19:17:02 ajm Exp $ */ -class FilterManager { +public class FilterManager implements uk.ac.ukc.iscream.util.Component { //---FINAL ATTRIBUTES--- /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.11 $"; + public static final String REVISION = "$Revision: 1.12 $"; + /** + * The friendly name for the FilterManager, used by + * all related classes. + */ + public static final String NAME = "FilterManager"; + //---STATIC METHODS--- - public static void main(String[] args) { - // *************************************** - // VERY TEMPORARY - will find a better way - System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); - System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); - // *************************************** - - // can't have a real toString() :) - String toString = "FilterManager(" + REVISION.substring(11, REVISION.length() - 2) + ")"; +//---CONSTRUCTORS--- + +//---PUBLIC METHODS--- + + /** + * This method starts the FilterManager + */ + public void start() throws ComponentStartException { + + _logger.write(toString(), Logger.SYSINIT, "coming up"); - ReferenceManager refman = ReferenceManager.init(null, null); - - refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); - // configuration variable we require int listenPort = 0; - Configuration config = refman.getCM().getConfiguration("FilterManager"); + Configuration config = _refman.getCM().getConfiguration("FilterManager"); if (config == null) { - throw new RuntimeException ("CRITICAL:Unable to obtain configuration" + - " Advise you check the i-scream log for more information."); + System.err.println("CRITICAL:Unable to obtain configuration" + + "\n Advise you check the i-scream log for more information."); + _logger.write(toString(), Logger.FATAL, "ERROR - unable to obtain configuration"); + System.exit(1); } else { try { listenPort = Integer.parseInt(config.getProperty("FilterManager.listenPort")); } catch (org.omg.CORBA.MARSHAL e) { - refman.getLogger().write(toString, Logger.FATAL, "required config property not present"); - throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" + - " Advise you check the i-scream log for more information."); - + System.err.println ("CRITICAL:Unable to obtain required configuration property" + + "\n Advise you check the i-scream log for more information."); + _logger.write(toString(), Logger.FATAL, "ERROR - required configuration property not present"); + System.exit(1); } } - refman.getLogger().write(toString, Logger.SYSINIT, "configured"); + _logger.write(toString(), Logger.SYSMSG, "configured"); - refman.getLogger().write(toString, Logger.SYSINIT, "starting listener"); - HostListener hostListener = new HostListener(listenPort); hostListener.start(); - refman.getLogger().write(toString, Logger.SYSINIT, "listener started"); - + _logger.write(toString(), Logger.SYSINIT, "started"); } -//---CONSTRUCTORS--- + /** + * Overrides the {@link java.lang.Object#toString() Object.toString()} + * method to provide clean logging (every class should have this). + * + * This uses the uk.ac.ukc.iscream.util.NameFormat class + * to format the toString() + * + * @return the name of this class and its CVS revision + */ + public String toString() { + return FormatName.getName( + _name, + this.getClass().getName(), + REVISION); + } -//---PUBLIC METHODS--- - //---PRIVATE METHODS--- //---ACCESSOR/MUTATOR METHODS--- //---ATTRIBUTES--- + + /** + * This is the friendly identifier of the + * component this class is running in. + * eg, a Filter may be called "filter1", + * If this class does not have an owning + * component, a name from the configuration + * can be placed here. This name could also + * be changed to null for utility classes. + */ + private String _name = FilterManager.NAME; + + /** + * This holds a reference to the + * system logger that is being used. + */ + private Logger _logger = ReferenceManager.getInstance().getLogger(); + + /** + * A reference to the reference manager in use + */ + private ReferenceManager _refman = ReferenceManager.getInstance(); //---STATIC ATTRIBUTES---