ALMA Computing Group

TimeoutHandlerClient.java

Go to the documentation of this file.
00001 /* 00002 * ALMA - Atacama Large Millimiter Array 00003 * (c) European Southern Observatory, 2002 00004 * Copyright by ESO (in the framework of the ALMA collaboration), 00005 * All rights reserved 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00020 * MA 02111-1307 USA 00021 */ 00022 package alma.demo.client; 00023 00024 import java.util.logging.Logger; 00025 00026 import alma.acs.component.client.ComponentClient; 00027 00028 import alma.acstime.Timer; 00029 import alma.acstime.Clock; 00030 import alma.acstime.TimeoutHandlerPOA; 00031 import alma.ACSErr.CompletionHolder; 00032 00033 public class TimeoutHandlerClient extends ComponentClient 00034 { 00042 private class TimeoutHandlerImpl extends TimeoutHandlerPOA 00043 { 00048 public void handleTimeout(alma.acstime.Epoch e) 00049 { 00050 System.out.println("The current time is: " + e.value); 00051 } 00052 } 00053 00057 private Timer m_timer = null; 00061 private Clock m_clock = null; 00062 00069 public TimeoutHandlerClient(Logger logger, String managerLoc, String clientName) 00070 throws Exception 00071 { 00072 super(logger, managerLoc, clientName); 00073 //Get the standard Clock component 00074 m_clock = alma.acstime.ClockHelper.narrow(getContainerServices().getComponent("CLOCK1")); 00075 //Get the standard Timer component 00076 m_timer = alma.acstime.TimerHelper.narrow(getContainerServices().getComponent("TIMER1")); 00077 } 00078 00079 public void doSomeStuff() 00080 throws Exception 00081 { 00082 //Schedule the timeout for now + three seconds. 00083 alma.ACS.ROuLongLong now = m_clock.now(); 00084 CompletionHolder completionHolder = new CompletionHolder(); 00085 alma.acstime.Epoch start = new alma.acstime.Epoch(now.get_sync(completionHolder)); 00086 start.value = start.value + 3000000; 00087 00088 //Timeout only occurs once 00089 alma.acstime.Duration period = new alma.acstime.Duration(0); 00090 00091 //Create timeout handler and schedule its timeout 00092 TimeoutHandlerImpl myHandler = new TimeoutHandlerImpl(); 00093 //The TimeoutHandler IDL interface is derived from ACS::OffShoot so 00094 //the container services can be used to activate it as a CORBA object 00095 alma.acstime.TimeoutHandler handlerCORBARef = alma.acstime.TimeoutHandlerHelper.narrow(getContainerServices().activateOffShoot(myHandler)); 00096 //Schedule the timeout with the Timer device. Although we save 00097 //the timeout ID in a variable, there is really no point since 00098 //this is a one-shot timeout that should not be cancelled. 00099 int id1 = m_timer.schedule(handlerCORBARef, 00100 start, 00101 period); 00102 } 00103 00107 public static void main(String[] args) 00108 throws Exception 00109 { 00110 String managerLoc = System.getProperty("ACS.manager"); 00111 if (managerLoc == null) 00112 { 00113 System.out.println("Java property 'ACS.manager' must be set to the corbaloc of the ACS manager!"); 00114 System.exit(-1); 00115 } 00116 00117 String clientName = "TimeoutHandlerClient"; 00118 00119 00120 final TimeoutHandlerClient lcbcl = new TimeoutHandlerClient(null, managerLoc, clientName); 00121 //Schedule the timeout 00122 lcbcl.doSomeStuff(); 00123 //Give it 20 seconds to occur (should only take 3 seconds). 00124 Thread.sleep(20000); 00125 System.out.println("20 sec waiting over, will tear down the show..."); 00126 lcbcl.tearDown(); 00127 } 00128 }