def __init__(self, numToExpect, outputFileName, waitBetweenEvents=0): ''' Constructor. Params: - handler Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' Consumer.__init__(self, perftest.NOTIFICATION_STRESS_CHANNEL_NAME) self.addSubscription( perftest.NotificationServiceStress.NotificationServiceStressEvent) self.outputFileName = outputFileName if (outputFileName is None): self.outputfile = sys.stdout else: self.outputfile = open(outputFileName, "w") self.consumerReady() if (numToExpect is None): self.numToExpect = 1 else: self.numToExpect = numToExpect self.numReceived = 0 self.waitBetweenEvents = waitBetweenEvents
def __init__(self, channelName): ''' Constructor. Handles absolutely everything. Once the constructor has been called, there is absolutely nothing for the developer to do other than let it run. Parameters: - channelName is the name of the channel to connect to Raises: ??? ''' #this member is the total number of events that have been received for #this particular channel self.count = 0 #a dictionary where event_type's are the keys and the values are the #total number of that type of event received self.typeCount = {} #just call the superclass constructor Consumer.__init__(self, channelName) #subscribe to ALL events. in theory we could just invoke addSubscription("*") #but TAO Notification Service does NOT adhere to the OMG specs in this case. self.consumerAdmin.subscription_change([CosNotification.EventType("*", "*")],[]) #ready to begin processing events self.consumerReady() return
def __init__ (self, numToExpect, outputFileName, waitBetweenEvents=0): ''' Constructor. Params: - handler Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' Consumer.__init__(self, perftest.NOTIFICATION_STRESS_CHANNEL_NAME) self.addSubscription(perftest.NotificationServiceStress.NotificationServiceStressEvent) self.outputFileName = outputFileName if(outputFileName is None): self.outputfile = sys.stdout else: self.outputfile = open(outputFileName, "w") self.consumerReady() if(numToExpect is None): self.numToExpect = 1 else: self.numToExpect = numToExpect self.numReceived = 0 self.waitBetweenEvents=waitBetweenEvents
def __init__(self, channel_name): ''' Constructor. Parameters: channel_name Channel name. ''' Consumer.__init__(self, channel_name, None) self.channel_name = channel_name self.rec_file_name = self.channel_name + '.xml' self.rec_file = None self.start_time = -1
def __init__ (self, handler): ''' Constructor. Params: - handler Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' self.handler = handler Consumer.__init__(self, acscommon.ARCHIVING_CHANNEL_NAME)
def __init__(self, handler): ''' Constructor. Params: - handler Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' self.handler = handler Consumer.__init__(self, acscommon.ARCHIVING_CHANNEL_NAME, None, acscommon.ACS_NC_DOMAIN_ARCHIVING)
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 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
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
''' 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)
def disconnect(self): Consumer.disconnect(self) self.outputfile.flush() if (self.outputFileName != None): self.outputfile.close()
''' 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)
def handlerEnded(event): global ended ended += 1 print event.execId print event.sbId print event.sessionId print event.arrayName print event.status print event.errorTrace print event.endTime 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:
#--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() #------------------------------------------------------------------------------
def responseHelper(self, incoming_channel_name, incoming_ifr_id, outgoing_channel_name, outgoing_ifr_id, delay, missed_event_chance, event_instance): ''' A fairly complex helper method which: - adds a subscription to a consumer for the incoming_ifr_id event type - whenever an event is received by the consumer, an event of outgoing_ifr_id type is PROBABLY published on the outgoing_channel_name channel after 'delay' seconds - there's a chance the event will not be published at all if 'missed_event_chance' is close to 1.0. ''' #sanity check to ensure a consumer is around if not self.consumers.has_key(incoming_channel_name): #add a consumer consumer = Consumer(incoming_channel_name) consumer.consumerReady() self.consumers[incoming_channel_name] = consumer #consumer cons = self.consumers[incoming_channel_name] #define the event handler method def eventHandler(data): ''' This event handler method: - checks the probability to ensure an event should actually be published. - pauses for a set amount of time - sends another event presumably of a different type ''' #first check the probability to see if we can #ignore the call entirely ran_float = (randrange(0, 100)) / 100.0 if ran_float > missed_event_chance: #bail self.logger.logDebug("Randomly skipped an event: " + str(ran_float)) return self.logger.logDebug( "Publishing a '" + outgoing_ifr_id + "' event on the '" + outgoing_channel_name + "' in response to receiving an event of type'" + incoming_ifr_id + "' on the '" + incoming_channel_name) #first we sleep sleep(delay) #send an event in response... if event_instance == None: supplyEventByType(self.comp_name, outgoing_channel_name, outgoing_ifr_id) else: supplyEventByInstance(self.comp_name, outgoing_channel_name, event_instance) return #ends the function definition #add the subscription; first getting at the event type event_type = incoming_ifr_id.split(":")[1].split('/').pop() #now add the subscription with the function we just defined cons.addSubscription(event_type, eventHandler)
data from the structured event. 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 responseHelper(self, incoming_channel_name, incoming_ifr_id, outgoing_channel_name, outgoing_ifr_id, delay, missed_event_chance, event_instance): ''' A fairly complex helper method which: - adds a subscription to a consumer for the incoming_ifr_id event type - whenever an event is received by the consumer, an event of outgoing_ifr_id type is PROBABLY published on the outgoing_channel_name channel after 'delay' seconds - there's a chance the event will not be published at all if 'missed_event_chance' is close to 1.0. ''' #sanity check to ensure a consumer is around if not self.consumers.has_key(incoming_channel_name): #add a consumer consumer = Consumer(incoming_channel_name) consumer.consumerReady() self.consumers[incoming_channel_name] = consumer #consumer cons = self.consumers[incoming_channel_name] #define the event handler method def eventHandler(data): ''' This event handler method: - checks the probability to ensure an event should actually be published. - pauses for a set amount of time - sends another event presumably of a different type ''' #first check the probability to see if we can #ignore the call entirely ran_float = (randrange(0,100))/100.0 if ran_float > missed_event_chance: #bail self.logger.logDebug("Randomly skipped an event: " + str(ran_float)) return self.logger.logDebug("Publishing a '" + outgoing_ifr_id + "' event on the '" + outgoing_channel_name + "' in response to receiving an event of type'" + incoming_ifr_id + "' on the '" + incoming_channel_name) #first we sleep sleep(delay) #send an event in response... if event_instance==None: supplyEventByType(self.comp_name, outgoing_channel_name, outgoing_ifr_id) else: supplyEventByInstance(self.comp_name, outgoing_channel_name, event_instance) return #ends the function definition #add the subscription; first getting at the event type event_type = incoming_ifr_id.split(":")[1].split('/').pop() #now add the subscription with the function we just defined cons.addSubscription(event_type, eventHandler)
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
#!/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()
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
#!/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()
#!/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)
def disconnect(self): Consumer.disconnect(self) self.outputfile.flush() if(self.outputFileName != None): self.outputfile.close()
#!/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()
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")
count = count + 1 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()
#!/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()
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()
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()
#----------------------------------------------------------------------------- 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() #-------------------------------------------------------------------------------
LOGGER.logInfo('The temperature difference is ' + str(someParam.absoluteDiff)) return #------------------------------------------------------------------------------ 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()
if pos !=-1: 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):
period = someParam.period 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()