summaryrefslogtreecommitdiffstats
path: root/src/python/openlmi/common/IndicationManager.py
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2013-05-16 09:23:31 +0200
committerJan Safranek <jsafrane@redhat.com>2013-05-16 09:23:31 +0200
commit04bf9226c8cc2b00dee4bb07d4f7d4a1c04428d6 (patch)
tree620eed4fc8442e1264656ca047bb6ce07e6fb624 /src/python/openlmi/common/IndicationManager.py
parent0d2ff2523333f4b93154a46d70e1c8143ac789e7 (diff)
downloadopenlmi-providers-04bf9226c8cc2b00dee4bb07d4f7d4a1c04428d6.tar.gz
openlmi-providers-04bf9226c8cc2b00dee4bb07d4f7d4a1c04428d6.tar.xz
openlmi-providers-04bf9226c8cc2b00dee4bb07d4f7d4a1c04428d6.zip
Add method to stop the running thread to all Managers.
We should cleanly shut down all threads when the provider is unloaded, just to be nice to CIMOMs.
Diffstat (limited to 'src/python/openlmi/common/IndicationManager.py')
-rw-r--r--src/python/openlmi/common/IndicationManager.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/python/openlmi/common/IndicationManager.py b/src/python/openlmi/common/IndicationManager.py
index a17703f..f9a1655 100644
--- a/src/python/openlmi/common/IndicationManager.py
+++ b/src/python/openlmi/common/IndicationManager.py
@@ -253,6 +253,8 @@ class IndicationManager(singletonmixin.Singleton):
"""
SEVERITY_INFO = pywbem.Uint16(2) # CIM_Indication.PerceivedSeverity
+ COMMAND_STOP = 1 # Command to the IndicationManager thread to stop.
+
@cmpi_logging.trace_method
def __init__(self, env, nameprefix, namespace, ns_interop=None,
queue=None):
@@ -295,7 +297,7 @@ class IndicationManager(singletonmixin.Singleton):
new_broker = ch.PrepareAttachThread()
self._indication_sender = threading.Thread(
target=self._send_indications_loop, args=(new_broker,))
- self._indication_sender.daemon = True
+ self._indication_sender.daemon = False
self._indication_sender.start()
@property
@@ -714,7 +716,7 @@ class IndicationManager(singletonmixin.Singleton):
:param fltr_id: (``string``) ID of the filter to check.
"""
with self._access_lock:
- return ( class_name in self._filters
+ return (class_name in self._filters
and fltr_id in self._filters[class_name])
def _send_indications_loop(self, broker):
@@ -726,9 +728,31 @@ class IndicationManager(singletonmixin.Singleton):
"""
broker.AttachThread()
while True:
- indication = self._queue.get()
- cmpi_logging.logger.trace_info("Delivering indication %s" %
- (str(indication.path)))
- broker.DeliverIndication(self.namespace, indication)
+ command = self._queue.get()
+
+ if isinstance(command, pywbem.CIMInstance) :
+ indication = command
+ cmpi_logging.logger.trace_info("Delivering indication %s" %
+ (str(indication.path)))
+ broker.DeliverIndication(self.namespace, indication)
+
+ elif isinstance(command, int):
+ cmpi_logging.logger.trace_info("Received command %d", command)
+ if command == self.COMMAND_STOP:
+ if hasattr(self._queue, "task_done"):
+ self._queue.task_done()
+ break
+
if hasattr(self._queue, "task_done"):
self._queue.task_done()
+
+ cmpi_logging.logger.info("Stopped Indication thread.")
+
+ @cmpi_logging.trace_method
+ def shutdown(self):
+ """
+ Stop the thread. This method blocks until the thread is safely
+ destroyed.
+ """
+ self._queue.put(self.COMMAND_STOP)
+ self._indication_sender.join()