--- projects/cms/source/server/uk/org/iscream/cms/server/client/ClientMain.java 2001/02/05 20:45:32 1.4 +++ projects/cms/source/server/uk/org/iscream/cms/server/client/ClientMain.java 2001/02/21 22:48:20 1.5 @@ -1,45 +1,125 @@ +//---PACKAGE DECLARATION--- package uk.ac.ukc.iscream.client; -import uk.ac.ukc.iscream.client.*; +//---IMPORTS--- import uk.ac.ukc.iscream.clientinterface.*; import uk.ac.ukc.iscream.componentmanager.*; -import org.omg.CosNaming.*; -import org.omg.CORBA.*; -import org.omg.PortableServer.*; +import uk.ac.ukc.iscream.core.*; +import uk.ac.ukc.iscream.util.*; -public class ClientMain { - public static void main(String args[]) { - System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); - System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); - try { - ReferenceManager _refman = ReferenceManager.getInstance(); - _refman.activatePOA(); +/** + * A startup component for the Local Clients. + * + * @author $Author: tdb $ + * @version $Id: ClientMain.java,v 1.5 2001/02/21 22:48:20 tdb Exp $ + */ +public class ClientMain implements Component { - ClientServant corbaServant = new ClientServant(); - org.omg.CORBA.Object o = _refman.getRootPOA().servant_to_reference(corbaServant); - Client client = ClientHelper.narrow(o); +//---FINAL ATTRIBUTES--- - o = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); - CorbaClientListener lRef = CorbaClientListenerHelper.narrow(o); + /** + * The current CVS revision of this class + */ + public static final String REVISION = "$Revision: 1.5 $"; + + /** + * The friendly name for this component, used by + * all related classes. + */ + public static final String NAME = "LocalClient"; + +//---STATIC METHODS--- - boolean result; - System.out.println(" -- connecting -- "); - CorbaControlHandler handler = lRef.connect(client); - System.out.println(" -- starting data -- "); - result = handler.startData(); - //System.out.println(" -- sleep for 30s -- "); - //Thread.sleep(30000); - //System.out.println(" -- stopping data -- "); - //result = handler.stopData(); - //Thread.sleep(2000); - //System.out.println(" -- completed -- "); - _refman.getORB().run(); +//---CONSTRUCTORS--- +//---PUBLIC METHODS--- + + /** + * This starts the Local Client component + */ + public void start() throws ComponentStartException { + + _logger.write(toString(), Logger.SYSINIT, "coming up"); + + // configuration variables we require + int queueMonitorInterval = 0; + + Configuration config = _refman.getCM().getConfiguration("LocalClient"); + if (config == null) { + throw new ComponentStartException("Unable to obtain configuration for component"); } - catch (Exception e) { - System.out.println("ERROR : " + e); - e.printStackTrace(System.out); + else { + try { + // get the configuration properties we need + queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval")); + } catch (org.omg.CORBA.MARSHAL e) { + throw new ComponentStartException("Unable to obtain requried configuration property for component"); + } } + + _logger.write(toString(), Logger.SYSINIT, "configured"); + + // setup the servant + _logger.write(toString(), Logger.SYSINIT, "starting servant"); + + Client client; + + try { + ClientServant ref = new ClientServant(); + org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); + client = ClientHelper.narrow(objRef); + + // this name maybe shouldn't be static + objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener"); + CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef); + + _logger.write(toString(), Logger.SYSINIT, "connecting"); + CorbaControlHandler handler = listener.connect(client); + handler.startData(); + } + catch(Exception e) { + // not sure what to do here + // so we just log the error + _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage()); + } + + _logger.write(toString(), Logger.SYSINIT, "started"); + } + + /** + * 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.FormatName class + * to format the toString() + * + * @return the name of this class and its CVS revision + */ + public String toString() { + return FormatName.getName( + NAME, + getClass().getName(), + REVISION); + } + +//---PRIVATE METHODS--- + +//---ACCESSOR/MUTATOR METHODS--- + +//---ATTRIBUTES--- + + /** + * 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--- }