qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/2] qpid-proton git commit: NO-JIRA: small enhancements to Container, MessagingHandler and examples
Date Fri, 06 Mar 2015 20:58:04 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 304f6dfda -> 5df0bbc2d


NO-JIRA: small enhancements to Container, MessagingHandler and examples

* made controlling distribution mode a little simpler
* added queue browsing example
* don't deliver messages after receiver has been closed, release them instead


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

Branch: refs/heads/master
Commit: aebacd07bcb246a4f122450353a2661813db41fb
Parents: 304f6df
Author: Gordon Sim <gsim@redhat.com>
Authored: Fri Mar 6 17:00:16 2015 +0000
Committer: Gordon Sim <gsim@redhat.com>
Committed: Fri Mar 6 17:03:29 2015 +0000

----------------------------------------------------------------------
 examples/python/queue_browser.py            | 42 ++++++++++++++++++++++++
 examples/python/simple_recv.py              |  1 +
 proton-c/bindings/python/proton/handlers.py | 26 +++++++++++----
 proton-c/bindings/python/proton/reactor.py  |  8 +++++
 4 files changed, 71 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aebacd07/examples/python/queue_browser.py
----------------------------------------------------------------------
diff --git a/examples/python/queue_browser.py b/examples/python/queue_browser.py
new file mode 100755
index 0000000..ad4d393
--- /dev/null
+++ b/examples/python/queue_browser.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from proton.reactor import Container, Copy
+from proton.handlers import MessagingHandler
+
+class Recv(MessagingHandler):
+    def __init__(self):
+        super(Recv, self).__init__()
+
+    def on_start(self, event):
+        conn = event.container.connect("localhost:5672")
+        event.container.create_receiver(conn, "examples", options=Copy())
+
+    def on_message(self, event):
+        print event.message
+        if event.receiver.queued == 0 and event.receiver.drained:
+            event.connection.close()
+
+try:
+    Container(Recv()).run()
+except KeyboardInterrupt: pass
+
+
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aebacd07/examples/python/simple_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/simple_recv.py b/examples/python/simple_recv.py
index f6ebc90..abe30cd 100755
--- a/examples/python/simple_recv.py
+++ b/examples/python/simple_recv.py
@@ -40,6 +40,7 @@ class Recv(MessagingHandler):
             print event.message.body
             self.received += 1
             if self.received == self.expected:
+                event.receiver.close()
                 event.connection.close()
 
 parser = optparse.OptionParser(usage="usage: %prog [options]")

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aebacd07/proton-c/bindings/python/proton/handlers.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/handlers.py b/proton-c/bindings/python/proton/handlers.py
index e696c69..53dda92 100644
--- a/proton-c/bindings/python/proton/handlers.py
+++ b/proton-c/bindings/python/proton/handlers.py
@@ -102,6 +102,12 @@ class Reject(ProtonException):
   """
   pass
 
+class Release(ProtonException):
+  """
+  An exception that indicate a message should be rejected
+  """
+  pass
+
 class Acking(object):
     def accept(self, delivery):
         """
@@ -148,14 +154,22 @@ class IncomingMessageHandler(Handler, Acking):
         if not dlv.link.is_receiver: return
         if dlv.readable and not dlv.partial:
             event.message = recv_msg(dlv)
-            try:
-                self.on_message(event)
+            if event.link.state & Endpoint.LOCAL_CLOSED:
                 if self.auto_accept:
-                    dlv.update(Delivery.ACCEPTED)
+                    dlv.update(Delivery.RELEASED)
+                    dlv.settle()
+            else:
+                try:
+                    self.on_message(event)
+                    if self.auto_accept:
+                        dlv.update(Delivery.ACCEPTED)
+                        dlv.settle()
+                except Reject:
+                    dlv.update(Delivery.REJECTED)
+                    dlv.settle()
+                except Release:
+                    dlv.update(Delivery.MODIFIED)
                     dlv.settle()
-            except Reject:
-                dlv.update(Delivery.REJECTED)
-                dlv.settle()
         elif dlv.updated and dlv.settled:
             self.on_settled(event)
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/aebacd07/proton-c/bindings/python/proton/reactor.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/reactor.py b/proton-c/bindings/python/proton/reactor.py
index e3a6961..0c59ff9 100644
--- a/proton-c/bindings/python/proton/reactor.py
+++ b/proton-c/bindings/python/proton/reactor.py
@@ -404,6 +404,14 @@ class Selector(Filter):
     def __init__(self, value, name='selector'):
         super(Selector, self).__init__({symbol(name): Described(symbol('apache.org:selector-filter:string'),
value)})
 
+class Move(ReceiverOption):
+    def apply(self, receiver):
+        receiver.source.distribution_mode = Terminus.DIST_MODE_MOVE
+
+class Copy(ReceiverOption):
+    def apply(self, receiver):
+        receiver.source.distribution_mode = Terminus.DIST_MODE_COPY
+
 def _apply_link_options(options, link):
     if options:
         if isinstance(options, list):


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


Mime
View raw message