def main(argv): consumers = [] wait_sec = int(argv[0]) for ch in argv[1:]: ch = int(ch) print "Creating channel %d" % (ch) consumer = None if ch == 1: consumer = Consumer(TEST_NS_STATISTICS_SERVICE.CHANNEL_1) consumer.addSubscription(TEST_NS_STATISTICS_SERVICE.Test1EventData,handler_function=dataHandler1) elif ch == 2: consumer = Consumer(TEST_NS_STATISTICS_SERVICE.CHANNEL_2) consumer.addSubscription(TEST_NS_STATISTICS_SERVICE.Test1EventData,handler_function=dataHandler2) elif ch == 3: consumer = Consumer(TEST_NS_STATISTICS_SERVICE.CHANNEL_3) consumer.addSubscription(TEST_NS_STATISTICS_SERVICE.Test1EventData,handler_function=dataHandler3) elif ch == 4: consumer = Consumer(TEST_NS_STATISTICS_SERVICE.CHANNEL_4) consumer.addSubscription(TEST_NS_STATISTICS_SERVICE.Test1EventData,handler_function=dataHandler4) if consumer is None: raise BaseException("Unknown channel. Allowed values are from 1 to 4: %d"%(ch)) else: consumers.append(consumer) print "Enable %d consumers"%(len(consumers)) for consumer in consumers: consumer.consumerReady() if wait_sec > 0: print "Wait %d seconds"%(wait_sec) sleep(wait_sec) # Disconnect consumers print "Disconnect %d consumers"%(len(consumers)) for consumer in consumers: consumer.disconnect()
for code in range(1,numAlarmsToSend+1): # Create a test fault fltstate = Acsalarmpy.AlarmSystemInterfaceFactory.createFaultState(family,member, code) fltstate.descriptor = FaultState.ACTIVE_STRING fltstate.userTimestamp = Timestamp.Timestamp() fltstate.userProperties[FaultState.ASI_PREFIX_PROPERTY_STRING] = "prefix" fltstate.userProperties[FaultState.ASI_SUFFIX_PROPERTY_STRING] = "suffix" fltstate.userProperties["TEST_PROPERTY"] = "TEST_VALUE" alarmSource.push(fltstate) print numAlarmsToSend,"alarms sent" numAlarmsToReceive=numAlarmsToSend timeout=120 now=0 while msgCount < numAlarmsToReceive or now>timeout: sleep(1) now= now +1 if msgCount==numAlarmsToReceive: print "Consumer received %d messages\n" % msgCount else: print "ERROR: consumer received",msgCount,"messages instead of",numAlarmsToReceive Acsalarmpy.AlarmSystemInterfaceFactory.done() sys.stdout.flush() c.disconnect() # # ___oOo___
Parameters: someParam is the real CORBA type extracted from the event. In this case, it will always be a ACSCOURSE_MOUNT.MountEventData. Returns: event handler functions return nothing. Raises: If any exception is thrown by this function, the Consumer class will catch it and call processEvent(...) which will hopefully have been overriden. ''' print "The commanded Az/El received by this consumer are:", someParam.Azimuth, ",", someParam.Elevation return #------------------------------------------------------------------------------ if __name__ == "__main__": #Create a Consumer g = Consumer(ACSCOURSE_MOUNT.MOUNT_CHANNEL) #Subscribe to MountEventData events (see the IDL for a definition) and register #this handler to process those events g.addSubscription(ACSCOURSE_MOUNT.MountEventData, handler_function=mountDataHandler) #Let the Notification Service know we are ready to start processing events. g.consumerReady() #Give suppliers 50 seconds to send events. print "Waiting for events . . ." for i in range(0,50): sleep(1) #cleanly disconnect the consumer g.disconnect() #------------------------------------------------------------------------------
#----------------------------------------------------------------------------- def dataHandler(someParam): ''' ''' global count global g if count < magicNumber: if count == (magicNumber - 1): g.removeSubscription(acsnc.EventDescription) count = count + 1 sleep(1.5) return #----------------------------------------------------------------------------- g = Consumer(str(argv[1])) g.addSubscription(acsnc.EventDescription, dataHandler) g.consumerReady() sleep(int(argv[2])) if count == magicNumber: print "Test passed!" else: print "Test failed!" g.disconnect() #-------------------------------------------------------------------------------
class CounterConsumer( COUNTER__POA.CounterConsumer, #CORBA stubs for IDL interface ACSComponent, #Base IDL interface ContainerServices, #Developer niceties ComponentLifecycle): #HLA stuff ''' Simple component implementation provided as a reference for developers. ''' def __init__(self): ''' Just call superclass constructors here. ''' ACSComponent.__init__(self) ContainerServices.__init__(self) self.eventCount = 0 self.contFlag = True self.LOGGER = getLogger("CounterConsumer") return #------------------------------------------------------------------------------ #--Override ComponentLifecycle methods----------------------------------------- #------------------------------------------------------------------------------ def initialize(self): ''' Override this method inherited from ComponentLifecycle ''' self.LOGGER.logTrace("CounterConsumer.CounterConsumer") #------------------------------------------------------------------------------ def cleanUp(self): ''' Override this method inherited from ComponentLifecycle ''' if self.name == None: self.LOGGER.logInfo("Stopping main ...") else: self.LOGGER.logInfo("Destroying " + self.name + "...") #cleanly disconnect from the channel if self.Consumer != None: self.Consumer.disconnect() self.Consumer = None #------------------------------------------------------------------------------ def counterDataHandler(self, someParam): ''' This function serves only one purpose...it must do something with the extracted data from the structured event. That is, it must be capable of processing filterable_data[0].any in the structured event. We can be certain of the real type of someParam because handlers are registered only for specific types (i.e., the type_name field of a structured event). Parameters: someParam is the real CORBA type extracted from the CORBA Any at filterable_data[0]. In this case, it will always be a COUNTER.temperatureDataBlockEvent. Returns: event handler functions return nothing. Raises: If any exception is thrown by this function, the Consumer class will catch it and call processEvent(...) which will hopefully have been overriden. ''' if self.contFlag: #pattern = someParam.status onOff = someParam.onOff myString = someParam.myString counter1 = someParam.counter1 counter2 = someParam.counter2 counter3 = someParam.counter3 lastFlag = someParam.flipFlop period = someParam.period if (onOff == COUNTER.ON) and (not lastFlag): self.LOGGER.logInfo( 'Counter now %d (max %d), flag will flip at %d' % (counter1, counter2, counter3)) #self.LOGGER.logInfo('bitmask: %x' % pattern) else: self.LOGGER.logInfo(myString + ' received, counter is now ' + str(counter1)) #self.LOGGER.logInfo('bitmask: %x' % pattern) self.contFlag = False self.eventCount = self.eventCount + 1 return #------------------------------------------------------------------------------ #--Implementation of IDL methods----------------------------------------------- #------------------------------------------------------------------------------ def getBlocks(self): #Create a Consumer self.LOGGER.logInfo('Creating an instance of Consumer') self.Consumer = Consumer(COUNTER.CHANNELNAME_COUNTER) #Subscribe to statusBlockEvent events (see nctest_IF.idl) and register #this handler to process those events self.Consumer.addSubscription(COUNTER.statusBlockEvent, self.counterDataHandler) #Let the Notification Service know we are ready to start processing events. #After consumerReady() is invoked, receive(...) is invoked #by the notification channel. That is, we have no control over when #that method is called. self.Consumer.consumerReady() self.LOGGER.logInfo( "CounterConsumer is ready to receive 'status' events.") return def waitTillDone(self): while self.contFlag and (self.Consumer != None): self.LOGGER.logInfo( "CounterConsumer received %d blocks so far ..." % self.eventCount) sleep(1.0) self.LOGGER.logInfo("CounterConsumer received total of %d blocks" % self.eventCount) #cleanly disconnect from the channel if self.Consumer != None: self.Consumer.disconnect() self.Consumer = None return self.eventCount
exit() try: started = 0 ended = 0 # Create a consumer consumer.addSubscription(ExecBlockStartedEvent, handlerStarted) consumer.addSubscription(ExecBlockEndedEvent, handlerEnded) consumer.consumerReady() except ACSErrTypeCommon.UnknownEx, e: simpleClient.getLogger().logCritical("Caught an ACSException....") helperException = ACSErrTypeCommonImpl.UnknownExImpl(exception=e) helperException.Print() helperException.log() # Release it except Exception, e: simpleClient.getLogger().logAlert("Caught an exception") simpleClient.getLogger().logDebug("The exception was:" + str(e)) time.sleep(900) consumer.disconnect() print "Start events received: " + str(started) print "End events received: " + str(ended) simpleClient.disconnect()
ec_cons.addSubscription("temperatureDataBlockEvent", eventHandler) ec_cons.addSubscription("XmlEntityStruct", eventHandler) ec_cons.consumerReady() erc_cons = Consumer("ALMA_EVENT_RESPONSE_CHANNEL") erc_cons.addSubscription("Duration", eventHandler) erc_cons.consumerReady() #create the event dispatcher ed = EventDispatcher(FAKE_MS) #sleep for awhile giving consumers a chance to process a few #events sleep(60) ec_cons.disconnect() erc_cons.disconnect() ed.destroy() if EVENT_COUNTER["IDL:alma/FRIDGE/temperatureDataBlockEvent:1.0"] > 10: print "Good...enough temperatureDataBlockEvent's" else: print "Bad...not enough temperatureDataBlockEvent's" if EVENT_COUNTER["IDL:alma/xmlentity/XmlEntityStruct:1.0"] > 4: print "Good...enough XmlEntityStruct's" else: print "Bad...not enough XmlEntityStruct's" if EVENT_COUNTER["IDL:alma/acstime/Duration:1.0"] > 1 and EVENT_COUNTER["IDL:alma/acstime/Duration:1.0"] < EVENT_COUNTER["IDL:alma/FRIDGE/temperatureDataBlockEvent:1.0"]: print "Good...enough Durations have been received"
def disconnect(self): Consumer.disconnect(self) self.outputfile.flush() if (self.outputFileName != None): self.outputfile.close()
ec_cons.addSubscription("temperatureDataBlockEvent", eventHandler) ec_cons.addSubscription("XmlEntityStruct", eventHandler) ec_cons.consumerReady() erc_cons = Consumer("ALMA_EVENT_RESPONSE_CHANNEL") erc_cons.addSubscription("Duration", eventHandler) erc_cons.consumerReady() #create the event dispatcher ed = EventDispatcher(FAKE_MS) #sleep for awhile giving consumers a chance to process a few #events sleep(60) ec_cons.disconnect() erc_cons.disconnect() ed.destroy() if EVENT_COUNTER["IDL:alma/FRIDGE/temperatureDataBlockEvent:1.0"] > 10: print "Good...enough temperatureDataBlockEvent's" else: print "Bad...not enough temperatureDataBlockEvent's" if EVENT_COUNTER["IDL:alma/xmlentity/XmlEntityStruct:1.0"] > 4: print "Good...enough XmlEntityStruct's" else: print "Bad...not enough XmlEntityStruct's" if EVENT_COUNTER["IDL:alma/acstime/Duration:1.0"] > 1 and EVENT_COUNTER[ "IDL:alma/acstime/Duration:1.0"] < EVENT_COUNTER[
fltstate = Acsalarmpy.AlarmSystemInterfaceFactory.createFaultState( family, member, code) fltstate.descriptor = FaultState.ACTIVE_STRING fltstate.userTimestamp = Timestamp.Timestamp() fltstate.userProperties[ FaultState.ASI_PREFIX_PROPERTY_STRING] = "prefix" fltstate.userProperties[ FaultState.ASI_SUFFIX_PROPERTY_STRING] = "suffix" fltstate.userProperties["TEST_PROPERTY"] = "TEST_VALUE" alarmSource.push(fltstate) print numAlarmsToSend, "alarms sent" numAlarmsToReceive = numAlarmsToSend timeout = 120 now = 0 while msgCount < numAlarmsToReceive or now > timeout: sleep(1) now = now + 1 if msgCount == numAlarmsToReceive: print "Consumer received %d messages\n" % msgCount else: print "ERROR: consumer received", msgCount, "messages instead of", numAlarmsToReceive Acsalarmpy.AlarmSystemInterfaceFactory.done() sys.stdout.flush() c.disconnect() # # ___oOo___
class CounterConsumer(COUNTER__POA.CounterConsumer, #CORBA stubs for IDL interface ACSComponent, #Base IDL interface ContainerServices, #Developer niceties ComponentLifecycle): #HLA stuff ''' Simple component implementation provided as a reference for developers. ''' def __init__(self): ''' Just call superclass constructors here. ''' ACSComponent.__init__(self) ContainerServices.__init__(self) self.eventCount = 0 self.contFlag = True self.LOGGER = getLogger("CounterConsumer") return #------------------------------------------------------------------------------ #--Override ComponentLifecycle methods----------------------------------------- #------------------------------------------------------------------------------ def initialize(self): ''' Override this method inherited from ComponentLifecycle ''' self.LOGGER.logTrace("CounterConsumer.CounterConsumer") #------------------------------------------------------------------------------ def cleanUp(self): ''' Override this method inherited from ComponentLifecycle ''' if self.name == None: self.LOGGER.logInfo("Stopping main ...") else: self.LOGGER.logInfo("Destroying " + self.name + "...") #cleanly disconnect from the channel if self.Consumer != None: self.Consumer.disconnect() self.Consumer = None #------------------------------------------------------------------------------ def counterDataHandler(self,someParam): ''' This function serves only one purpose...it must do something with the extracted data from the structured event. That is, it must be capable of processing filterable_data[0].any in the structured event. We can be certain of the real type of someParam because handlers are registered only for specific types (i.e., the type_name field of a structured event). Parameters: someParam is the real CORBA type extracted from the CORBA Any at filterable_data[0]. In this case, it will always be a COUNTER.temperatureDataBlockEvent. Returns: event handler functions return nothing. Raises: If any exception is thrown by this function, the Consumer class will catch it and call processEvent(...) which will hopefully have been overriden. ''' if self.contFlag: #pattern = someParam.status onOff = someParam.onOff myString = someParam.myString counter1 = someParam.counter1 counter2 = someParam.counter2 counter3 = someParam.counter3 lastFlag = someParam.flipFlop period = someParam.period if (onOff == COUNTER.ON) and (not lastFlag): self.LOGGER.logInfo('Counter now %d (max %d), flag will flip at %d' % (counter1, counter2, counter3)) #self.LOGGER.logInfo('bitmask: %x' % pattern) else: self.LOGGER.logInfo(myString + ' received, counter is now ' + str(counter1)) #self.LOGGER.logInfo('bitmask: %x' % pattern) self.contFlag = False self.eventCount = self.eventCount + 1 return #------------------------------------------------------------------------------ #--Implementation of IDL methods----------------------------------------------- #------------------------------------------------------------------------------ def getBlocks(self): #Create a Consumer self.LOGGER.logInfo('Creating an instance of Consumer') self.Consumer = Consumer(COUNTER.CHANNELNAME_COUNTER) #Subscribe to statusBlockEvent events (see nctest_IF.idl) and register #this handler to process those events self.Consumer.addSubscription(COUNTER.statusBlockEvent, self.counterDataHandler) #Let the Notification Service know we are ready to start processing events. #After consumerReady() is invoked, receive(...) is invoked #by the notification channel. That is, we have no control over when #that method is called. self.Consumer.consumerReady() self.LOGGER.logInfo("CounterConsumer is ready to receive 'status' events.") return def waitTillDone(self): while self.contFlag and (self.Consumer != None): self.LOGGER.logInfo("CounterConsumer received %d blocks so far ..." % self.eventCount) sleep(1.0) self.LOGGER.logInfo("CounterConsumer received total of %d blocks" % self.eventCount) #cleanly disconnect from the channel if self.Consumer != None : self.Consumer.disconnect() self.Consumer = None return self.eventCount
def disconnect(self): Consumer.disconnect(self) self.outputfile.flush() if(self.outputFileName != None): self.outputfile.close()