From 5088f27792771f1207758ab90c9061eb8774e409 Mon Sep 17 00:00:00 2001 From: Shachar Snapiri Date: Mon, 30 Apr 2018 17:10:10 +0300 Subject: [PATCH] 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 --- dragonflow/db/pub_sub_api.py | 11 +++++++++-- dragonflow/db/pubsub_drivers/etcd_pubsub_driver.py | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dragonflow/db/pub_sub_api.py b/dragonflow/db/pub_sub_api.py index 00ab7e6b5..d7a850ccd 100644 --- a/dragonflow/db/pub_sub_api.py +++ b/dragonflow/db/pub_sub_api.py @@ -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) diff --git a/dragonflow/db/pubsub_drivers/etcd_pubsub_driver.py b/dragonflow/db/pubsub_drivers/etcd_pubsub_driver.py index 5603741d2..3222b340a 100644 --- a/dragonflow/db/pubsub_drivers/etcd_pubsub_driver.py +++ b/dragonflow/db/pubsub_drivers/etcd_pubsub_driver.py @@ -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():