def __init__ (self, channelname, component=None, domain=None): ''' Constructor. Params: - channelName is the channel name - component is the component this supplier has been instantiated from (if applicable). This parameter is likely to become mandatory in future version of ACS - domain is the name of the domain of notification channels the channel belongs to Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' #Logger for this supplier self.logger = getLogger(str(channelname) + "-Supplier") #Call the super's constructor CommonNC.__init__(self, channelname, component, domain) #CORBA ref to the channels supplier admin self.supplierAdmin = None #CORBA ref to this suppliers structured proxy push consumer self.sppc = None #number of events sent so far self.count = 0 #Handle all of the CORBA stuff now CommonNC.initCORBA(self) self.initCORBA()
def __init__(self, channelname, component=None, domain=None): ''' Constructor. Params: - channelName is the channel name - component is the component this supplier has been instantiated from (if applicable). This parameter is likely to become mandatory in future version of ACS - domain is the name of the domain of notification channels the channel belongs to Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' #Logger for this supplier self.logger = getLogger(str(channelname) + "-Supplier") #Call the super's constructor CommonNC.__init__(self, channelname, component, domain) #CORBA ref to the channels supplier admin self.supplierAdmin = None #CORBA ref to this suppliers structured proxy push consumer self.sppc = None #number of events sent so far self.count = 0 #Handle all of the CORBA stuff now CommonNC.initCORBA(self) self.initCORBA()
def __init__ (self, name, component=None, domain=None): ''' Constructor. Params: - name is the channel name in string format - component is the component this supplier has been instantiated from (if applicable). This parameter is likely to become mandatory in future version of ACS - domain is the name of the domain of notification channels the channel belongs to Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' self.logger = getLogger(str(name) + "-Consumer") #Call the super's constructor CommonNC.__init__(self, name, component, domain) #CORBA ref to the channels consumer admin self.consumerAdmin = None #CORBA ref to this consumers structured proxy push supplier self.spps = None #Dictionary containing handler functions for different object types self.handlers = {} #dictionary mapping events to the total amount of time they have #to finish self.handlerTimeoutDict = getEventHandlerTimeoutDict(name) #profiler to time how long it takes events to be processed self.profiler = Profiler() #Is the consumer suspended? self.suspended = False #Lock used to read & write suspended attribute self.lockAction = threading.Lock() #Handle all of the CORBA stuff now CommonNC.initCORBA(self) self.initCORBA() self.__buffer_max_size = 100 self.__buffer = Queue.Queue(self.__buffer_max_size); self.__stop_thread = False self.__thread = Thread(target=self.__process_event) self.__thread.setDaemon(True) self.__thread.start()
def reinitConnection(self): ''' Consumer reinitializes the connection to the Channel. Parameters: None Returns: Nothing Raises: ACSErrTypeCommonImpl.CORBAProblemExImpl on critical failures ''' oldChannelTimestamp = self.channelTimestamp try: CommonNC.initCORBA(self) self.initCORBA() self.spps.connect_structured_push_consumer(self._this()) except: self.channelTimestamp = oldChannelTimestamp raise self.logger.logInfo("Consumer reconnected to the channel '%s'"%(self.channelName))
def publishEvent (self, simple_data=None, event_callback=None, type_name=None, event_name="", se=None, supplier_name=None): ''' publishEvent is the one method developers have to use. publishEvent() is designed so Supplier does not have to be subclassed. Params: - simple_data is a user-defined IDL struct. If this parameter is not specified by the developer, se MUST be used. 99% of the time developers should specify the simple_data parameter and NOTHING ELSE! - event_callback is a reference to the user implemented eventProcessCallback the user must implements: eventSent(self, simple_data), eventDropped(self, simple_data) and eventStoredInQueue(self, simple_data) methods. - type_name is literally the type_name field of a structured event. This is an optional parameter and should not be specified under normal circumstances. If unspecified, the name of the simple_data object is used. - event_name is the event_name field of the structured event. Not really useful. - se is a fully-defined structured event. If this parameter is specified, all other parameters will be completely ignored. A check is made to ensure that this object is really what it claims to be. This parameter is reserved for ACS internal usage. - suppier_name is the name of the supplier publishing the event. This parameter is reserved for ACS internal usage. Returns: Nothing Raises: - ACSErrTypeCommonImpl.CORBAProblemExImpl - ACSErrTypeCommonImpl.CouldntPerformActionExImpl - ACSErrTypeCommonImpl.TypeNotSupportedExImpl ''' #Whoah, user passed in the entire structured event...I'm impressed. if se != None: #check to make sure it's a structured event first. if isinstance(se, CosNotification.StructuredEvent): #publish it try: self.sppc.push_structured_event(se) return except CORBA.OBJECT_NOT_EXIST, e: if self.autoreconnect: # Recreate the channel CommonNC.initCORBA(self) self.initCORBA() raise CORBAProblemExImpl(nvSeq=[NameValue("channelname", self.channelName), NameValue("exception", str(e))]) except Exception, e: print_exc() raise CORBAProblemExImpl(nvSeq=[NameValue("channelname", self.channelName), NameValue("exception", str(e))])
self.logger.logNotice("Publisher:" + comp_name + ", Event Type:" + type_name) self.count = self.count + 1 except (CORBA.COMM_FAILURE, CORBA.TRANSIENT): #Notify Service is down if event_callback != None: event_callback.eventDropped(simple_data) except (CORBA.OBJECT_NOT_EXIST, CORBA.BAD_OPERATION) as e: #Notify Service is down if self.autoreconnect: # Recreate the channel channel_recreated = False try: CommonNC.initCORBA(self) self.initCORBA() channel_recreated = True except Exception, e: channel_recreated = False if channel_recreated: # Try to publish again the event try: self.sppc.push_structured_event(se) if event_callback != None: event_callback.eventSent(simple_data) # Event cannot be sent except Exception, e: if event_callback != None: event_callback.eventDropped(simple_data)
def publishEvent(self, simple_data=None, event_callback=None, type_name=None, event_name="", se=None, supplier_name=None): ''' publishEvent is the one method developers have to use. publishEvent() is designed so Supplier does not have to be subclassed. Params: - simple_data is a user-defined IDL struct. If this parameter is not specified by the developer, se MUST be used. 99% of the time developers should specify the simple_data parameter and NOTHING ELSE! - event_callback is a reference to the user implemented eventProcessCallback the user must implements: eventSent(self, simple_data), eventDropped(self, simple_data) and eventStoredInQueue(self, simple_data) methods. - type_name is literally the type_name field of a structured event. This is an optional parameter and should not be specified under normal circumstances. If unspecified, the name of the simple_data object is used. - event_name is the event_name field of the structured event. Not really useful. - se is a fully-defined structured event. If this parameter is specified, all other parameters will be completely ignored. A check is made to ensure that this object is really what it claims to be. This parameter is reserved for ACS internal usage. - suppier_name is the name of the supplier publishing the event. This parameter is reserved for ACS internal usage. Returns: Nothing Raises: - ACSErrTypeCommonImpl.CORBAProblemExImpl - ACSErrTypeCommonImpl.CouldntPerformActionExImpl - ACSErrTypeCommonImpl.TypeNotSupportedExImpl ''' #Whoah, user passed in the entire structured event...I'm impressed. if se != None: #check to make sure it's a structured event first. if isinstance(se, CosNotification.StructuredEvent): #publish it try: self.sppc.push_structured_event(se) return except CORBA.OBJECT_NOT_EXIST, e: if self.autoreconnect: # Recreate the channel CommonNC.initCORBA(self) self.initCORBA() raise CORBAProblemExImpl(nvSeq=[ NameValue("channelname", self.channelName), NameValue("exception", str(e)) ]) except Exception, e: print_exc() raise CORBAProblemExImpl(nvSeq=[ NameValue("channelname", self.channelName), NameValue("exception", str(e)) ])