You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2015/02/02 16:52:16 UTC

qpid-proton git commit: PROTON-812: added exceptions to convey link detach and connection close conditions to users of synchronous utilities

Repository: qpid-proton
Updated Branches:
  refs/heads/master cdd154297 -> 213e463c0


PROTON-812: added exceptions to convey link detach and connection close conditions to users of synchronous utilities


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/213e463c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/213e463c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/213e463c

Branch: refs/heads/master
Commit: 213e463c0589bdf08dff10c46bf2ce8440000c8d
Parents: cdd1542
Author: Gordon Sim <gs...@redhat.com>
Authored: Mon Feb 2 15:53:16 2015 +0000
Committer: Gordon Sim <gs...@redhat.com>
Committed: Mon Feb 2 15:53:16 2015 +0000

----------------------------------------------------------------------
 proton-c/bindings/python/proton/utils.py | 52 ++++++++++++++++++---------
 1 file changed, 35 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/213e463c/proton-c/bindings/python/proton/utils.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/utils.py b/proton-c/bindings/python/proton/utils.py
index 9349bb9..63ac6be 100644
--- a/proton-c/bindings/python/proton/utils.py
+++ b/proton-c/bindings/python/proton/utils.py
@@ -80,8 +80,10 @@ class Fetcher(MessagingHandler):
         self.incoming.append((event.message, event.delivery))
 
     def on_link_error(self, event):
-        # This will be handled by BlockingConnection
-        pass
+        raise LinkDetached(event.link)
+
+    def on_connection_error(self, event):
+        raise ConnectionClosed(event.connection)
 
     @property
     def has_message(self):
@@ -135,6 +137,35 @@ class BlockingReceiver(BlockingLink):
         self.fetcher.settle(state)
 
 
+class LinkDetached(LinkException):
+    def __init__(self, link):
+        self.link = link
+        if link.is_sender:
+            txt = "sender %s to %s closed" % (link.name, link.target.address)
+        else:
+            txt = "receiver %s from %s closed" % (link.name, link.source.address)
+        if link.remote_condition:
+            txt += " due to: %s" % link.remote_condition
+            self.condition = link.remote_condition.name
+        else:
+            txt += " by peer"
+            self.condition = None
+        super(LinkDetached, self).__init__(txt)
+
+
+class ConnectionClosed(ConnectionException):
+    def __init__(self, connection):
+        self.connection = connection
+        txt = "Connection %s closed" % self.url
+        if event.connection.remote_condition:
+            txt += " due to: %s" % event.connection.remote_condition
+            self.condition = connection.remote_condition.name
+        else:
+            txt += " by peer"
+            self.condition = None
+        super(ConnectionClosed, self).__init__(txt)
+
+
 class BlockingConnection(Handler):
     """
     A synchronous style connection wrapper.
@@ -188,25 +219,12 @@ class BlockingConnection(Handler):
     def on_link_remote_close(self, event):
         if event.link.state & Endpoint.LOCAL_ACTIVE:
             event.link.close()
-            if event.link.is_sender:
-                txt = "sender %s to %s closed" % (event.link.name, event.link.target.address)
-            else:
-                txt = "receiver %s from %s closed" % (event.link.name, event.link.source.address)
-            if event.link.remote_condition:
-                txt += " due to: %s" % event.link.remote_condition
-            else:
-                txt += " by peer"
-            raise LinkException(txt)
+            raise LinkDetached(event.link)
 
     def on_connection_remote_close(self, event):
         if event.connection.state & Endpoint.LOCAL_ACTIVE:
             event.connection.close()
-            txt = "Connection %s closed" % self.url
-            if event.connection.remote_condition:
-                txt += " due to: %s" % event.connection.remote_condition
-            else:
-                txt += " by peer"
-            raise ConnectionException(txt)
+            raise ConnectionClosed(event.connection)
 
     def on_disconnected(self, event):
         raise ConnectionException("Connection %s disconnected" % self.url);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org