ALMA Computing Group

EventSupplierImpl.java

Go to the documentation of this file.
00001 /*
00002  *    ALMA - Atacama Large Millimiter Array
00003  *    (c) Associated Universities Inc., 2002 
00004  *    (c) European Southern Observatory, 2002
00005  *    Copyright by ESO (in the framework of the ALMA collaboration),
00006  *    All rights reserved
00007  *
00008  *    This library is free software; you can redistribute it and/or
00009  *    modify it under the terms of the GNU Lesser General Public
00010  *    License as published by the Free Software Foundation; either
00011  *    version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *    This library is distributed in the hope that it will be useful,
00014  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *    Lesser General Public License for more details.
00017  *
00018  *    You should have received a copy of the GNU Lesser General Public
00019  *    License along with this library; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00021  *    MA 02111-1307  USA
00022  *
00023  * ncTestCompImpl.java
00024  *
00025  * Created on April 11, 2003, 2:21 PM
00026  */
00027 package alma.demo.EventSupplierImpl;
00028 
00029 import java.util.logging.Level;
00030 
00031 import alma.ACSErrTypeCommon.CouldntPerformActionEx;
00032 import alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx;
00033 import alma.FRIDGE.TemperatureStatus;
00034 import alma.FRIDGE.temperatureDataBlockEvent;
00035 import alma.FRIDGE.FridgeControlPackage.NestedFridgeEvent;
00036 import alma.acs.component.ComponentImplBase;
00037 import alma.acs.component.ComponentLifecycleException;
00038 import alma.acs.container.ContainerServices;
00039 import alma.acs.exceptions.AcsJException;
00040 import alma.acs.nc.SimpleSupplier;
00041 import alma.demo.SupplierCompOperations;
00042 
00043 
00048 public class EventSupplierImpl extends ComponentImplBase implements SupplierCompOperations
00049 {
00050     private SimpleSupplier m_supplier;
00051 
00055     public void initialize(ContainerServices containerServices) throws ComponentLifecycleException
00056     {
00057         super.initialize(containerServices);
00058         SimpleSupplier.EventProcessingCallback<alma.FRIDGE.temperatureDataBlockEvent> callback =
00059                 new EventProcessingCallbackImpl();
00060         try {
00061                 // Instantiate our supplier
00062                 m_supplier = new SimpleSupplier(alma.FRIDGE.CHANNELNAME_FRIDGE.value,  //the channel's name 
00063                                 m_containerServices, callback);
00064         }
00065         catch (Exception e) {
00066                 throw new ComponentLifecycleException("failed to create SimpleSupplier for channel " + alma.FRIDGE.CHANNELNAME_FRIDGE.value, e);
00067         }
00068     }
00069 
00073     public void cleanUp()
00074     {
00075         m_supplier.disconnect();
00076     }
00077     
00078 
00082     public void sendEvents(short param) throws CouldntPerformActionEx
00083     {
00084         m_logger.info("Now sending " + param + " temperatureDataBlockEvent events...");
00085         try {
00086             temperatureDataBlockEvent t_block = new temperatureDataBlockEvent(3.14F, TemperatureStatus.ATREF);
00087             for(short i=0; i<param; i++)
00088             {
00089                 m_supplier.publishEvent(t_block);
00090             }
00091         }
00092         catch(Throwable thr) {
00093             m_logger.log(Level.WARNING, "failed to send temperatureDataBlockEvent. Will not try again.");
00094             throw (new AcsJCouldntPerformActionEx(thr)).toCouldntPerformActionEx();
00095         }
00096     }
00097 
00098     public void sendEventsSpecial(NestedFridgeEvent[] eventData) throws CouldntPerformActionEx {
00099         try {
00100                 m_logger.info("Now sending " + eventData.length + " NestedFridgeEvent events...");
00101             for (NestedFridgeEvent event : eventData) {
00102                 m_supplier.publishEvent(event);
00103                         }
00104         }
00105         catch(Throwable thr) {
00106             m_logger.log(Level.WARNING, "failed to send NestedFridgeEvent. Will not try again.");
00107             throw (new AcsJCouldntPerformActionEx(thr)).toCouldntPerformActionEx();
00108         }
00109     }
00110     
00111         private class EventProcessingCallbackImpl implements 
00112         SimpleSupplier.EventProcessingCallback<alma.FRIDGE.temperatureDataBlockEvent>
00113         {
00114 
00115                 @Override
00116                 public void eventDropped(temperatureDataBlockEvent event) {
00117                         m_logger.log(Level.WARNING, "CALLBACK: Event dropped, trying to send again");
00118                         try {
00119                                 m_supplier.publishEvent(event);
00120                         } catch (AcsJException e) {
00121                                 e.printStackTrace();
00122                         }
00123                 }
00124 
00125                 @Override
00126                 public void eventSent(temperatureDataBlockEvent event) {
00127                         m_logger.log(Level.INFO, "CALLBACK: Event sent successfully");
00128                         
00129                 }
00130 
00131                 @Override
00132                 public void eventStoredInQueue(temperatureDataBlockEvent event) {
00133                         m_logger.log(Level.INFO, "CALLBACK: Notify Service probably is down. Storing the event");
00134                         
00135                 }
00136                 
00137         }
00138 }