From 88859adc0c87a2261d39343daab2290dd6b3eb0e Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 30 May 2007 22:11:24 +0000 Subject: added listener support to queues, also added support for non version specific tests git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@542955 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/queue.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'python/qpid/queue.py') diff --git a/python/qpid/queue.py b/python/qpid/queue.py index 5438b328ab..af0565b6cc 100644 --- a/python/qpid/queue.py +++ b/python/qpid/queue.py @@ -31,15 +31,29 @@ class Queue(BaseQueue): END = object() + def __init__(self, *args, **kwargs): + BaseQueue.__init__(self, *args, **kwargs) + self._real_put = self.put + self.listener = self._real_put + def close(self): self.put(Queue.END) def get(self, block = True, timeout = None): - result = BaseQueue.get(self, block, timeout) - if result == Queue.END: - # this guarantees that any other waiting threads or any future - # calls to get will also result in a Closed exception - self.put(Queue.END) - raise Closed() - else: - return result + self.put = self._real_put + try: + result = BaseQueue.get(self, block, timeout) + if result == Queue.END: + # this guarantees that any other waiting threads or any future + # calls to get will also result in a Closed exception + self.put(Queue.END) + raise Closed() + else: + return result + finally: + self.put = self.listener + pass + + def listen(self, listener): + self.listener = listener + self.put = self.listener -- cgit v1.2.1