ALMA Computing Group

LampAccessImpl.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.LampAccessImpl; 00023 00024 import java.util.logging.Level; 00025 00026 import alma.ACS.CBDescIn; 00027 import alma.ACS.CBvoid; 00028 import alma.ACSErr.CompletionHolder; 00029 import alma.acs.container.ContainerServices; 00030 import alma.ACS.RWdouble; 00031 import alma.acs.component.ComponentImplBase; 00032 import alma.acs.component.ComponentLifecycleException; 00033 import alma.acsexmplLamp.Lamp; 00034 import alma.acsexmplLamp.LampHelper; 00035 import alma.demo.LampAccessOperations; 00036 import alma.demo.LampUnavailable; 00037 00038 00039 public class LampAccessImpl extends ComponentImplBase implements LampAccessOperations 00040 { 00041 private RWdouble m_brightness; 00042 private CBvoidLampAccess m_cb; 00043 private CBvoid m_cbvoid; 00044 private CBDescIn m_desc; 00045 private static final String m_lampCurl = "LAMP1"; 00046 00048 // Implementation of ComponentLifecycle 00050 00051 public void initialize(ContainerServices containerServices) throws ComponentLifecycleException 00052 { 00053 super.initialize(containerServices); 00054 m_logger.finer("initialize() called..."); 00055 00056 try 00057 { 00058 getLampBrightnessProperty(); 00059 } 00060 catch (Exception e) 00061 { 00062 throw new ComponentLifecycleException( 00063 "failed to get reference to 'brightness' " + 00064 "property of the lamp component.", e); 00065 } 00066 } 00067 00072 public void cleanUp() 00073 { 00074 m_logger.info("cleanUp() called..."); 00075 m_containerServices.releaseComponent(m_lampCurl); 00076 } 00077 00079 // Implementation of LampAccessOperations 00081 00088 public void setLampBrightness(double brightness) throws LampUnavailable 00089 { 00090 m_logger.finer("LampAccess:setLampBrightness(" + brightness + ") called..."); 00091 00092 if (m_brightness == null) 00093 { 00094 m_brightness = getLampBrightnessProperty(); 00095 m_logger.info("m_brightness initialized..."); 00096 } 00097 00098 if (m_cb == null) 00099 { 00100 try 00101 { 00102 m_cb = new CBvoidLampAccess(m_logger); 00103 m_logger.info("CBvoidLampAccess instantiated..."); 00104 m_cbvoid = alma.ACS.CBvoidHelper.narrow(m_containerServices.activateOffShoot(m_cb)); 00105 00106 // m_logger.warning("doof test: second activation..."); 00107 // CBvoidLampAccess cb2 = new CBvoidLampAccess(m_logger); 00108 // m_containerServices.activateOffShoot(cb2); 00109 } 00110 catch (Exception e) 00111 { 00112 m_logger.log(Level.SEVERE, "failed to obtain the callback offshoot object.", e); 00113 throw new LampUnavailable(e.getMessage()); 00114 } 00115 00116 } 00117 00118 if (m_desc == null) 00119 { 00120 m_desc = new CBDescIn(); 00121 m_logger.info("m_desc instantiated..."); 00122 } 00123 try 00124 { 00125 m_logger.info("before callback done..."); 00126 getLampBrightnessProperty().set_async(brightness, m_cbvoid, m_desc); 00127 m_logger.finer("now callback done..."); 00128 } 00129 catch (Exception ex) 00130 { 00131 m_logger.log(Level.SEVERE, "ex in setLampBrightness impl", ex); 00132 throw new LampUnavailable(ex.getMessage()); 00133 } 00134 } 00135 00142 public double getLampBrightness() throws LampUnavailable 00143 { 00144 m_logger.finer("LampAccess:getLampBrightness() called..."); 00145 00146 try 00147 { 00148 m_brightness = getLampBrightnessProperty(); 00149 CompletionHolder compHolder = new CompletionHolder(); 00150 return m_brightness.get_sync(compHolder); 00151 00152 } 00153 catch (Exception ex) 00154 { 00155 throw new LampUnavailable(ex.getMessage()); 00156 } 00157 } 00158 00159 00161 // other 00163 00169 RWdouble getLampBrightnessProperty() throws LampUnavailable 00170 { 00171 if (m_brightness == null) 00172 { 00173 org.omg.CORBA.Object cmp = null; 00174 try 00175 { 00176 cmp = m_containerServices.getComponent(m_lampCurl); 00177 Lamp lamp = LampHelper.narrow(cmp); 00178 m_brightness = lamp.brightness(); 00179 } 00180 catch (Exception ex) 00181 { 00182 throw new LampUnavailable(ex.getMessage()); 00183 } 00184 00185 if (m_brightness == null) 00186 { 00187 throw new LampUnavailable("failed to obtain the lamp component's brightness property (NULL)."); 00188 } 00189 } 00190 return m_brightness; 00191 } 00192 00193 // /** 00194 // * Throws an exception that is of type LampAccessAcsJEx. 00195 // * @throws ACSException 00196 // */ 00197 // public void brightLampExceptionMethod() throws ACSException 00198 // { 00199 // try 00200 // { 00201 // throw new LampAccessAcsJEx("mean bright lamp exception"); 00202 // } 00203 // catch (AcsJException ex) 00204 // { 00205 // AcsJException acsEx = new LampAccessAcsJEx("caught exception", ex); 00206 // ACSException e = ex.getACSException(); 00207 // throw e; 00208 // } 00209 // } 00210 } 00211