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/03/06 21:58:04 UTC

[1/2] qpid-proton git commit: NO-JIRA: small enhancements to Container, MessagingHandler and examples

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 <gs...@redhat.com>
Authored: Fri Mar 6 17:00:16 2015 +0000
Committer: Gordon Sim <gs...@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


[2/2] qpid-proton git commit: NO-JIRA: added sender and receiver example that accept incoming connections, demonstrating non-intermediated use.

Posted by gs...@apache.org.
NO-JIRA: added sender and receiver example that accept incoming connections, demonstrating non-intermediated use.


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

Branch: refs/heads/master
Commit: 5df0bbc2df27b4a4582672b12975ec3aeee8ee06
Parents: aebacd0
Author: Gordon Sim <gs...@redhat.com>
Authored: Fri Mar 6 19:25:52 2015 +0000
Committer: Gordon Sim <gs...@redhat.com>
Committed: Fri Mar 6 19:25:52 2015 +0000

----------------------------------------------------------------------
 examples/python/direct_recv.py   | 56 +++++++++++++++++++++++++++++++++++
 examples/python/direct_send.py   | 50 +++++++++++++++++++++++++++++++
 examples/python/test_examples.py | 21 +++++++++++++
 3 files changed, 127 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5df0bbc2/examples/python/direct_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/direct_recv.py b/examples/python/direct_recv.py
new file mode 100755
index 0000000..dd0e3c9
--- /dev/null
+++ b/examples/python/direct_recv.py
@@ -0,0 +1,56 @@
+#!/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.
+#
+
+import optparse
+from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+class Recv(MessagingHandler):
+    def __init__(self, url, count):
+        super(Recv, self).__init__()
+        self.url = url
+        self.expected = count
+        self.received = 0
+
+    def on_start(self, event):
+        self.acceptor = event.container.listen(self.url)
+
+    def on_message(self, event):
+        if self.expected == 0 or self.received < self.expected:
+            print event.message.body
+            self.received += 1
+            if self.received == self.expected:
+                event.receiver.close()
+                event.connection.close()
+                self.acceptor.close()
+
+parser = optparse.OptionParser(usage="usage: %prog [options]")
+parser.add_option("-a", "--address", default="localhost:8888",
+                  help="address from which messages are received (default %default)")
+parser.add_option("-m", "--messages", type="int", default=100,
+                  help="number of messages to receive; 0 receives indefinitely (default %default)")
+opts, args = parser.parse_args()
+
+try:
+    Container(Recv(opts.address, opts.messages)).run()
+except KeyboardInterrupt: pass
+
+
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5df0bbc2/examples/python/direct_send.py
----------------------------------------------------------------------
diff --git a/examples/python/direct_send.py b/examples/python/direct_send.py
new file mode 100755
index 0000000..bfeb357
--- /dev/null
+++ b/examples/python/direct_send.py
@@ -0,0 +1,50 @@
+#!/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.
+#
+
+import optparse
+from proton import Message
+from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+class Send(MessagingHandler):
+    def __init__(self, url):
+        super(Send, self).__init__()
+        self.url = url
+        self.sent = 0
+        self.confirmed = 0
+
+    def on_start(self, event):
+        event.container.listen(self.url)
+
+    def on_sendable(self, event):
+        while event.sender.credit:
+            msg = Message(id=(self.sent+1), body={'sequence':(self.sent+1)})
+            event.sender.send(msg)
+            self.sent += 1
+
+    def on_accepted(self, event):
+        self.confirmed += 1
+
+    def on_disconnected(self, event):
+        self.sent = self.confirmed
+
+try:
+    Container(Send("localhost:8888")).run()
+except KeyboardInterrupt: pass

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5df0bbc2/examples/python/test_examples.py
----------------------------------------------------------------------
diff --git a/examples/python/test_examples.py b/examples/python/test_examples.py
index 49abb8a..c3eaa11 100644
--- a/examples/python/test_examples.py
+++ b/examples/python/test_examples.py
@@ -107,3 +107,24 @@ class ExamplesTest(unittest.TestCase):
 
     def test_tx_send_tx_recv(self):
         self.test_simple_send_recv(recv='tx_recv.py', send='tx_send.py')
+
+    def test_simple_send_direct_recv(self):
+        self.maxDiff = None
+        r = subprocess.Popen(['direct_recv.py'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        time.sleep(0.5)
+        s = subprocess.Popen(['simple_send.py', '-a', 'localhost:8888'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        s.wait()
+        r.wait()
+        actual = [l.strip() for l in r.stdout]
+        expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+        self.assertEqual(actual, expected)
+
+    def test_direct_send_simple_recv(self):
+        s = subprocess.Popen(['direct_send.py'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        time.sleep(0.5)
+        r = subprocess.Popen(['simple_recv.py', '-a', 'localhost:8888'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        r.wait()
+        actual = [l.strip() for l in r.stdout]
+        expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+        s.terminate()
+        self.assertEqual(actual, expected)


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