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()
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() #------------------------------------------------------------------------------
Consumer event handler ''' ifr_id = event._NP_RepositoryId #sanity check if not EVENT_COUNTER.has_key(ifr_id): EVENT_COUNTER[ifr_id] = 0 #increment EVENT_COUNTER[ifr_id] = EVENT_COUNTER[ifr_id] + 1 if __name__=="__main__": ec_cons = Consumer("ALMA_EVENT_CHANNEL") 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()
Consumer event handler ''' ifr_id = event._NP_RepositoryId #sanity check if not EVENT_COUNTER.has_key(ifr_id): EVENT_COUNTER[ifr_id] = 0 #increment EVENT_COUNTER[ifr_id] = EVENT_COUNTER[ifr_id] + 1 if __name__ == "__main__": ec_cons = Consumer("ALMA_EVENT_CHANNEL") 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()
triplet = triplet[:pos + 1] print "Triplet received", triplet.strip() sys.stdout.flush() msgCount += 1 return if len(sys.argv) < 2: print "\n\nUsage: \n\nTestAcsAlarmSending <NUM_ALARMS_TO_SEND>\n\nwhere NUM_ALARMS_TO_SEND is how many alarms you wish to send.\n\n" else: numAlarmsToSend = int(sys.argv[1]) c = Consumer("CMW.ALARM_SYSTEM.ALARMS.SOURCES.ALARM_SYSTEM_SOURCES", None, ACS_NC_DOMAIN_ALARMSYSTEM) c.addSubscription( ACSJMSMessageEntity_idl._0_com.cosylab.acs.jms.ACSJMSMessageEntity, alarmDataHandler) c.consumerReady() # Test data for our fault family = 'Mount' member = 'ALARM_SOURCE_MOUNT' print "Testing long-hand style of sending alarms" Acsalarmpy.AlarmSystemInterfaceFactory.init() alarmSource = Acsalarmpy.AlarmSystemInterfaceFactory.createSource( "ALARM_SYSTEM_SOURCES") # The heart of the test
#!/usr/bin/env python import time from Acspy.Nc.Consumer import Consumer import com.cosylab.acs.jms from xml.dom import minidom def testDataHandler(param): xml = str(param.text) parse = minidom.parseString(xml) fault_state = parse.getElementsByTagName('fault-state') family = str(fault_state[0].getAttribute('family')) member = str(fault_state[0].getAttribute('member')) code = str(fault_state[0].getAttribute('code')) print family+','+member+','+code if __name__ == "__main__": c=Consumer("CMW.ALARM_SYSTEM.ALARMS.SOURCES.ALARM_SYSTEM_SOURCES") c.addSubscription(com.cosylab.acs.jms.ACSJMSMessageEntity, testDataHandler) c.consumerReady() time.sleep(1000)
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() #------------------------------------------------------------------------------
'Last event from supplier received, counter is now ' + str(counter1)) contFlag = False count = count + 1 return #------------------------------------------------------------------------------ if __name__ == "__main__": #Create a contNcTestCounterConsumer LOGGER.logInfo('Creating contNcTestCounterConsumer') g = Consumer(COUNTER.CHANNELNAME_COUNTER) #Subscribe to statusBlockEvent events (see contNcTest_IF.idl) and register #this handler to process those events g.addSubscription(COUNTER.statusBlockEvent, counterDataHandler) #Let the Notification Service know we are ready to start processing events. g.consumerReady() #After five events have been received, disconnect from the channel LOGGER.logInfo("Waiting for events . . .") while (contFlag): sleep(0.5) LOGGER.logInfo("Events all done (%d) . . . exiting" % count) g.disconnect() #------------------------------------------------------------------------------
if count < 5: for data in someParam: print "TIME STAMP: ", data.sampTime print "VALUE: ", data.sampVal.value() print "Received: ", count return #------------------------------------------------------------------------------ if __name__ == "__main__": client = PySimpleClient() samp = client.getComponent(argv[1]) sampObj = samp.initSampObj("LAMP1", "brightness", 1000000, 10000000) print "acssampConsumer entering ..." g = Consumer("NC_LAMP1_brightness_1000000_10000000") g.addSubscription("SampDataBlockSeq", handlerFunction=dataHandler) g.consumerReady() sampObj.start() print " ACS sampling started" sleep(5) sampObj.suspend() print "ACS sampling suspended" sleep(5) sampObj.resume() print "ACS sampling resumed" sleep(6) sampObj.stop() print "ACS sampling stopped"
#!/usr/bin/env python from time import sleep from sys import argv from Acspy.Clients.SimpleClient import PySimpleClient from Acspy.Nc.Consumer import Consumer import acsnc def dataHandler(someParam): print "----------------------------" print someParam.name print someParam.timestamp print "----------------------------" return #------------------------------------------------------------------------------ if __name__ == "__main__": g = Consumer("BD_ERR_PROP") g.addSubscription(acsnc.EventDescription, handler_function=dataHandler) g.consumerReady() #After five events have been received, disconnect from the channel print "Waiting for events . . ." doit = True while(doit): try: sleep(0.1) except KeyboardInterrupt: doit = False g.disconnect()
magicNumber = int(argv[3]) g = None #----------------------------------------------------------------------------- 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() #-------------------------------------------------------------------------------
#--GLOBALS--------------------------------------------------------------------- sup = Supplier("perf channel") count = 0 magicNumber = long(argv[1]) #------------------------------------------------------------------------------ def eventHandler(someParam): ''' ''' global count count = count + 1 return #------------------------------------------------------------------------------ if __name__ == "__main__": print 'Creating Consumer' g = Consumer("perf channel") g.addSubscription(perftest.charSeqStruct, handler_function=eventHandler) g.consumerReady() #After five events have been received, disconnect from the channel print "Waiting for events . . ." while(count<magicNumber): sleep(1) print "Events all done . . . exiting" g.disconnect() sup.disconnect() #------------------------------------------------------------------------------
#!/usr/bin/env python #import CORBA Stubs import TEST from Acspy.Nc.Consumer import Consumer import time #define a handler function, maybe you want to write in a file :P def testDataHandler(param): print param.Log return if __name__ == "__main__": g = Consumer(TEST.TEST_CHANNELNAME) #register the data type and the function to handle the events g.addSubscription(TEST.TestLog, testDataHandler) g.consumerReady() #wait enough time to receive all the logs time.sleep(70) g.disconnect()
#!/usr/bin/env python from time import sleep from sys import argv from Acspy.Clients.SimpleClient import PySimpleClient from Acspy.Nc.Consumer import Consumer def dataHandler(someParam): print "<-" return #------------------------------------------------------------------------------ if __name__ == "__main__": g = Consumer("CONTROL_SYSTEM") g.addSubscription("ExecBlockStartedEvent", handlerFunction=dataHandler) g.consumerReady() #After five events have been received, disconnect from the channel print "Waiting for events . . ." # while(count<5): # sleep(1) 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
return try: consumer = Consumer(CHANNELNAME_CONTROLSYSTEM) except Exception, e: print str(e) 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)
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
if __name__ == "__main__": print 'Making sure there is a fridge available...' #Start publishing events through a C++ Supplier simpleClient = PySimpleClient() aFridge = simpleClient.getComponent("FRIDGE1") aFridge.on() #Create a FridgeConsumer simpleClient.getLogger().logInfo('Creating FridgeConsumer') g = Consumer(FRIDGE.CHANNELNAME_FRIDGE) #Subscribe to temperatureDataBlockEvent events and register this handler to process #those events g.addSubscription(FRIDGE.temperatureDataBlockEvent, fridgeDataHandler) #Let the Notification Service know we are ready to start processing events. g.consumerReady() #After five events have been received, disconnect from the channel simpleClient.getLogger().logInfo("Waiting for events . . .") while(count<5): sleep(1) simpleClient.getLogger().logInfo("Events all done . . . exiting") g.disconnect() #Turn the C++ Fridge device off. aFridge.off()
#----------------------------------------------------------------------------- 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() #-------------------------------------------------------------------------------
if (onOff == COUNTER.ON) and (not lastFlag): LOGGER.logInfo('Counter now %d (max %d), flag will flip at %d' % (counter1, counter2, counter3)) else: LOGGER.logInfo('Last event from supplier received, counter is now ' + str(counter1)) contFlag = False count = count + 1 return #------------------------------------------------------------------------------ if __name__ == "__main__": #Create a contNcTestCounterConsumer LOGGER.logInfo('Creating contNcTestCounterConsumer') g = Consumer(COUNTER.CHANNELNAME_COUNTER) #Subscribe to statusBlockEvent events (see contNcTest_IF.idl) and register #this handler to process those events g.addSubscription(COUNTER.statusBlockEvent, counterDataHandler) #Let the Notification Service know we are ready to start processing events. g.consumerReady() #After five events have been received, disconnect from the channel LOGGER.logInfo("Waiting for events . . .") while(contFlag): sleep(0.5) LOGGER.logInfo("Events all done (%d) . . . exiting" % count) g.disconnect() #------------------------------------------------------------------------------
triplet= some_param.text[pos:] pos = triplet.find(">") if pos!=-1: triplet = triplet[:pos+1] print "Triplet received",triplet.strip() sys.stdout.flush() msgCount += 1 return if len(sys.argv) < 2: print "\n\nUsage: \n\nTestAcsAlarmSending <NUM_ALARMS_TO_SEND>\n\nwhere NUM_ALARMS_TO_SEND is how many alarms you wish to send.\n\n" else: numAlarmsToSend = int(sys.argv[1]) c = Consumer("CMW.ALARM_SYSTEM.ALARMS.SOURCES.ALARM_SYSTEM_SOURCES",None,ACS_NC_DOMAIN_ALARMSYSTEM) c.addSubscription(ACSJMSMessageEntity_idl._0_com.cosylab.acs.jms.ACSJMSMessageEntity, alarmDataHandler) c.consumerReady() # Test data for our fault family = 'Mount' member = 'ALARM_SOURCE_MOUNT' print "Testing long-hand style of sending alarms" Acsalarmpy.AlarmSystemInterfaceFactory.init() alarmSource = Acsalarmpy.AlarmSystemInterfaceFactory.createSource("ALARM_SYSTEM_SOURCES") # The heart of the test for code in range(1,numAlarmsToSend+1): # Create a test fault
#!/usr/bin/env python from time import sleep from sys import argv from Acspy.Clients.SimpleClient import PySimpleClient from Acspy.Nc.Consumer import Consumer import bulkdata def dataHandler(someParam): print "----------------------------" print someParam.flow print someParam.status print someParam.timestamp print "----------------------------" return #------------------------------------------------------------------------------ if __name__ == "__main__": g = Consumer(bulkdata.CHANNELNAME_ERR_PROP) g.addSubscription(bulkdata.errorStatusBlock, handler_function=dataHandler) g.consumerReady() #After five events have been received, disconnect from the channel print "Waiting for events . . ." doit = True while(doit): try: sleep(0.1) except KeyboardInterrupt: doit = False g.disconnect()