Add is_running property to the subscriber api in pubsub
This is to allow checking if the subscriber is already running and not call initialize in that case. Change-Id: I93583bbd38886032cdd30c6e93651d9e06f24624
This commit is contained in:
parent
c051a44b88
commit
5088f27792
|
@ -191,6 +191,11 @@ class SubscriberApi(object):
|
|||
"""Start the Subscriber thread
|
||||
"""
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def is_running(self):
|
||||
"""Returns True if the subscriber is running, False otherwise"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def close(self):
|
||||
"""Close the subscriber. Release all used resources"""
|
||||
|
@ -217,6 +222,8 @@ class SubscriberAgentBase(SubscriberApi):
|
|||
|
||||
def __init__(self):
|
||||
super(SubscriberAgentBase, self).__init__()
|
||||
self.db_changes_callback = None
|
||||
self.daemon = None
|
||||
self.topic_list = []
|
||||
self.uri_list = []
|
||||
|
||||
|
@ -238,8 +245,8 @@ class SubscriberAgentBase(SubscriberApi):
|
|||
self.daemon.start()
|
||||
|
||||
@property
|
||||
def is_daemonize(self):
|
||||
return self.daemon.is_alive()
|
||||
def is_running(self):
|
||||
return self.daemon and self.daemon.is_alive()
|
||||
|
||||
def register_topic(self, topic):
|
||||
LOG.info('Register topic %s', topic)
|
||||
|
|
|
@ -110,6 +110,11 @@ class EtcdSubscriberAgent(pub_sub_api.SubscriberApi):
|
|||
for topic in self.topic_dict:
|
||||
self.topic_dict[topic].start()
|
||||
|
||||
@property
|
||||
def is_running(self):
|
||||
"""Returns True if the subscriber is running, False otherwise"""
|
||||
return self.running
|
||||
|
||||
def close(self):
|
||||
self.running = False
|
||||
for topic, thread in self.topic_dict.items():
|
||||
|
|
Loading…
Reference in New Issue