Repository: qpid-proton Updated Branches: refs/heads/master bbeb78caa -> db3ee8284
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/send.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/send.py b/examples/python/reactor/send.py deleted file mode 100755 index 4356da1..0000000 --- a/examples/python/reactor/send.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/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 sys -from proton import Message, Url -from proton.reactor import Reactor -from proton.handlers import CHandshaker - -# This is a send in terms of low level AMQP events. There are handlers -# that can streamline this significantly if you don't want to worry -# about all the details, but it is useful to see how the AMQP engine -# classes interact with handlers and events. - -class Send: - - def __init__(self, message, target): - self.message = message - self.target = target if target is not None else "examples" - # Use the handlers property to add some default handshaking - # behaviour. - self.handlers = [CHandshaker()] - - def on_connection_init(self, event): - conn = event.connection - - # Every session or link could have their own handler(s) if we - # wanted simply by setting the "handler" slot on the - # given session or link. - ssn = conn.session() - - # If a link doesn't have an event handler, the events go to - # its parent session. If the session doesn't have a handler - # the events go to its parent connection. If the connection - # doesn't have a handler, the events go to the reactor. - snd = ssn.sender("sender") - snd.target.address = self.target - conn.open() - ssn.open() - snd.open() - - def on_transport_error(self, event): - print event.transport.condition - - def on_link_flow(self, event): - snd = event.sender - if snd.credit > 0: - dlv = snd.send(self.message) - dlv.settle() - snd.close() - snd.session.close() - snd.connection.close() - -class Program: - - def __init__(self, url, content): - self.url = url - self.content = content - - def on_reactor_init(self, event): - # You can use the connection method to create AMQP connections. - - # This connection's handler is the Send object. All the events - # for this connection will go to the Send object instead of - # going to the reactor. If you were to omit the Send object, - # all the events would go to the reactor. - event.reactor.connection_to_host(self.url.host, self.url.port, - Send(Message(self.content), - self.url.path)) - -args = sys.argv[1:] -url = Url(args.pop() if args else "localhost:5672/examples") -content = args.pop() if args else "Hello World!" - -r = Reactor(Program(url, content)) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/tornado-hello-world.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/tornado-hello-world.py b/examples/python/reactor/tornado-hello-world.py deleted file mode 100755 index d06cd1b..0000000 --- a/examples/python/reactor/tornado-hello-world.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/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 __future__ import print_function -import tornado.ioloop -from tornado_app import TornadoApp - -# The proton reactor provides a general purpose event processing -# library for writing reactive programs. A reactive program is defined -# by a set of event handlers. An event handler is just any class or -# object that defines the "on_<event>" methods that it cares to -# handle. - -class Program: - - # The reactor init event is produced by the reactor itself when it - # starts. - def on_reactor_init(self, event): - print("Hello, World!") - -# The TornadoApp integrates a Reactor into tornado's ioloop. -TornadoApp(Program()) - -# Now the tornado main loop will behave like the reactor's main loop. -tornado.ioloop.IOLoop.instance().start() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/tornado-send.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/tornado-send.py b/examples/python/reactor/tornado-send.py deleted file mode 100755 index c69876a..0000000 --- a/examples/python/reactor/tornado-send.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/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 sys, tornado.ioloop -from tornado_app import TornadoApp -from proton import Message, Url -from proton.handlers import CHandshaker - -class Send: - - def __init__(self, message, target): - self.message = message - self.target = target if target is not None else "examples" - # Use the handlers property to add some default handshaking - # behaviour. - self.handlers = [CHandshaker()] - - def on_connection_init(self, event): - conn = event.connection - - # Every session or link could have their own handler(s) if we - # wanted simply by setting the "handler" slot on the - # given session or link. - ssn = conn.session() - - # If a link doesn't have an event handler, the events go to - # its parent session. If the session doesn't have a handler - # the events go to its parent connection. If the connection - # doesn't have a handler, the events go to the reactor. - snd = ssn.sender("sender") - snd.target.address = self.target - conn.open() - ssn.open() - snd.open() - - def on_link_flow(self, event): - snd = event.sender - if snd.credit > 0: - dlv = snd.send(self.message) - dlv.settle() - snd.close() - snd.session.close() - snd.connection.close() - -class Program: - - def __init__(self, url, content): - self.url = url - self.content = content - - def on_reactor_init(self, event): - # You can use the connection method to create AMQP connections. - - # This connection's handler is the Send object. All the events - # for this connection will go to the Send object instead of - # going to the reactor. If you were to omit the Send object, - # all the events would go to the reactor. - event.reactor.connection_to_host(self.url.host, self.url.port, - Send(Message(self.content), - self.url.path)) - -args = sys.argv[1:] -url = Url(args.pop() if args else "localhost:5672/examples") -content = args.pop() if args else "Hello World!" - -TornadoApp(Program(url, content)) -tornado.ioloop.IOLoop.instance().start() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/tornado_app.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/tornado_app.py b/examples/python/reactor/tornado_app.py deleted file mode 100644 index 966ac8b..0000000 --- a/examples/python/reactor/tornado_app.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/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 Reactor -from proton.handlers import IOHandler - -class TornadoApp: - - def __init__(self, *args): - self.reactor = Reactor(*args) - self.reactor.global_handler = self - self.io = IOHandler() - self.loop = tornado.ioloop.IOLoop.instance() - self.count = 0 - self.reactor.start() - self.reactor.process() - - 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() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/unhandled.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/unhandled.py b/examples/python/reactor/unhandled.py deleted file mode 100755 index 9ab2212..0000000 --- a/examples/python/reactor/unhandled.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/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 __future__ import print_function -import time -from proton.reactor import Reactor - -class Program: - - # If an event occurs and its handler doesn't have an on_<event> - # method, the reactor will attempt to call the on_unhandled method - # if it exists. This can be useful not only for debugging, but for - # logging and for delegating/inheritance. - def on_unhandled(self, name, event): - print(name, event) - -r = Reactor(Program()) -r.run() --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
