/** * Tutorial demo code. * * @version $Revision: 1.2 $ $Author: arossi * $ $Date: 2001/12/23 16:23:10 $ (GMT) * @author Albert L. Rossi [mailto:arossi@indiana.edu] */ package demo; import soaprmi.RemoteException; import soaprmi.server.UnicastRemoteObject; /** * Implementation of the ProvidesParamControl interface. * Extends soaprmi.UnicastRemoteObject. */ public class PrintEnvControlImpl extends UnicastRemoteObject implements demo.ProvidesParamControl { private PrintEnvComponent pec = null; /** * Must explicitly call the superclass * constructor as this is a remote object. * @param _pec reference to the underlying component * (PrintEnvComponent). */ public PrintEnvControlImpl (PrintEnvComponent _pec) throws RemoteException { super(); this.pec = _pec; } // constructor /** * Method defined by the Control_idl interface. * Routine for starting a component. * In the case of PrintEnvComponent, this method simply * returns 0. */ public int start() { //nothing to do return 0; } // start /** * Method defined by the Control_idl interface. * Routine for shutting down the JVM in which the * component is running. * * Spins off a separate thread which sleeps a few seconds * before calling System.exit, in order to avoid race * conditions. */ public int kill() { new Thread() { public void run() { try { Thread.sleep(3000); } catch (InterruptedException ie) {} System.exit(0); } }.start(); return 0; } // kill /** * Method defined by the Parameter_idl interface. * Routine for passing in parameters. * * Here implemented to call the component's "init" * method. * * @param param an array of Objects representing * the arguments of the method to be * called. In this implementation, * it is assumed that there is only * one: an array of Strings. */ public int sendParameter (Object [] param) { String [] args = (String []) param[0]; try { pec.init(args); } catch (Exception e) { System.err.println ("sendParameter: " + e); return -1; } return 0; } // sendParameter } // class PrintEnvControlImpl