Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 564431860C for ; Tue, 26 May 2015 17:54:40 +0000 (UTC) Received: (qmail 85791 invoked by uid 500); 26 May 2015 17:54:40 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 85693 invoked by uid 500); 26 May 2015 17:54:40 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 85318 invoked by uid 99); 26 May 2015 17:54:40 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 May 2015 17:54:40 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id E4168AC0B9D for ; Tue, 26 May 2015 17:54:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1681800 [9/10] - in /qpid/site: docs/releases/qpid-proton-0.9.1/proton/python/examples/ input/releases/qpid-proton-0.9.1/proton/python/examples/ Date: Tue, 26 May 2015 17:54:38 -0000 To: commits@qpid.apache.org From: gsim@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150526175439.E4168AC0B9D@hades.apache.org> Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/proton_tornado.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/proton_tornado.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/proton_tornado.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/proton_tornado.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,115 @@ +
#!/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 tornado.ioloop
+from proton.reactor import Container as BaseContainer
+from proton.handlers import IOHandler
+
+class TornadoLoopHandler:
+
+    def __init__(self, loop=None, handler_base=None):
+        self.loop = loop or tornado.ioloop.IOLoop.instance()
+        self.io = handler_base or IOHandler()
+        self.count = 0
+
+    def on_reactor_init(self, event):
+        self.reactor = event.reactor
+
+    def on_reactor_quiesced(self, event):
+        event.reactor.yield_()
+
+    def on_unhandled(self, name, event):
+        event.dispatch(self.io)
+
+    def _events(self, sel):
+        events = self.loop.ERROR
+        if sel.reading:
+            events |= self.loop.READ
+        if sel.writing:
+            events |= self.loop.WRITE
+        return events
+
+    def _schedule(self, sel):
+        if sel.deadline:
+            self.loop.add_timeout(sel.deadline, lambda: self.expired(sel))
+
+    def _expired(self, sel):
+        sel.expired()
+
+    def _process(self):
+        self.reactor.process()
+        if not self.reactor.quiesced:
+            self.loop.add_callback(self._process)
+
+    def _callback(self, sel, events):
+        if self.loop.READ & events:
+            sel.readable()
+        if self.loop.WRITE & events:
+            sel.writable()
+        self._process()
+
+    def on_selectable_init(self, event):
+        sel = event.context
+        if sel.fileno() >= 0:
+            self.loop.add_handler(sel.fileno(), lambda fd, events: self._callback(sel, events), self._events(sel))
+        self._schedule(sel)
+        self.count += 1
+
+    def on_selectable_updated(self, event):
+        sel = event.context
+        if sel.fileno() > 0:
+            self.loop.update_handler(sel.fileno(), self._events(sel))
+        self._schedule(sel)
+
+    def on_selectable_final(self, event):
+        sel = event.context
+        if sel.fileno() > 0:
+            self.loop.remove_handler(sel.fileno())
+        sel.release()
+        self.count -= 1
+        if self.count == 0:
+            self.loop.add_callback(self._stop)
+
+    def _stop(self):
+        self.reactor.stop()
+        self.loop.stop()
+
+class Container(object):
+    def __init__(self, *handlers, **kwargs):
+        self.tornado_loop = kwargs.get('loop', tornado.ioloop.IOLoop.instance())
+        kwargs['global_handler'] = TornadoLoopHandler(self.tornado_loop, kwargs.get('handler_base', None))
+        self.container = BaseContainer(*handlers, **kwargs)
+
+    def initialise(self):
+        self.container.start()
+        self.container.process()
+
+    def run(self):
+        self.initialise()
+        self.tornado_loop.start()
+
+    def touch(self):
+        self._process()
+
+    def _process(self):
+        self.container.process()
+        if not self.container.quiesced:
+            self.tornado_loop.add_callback(self._process)
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/queue_browser.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/queue_browser.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/queue_browser.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/queue_browser.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,40 @@ +
#!/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
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,41 @@ +
#!/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, Handler
+
+class Recurring(Handler):
+    def __init__(self, period):
+        self.period = period
+
+    def on_reactor_init(self, event):
+        self.container = event.reactor
+        self.container.schedule(self.period, self)
+
+    def on_timer_task(self, event):
+        print "Tick..."
+        self.container.schedule(self.period, self)
+
+try:
+    container = Container(Recurring(1.0))
+    container.run()
+except KeyboardInterrupt:
+    container.stop()
+    print
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer_tornado.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer_tornado.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer_tornado.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/recurring_timer_tornado.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,43 @@ +
#!/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 time
+from proton.reactor import Handler
+from proton_tornado import TornadoLoop
+
+class Recurring(Handler):
+    def __init__(self, period):
+        self.period = period
+
+    def on_start(self, event):
+        self.container = event.container
+        self.container.schedule(time.time() + self.period, subject=self)
+
+    def on_timer(self, event):
+        print "Tick..."
+        self.container.schedule(time.time() + self.period, subject=self)
+
+try:
+    container = TornadoLoop(Recurring(1.0))
+    container.run()
+except KeyboardInterrupt:
+    container.stop()
+    print
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/selected_recv.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/selected_recv.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/selected_recv.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/selected_recv.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,38 @@ +
#!/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, Selector
+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=Selector(u"colour = 'green'"))
+
+    def on_message(self, event):
+        print event.message.body
+
+try:
+    Container(Recv()).run()
+except KeyboardInterrupt: pass
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,55 @@ +
#!/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 import Message
+from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+class Server(MessagingHandler):
+    def __init__(self, url, address):
+        super(Server, self).__init__()
+        self.url = url
+        self.address = address
+        self.senders = {}
+
+    def on_start(self, event):
+        print "Listening on", self.url
+        self.container = event.container
+        self.conn = event.container.connect(self.url)
+        self.receiver = event.container.create_receiver(self.conn, self.address)
+        self.relay = None
+
+    def on_connection_opened(self, event):
+        if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities:
+            self.relay = self.container.create_sender(self.conn, None)
+
+    def on_message(self, event):
+        print "Received", event.message
+        sender = self.relay or self.senders.get(event.message.reply_to)
+        if not sender:
+            sender = self.container.create_sender(self.conn, event.message.reply_to)
+            self.senders[event.message.reply_to] = sender
+        sender.send(Message(address=event.message.reply_to, body=event.message.body.upper(),
+                            correlation_id=event.message.correlation_id))
+
+try:
+    Container(Server("0.0.0.0:5672", "examples")).run()
+except KeyboardInterrupt: pass
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_direct.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_direct.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_direct.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_direct.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,61 @@ +
#!/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 import generate_uuid, Message
+from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+class Server(MessagingHandler):
+    def __init__(self, url):
+        super(Server, self).__init__()
+        self.url = url
+        self.senders = {}
+
+    def on_start(self, event):
+        print "Listening on", self.url
+        self.container = event.container
+        self.acceptor = event.container.listen(self.url)
+
+    def on_link_opening(self, event):
+        if event.link.is_sender:
+            if event.link.remote_source and event.link.remote_source.dynamic:
+                event.link.source.address = str(generate_uuid())
+                self.senders[event.link.source.address] = event.link
+            elif event.link.remote_target and event.link.remote_target.address:
+                event.link.target.address = event.link.remote_target.address
+                self.senders[event.link.remote_target.address] = event.link
+            elif event.link.remote_source:
+                event.link.source.address = event.link.remote_source.address
+        elif event.link.remote_target:
+            event.link.target.address = event.link.remote_target.address
+
+    def on_message(self, event):
+        print "Received", event.message
+        sender = self.senders.get(event.message.reply_to)
+        if not sender:
+            print "No link for reply"
+            return
+        sender.send(Message(address=event.message.reply_to, body=event.message.body.upper(),
+                            correlation_id=event.message.correlation_id))
+
+try:
+    Container(Server("0.0.0.0:8888")).run()
+except KeyboardInterrupt: pass
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_tx.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_tx.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_tx.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/server_tx.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,76 @@ +
#!/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 import Message
+from proton.reactor import Container
+from proton.handlers import MessagingHandler, TransactionHandler
+
+class TxRequest(TransactionHandler):
+    def __init__(self, response, sender, request_delivery):
+        super(TxRequest, self).__init__()
+        self.response = response
+        self.sender = sender
+        self.request_delivery = request_delivery
+
+    def on_transaction_declared(self, event):
+        event.transaction.send(self.sender, self.response)
+        event.transaction.accept(self.request_delivery)
+        event.transaction.commit()
+
+    def on_transaction_committed(self, event):
+        print "Request processed successfully"
+
+    def on_transaction_aborted(self, event):
+        print "Request processing aborted"
+
+
+class TxServer(MessagingHandler):
+    def __init__(self, host, address):
+        super(TxServer, self).__init__(auto_accept=False)
+        self.host = host
+        self.address = address
+
+    def on_start(self, event):
+        self.container = event.container
+        self.conn = event.container.connect(self.host, reconnect=False)
+        self.receiver = event.container.create_receiver(self.conn, self.address)
+        self.senders = {}
+        self.relay = None
+
+    def on_message(self, event):
+        sender = self.relay
+        if not sender:
+            sender = self.senders.get(event.message.reply_to)
+        if not sender:
+            sender = self.container.create_sender(self.conn, event.message.reply_to)
+            self.senders[event.message.reply_to] = sender
+
+        response = Message(address=event.message.reply_to, body=event.message.body.upper(),
+                           correlation_id=event.message.correlation_id)
+        self.container.declare_transaction(self.conn, handler=TxRequest(response, sender, event.delivery))
+
+    def on_connection_open(self, event):
+        if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities:
+            self.relay = self.container.create_sender(self.conn, None)
+
+try:
+    Container(TxServer("localhost:5672", "examples")).run()
+except KeyboardInterrupt: pass
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_recv.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_recv.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_recv.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_recv.py.html.in Tue May 26 17:54:36 2015 @@ -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):
+        event.container.create_receiver(self.url)
+
+    def on_message(self, event):
+        if event.message.id and event.message.id < self.received:
+            # ignore duplicate message
+            return
+        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()
+
+parser = optparse.OptionParser(usage="usage: %prog [options]")
+parser.add_option("-a", "--address", default="localhost:5672/examples",
+                  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
+
Added: qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_send.py.html.in URL: http://svn.apache.org/viewvc/qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_send.py.html.in?rev=1681800&view=auto ============================================================================== --- qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_send.py.html.in (added) +++ qpid/site/input/releases/qpid-proton-0.9.1/proton/python/examples/simple_send.py.html.in Tue May 26 17:54:36 2015 @@ -0,0 +1,63 @@ +
#!/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, messages):
+        super(Send, self).__init__()
+        self.url = url
+        self.sent = 0
+        self.confirmed = 0
+        self.total = messages
+
+    def on_start(self, event):
+        event.container.create_sender(self.url)
+
+    def on_sendable(self, event):
+        while event.sender.credit and self.sent < self.total:
+            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
+        if self.confirmed == self.total:
+            print "all messages confirmed"
+            event.connection.close()
+
+    def on_disconnected(self, event):
+        self.sent = self.confirmed
+
+parser = optparse.OptionParser(usage="usage: %prog [options]",
+                               description="Send messages to the supplied address.")
+parser.add_option("-a", "--address", default="localhost:5672/examples",
+                  help="address to which messages are sent (default %default)")
+parser.add_option("-m", "--messages", type="int", default=100,
+                  help="number of messages to send (default %default)")
+opts, args = parser.parse_args()
+
+try:
+    Container(Send(opts.address, opts.messages)).run()
+except KeyboardInterrupt: pass
+
--------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org