http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/send.js ---------------------------------------------------------------------- diff --git a/examples/javascript/messenger/send.js b/examples/javascript/messenger/send.js deleted file mode 100755 index 608fab4..0000000 --- a/examples/javascript/messenger/send.js +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env node -/* - * 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. - * - */ - -// Check if the environment is Node.js and if not log an error and exit. -if (typeof process === 'object' && typeof require === 'function') { - // In this example we also set the global variable PROTON_TOTAL_MEMORY in order - // to increase the virtual heap available to the emscripten compiled C runtime. - // It is not really necessary to do this for this application as the default - // value of 16777216 is fine, it is simply done here to illustrate how to do it. - PROTON_TOTAL_MEMORY = 50000000; - var proton = require("qpid-proton-messenger"); - - var address = "amqp://0.0.0.0"; - var subject = "UK.WEATHER"; - var msgtext = "Hello World!"; - var tracker = null; - var running = true; - - var message = new proton.Message(); - var messenger = new proton.Messenger(); - - // This is an asynchronous send, so we can't simply call messenger.put(message) - // at the end of the application as we would with a synchronous/blocking - // version, as the application would simply exit without actually sending. - // The following callback function (and messenger.setOutgoingWindow()) - // gives us a means to wait until the consumer has received the message before - // exiting. The recv.js example explicitly accepts messages it receives. - var pumpData = function() { - var status = messenger.status(tracker); - if (status != proton.Status.PENDING) { - if (running) { - messenger.stop(); - running = false; - } - } - - if (messenger.isStopped()) { - message.free(); - messenger.free(); - } - }; - - var args = process.argv.slice(2); - if (args.length > 0) { - if (args[0] === '-h' || args[0] === '--help') { - console.log("Usage: node send.js [options] [message]"); - console.log("Options:"); - console.log(" -a <addr> The target address [amqp[s]://domain[/name]] (default " + address + ")"); - console.log(" -s <subject> The message subject (default " + subject + ")"); - console.log("message A text string to send."); - process.exit(0); - } - - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.charAt(0) === '-') { - i++; - var val = args[i]; - if (arg === '-a') { - address = val; - } else if (arg === '-s') { - subject = val; - } - } else { - msgtext = arg; - } - } - } - - console.log("Address: " + address); - console.log("Subject: " + subject); - console.log("Content: " + msgtext); - - messenger.on('error', function(error) {console.log(error);}); - messenger.on('work', pumpData); - messenger.setOutgoingWindow(1024); // So we can track status of send message. - messenger.start(); - - message.setAddress(address); - message.setSubject(subject); - message.body = msgtext; - - tracker = messenger.put(message); -} else { - console.error("send.js should be run in Node.js"); -} -
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/server.js ---------------------------------------------------------------------- diff --git a/examples/javascript/messenger/server.js b/examples/javascript/messenger/server.js deleted file mode 100755 index 6015321..0000000 --- a/examples/javascript/messenger/server.js +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env node -/* - * 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. - * - */ - -// Simple server for use with client.js illustrating request/response - -// Check if the environment is Node.js and if not log an error and exit. -if (typeof process === 'object' && typeof require === 'function') { - var proton = require("qpid-proton-messenger"); - - var address = "amqp://~0.0.0.0"; - var message = new proton.Message(); - var reply = new proton.Message(); - var messenger = new proton.Messenger(); - - var dispatch = function(request, response) { - var subject = request.getSubject(); - if (subject) { - response.setSubject('Re: ' + subject); - } - response.properties = request.properties - console.log("Dispatched " + subject + " " + JSON.stringify(request.properties)); - }; - - var pumpData = function() { - while (messenger.incoming()) { - var t = messenger.get(message); - - var replyTo = message.getReplyTo(); - if (replyTo) { - console.log(replyTo); - reply.setAddress(replyTo); - reply.setCorrelationID(message.getCorrelationID()); - reply.body = message.body; - dispatch(message, reply); - messenger.put(reply); - } - - messenger.accept(t); - } - }; - - var args = process.argv.slice(2); - if (args.length > 0) { - if (args[0] === '-h' || args[0] === '--help') { - console.log("Usage: node server.js <addr> (default " + address + ")"); - process.exit(0); - } - - address = args[0]; - } - - messenger.setIncomingWindow(1024); - - messenger.on('error', function(error) {console.log(error);}); - messenger.on('work', pumpData); - messenger.recv(); // Receive as many messages as messenger can buffer. - messenger.start(); - - messenger.subscribe(address); -} else { - console.error("server.js should be run in Node.js"); -} - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/spout.js ---------------------------------------------------------------------- diff --git a/examples/javascript/messenger/spout.js b/examples/javascript/messenger/spout.js deleted file mode 100755 index 013f79f..0000000 --- a/examples/javascript/messenger/spout.js +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env node -/* - * 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. - * - */ - -// Check if the environment is Node.js and if not log an error and exit. -if (typeof process === 'object' && typeof require === 'function') { - var proton = require("qpid-proton-messenger"); - - console.log("spout not implemented yet"); - process.exit(0); - - var address = "amqp://0.0.0.0"; - var subject = "UK.WEATHER"; - var msgtext = "Hello World!"; - var tracker = null; - var running = true; - - var message = new proton.Message(); - var messenger = new proton.Messenger(); - - function pumpData() { - var status = messenger.status(tracker); - if (status != proton.Status.PENDING) { -console.log("status = " + status); - - if (running) { -console.log("stopping"); - messenger.stop(); - running = false; - } - } - - if (messenger.isStopped()) { -console.log("exiting"); - message.free(); - messenger.free(); - } - }; - - messenger.on('error', function(error) {console.log(error);}); - messenger.on('work', pumpData); - messenger.setOutgoingWindow(1024); - messenger.start(); - - message.setAddress(address); - message.setSubject(subject); - - message.body = msgtext; - - tracker = messenger.put(message); -} else { - console.error("spout.js should be run in Node.js"); -} - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/ws2tcp.js ---------------------------------------------------------------------- diff --git a/examples/javascript/messenger/ws2tcp.js b/examples/javascript/messenger/ws2tcp.js deleted file mode 100644 index 1d90543..0000000 --- a/examples/javascript/messenger/ws2tcp.js +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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. - * - */ - -/** - * ws2tcp.js is a simple node.js library that proxies from a WebSocket to a TCP - * Socket or vice versa. It has minimal dependencies - the standard node.js net - * library and the ws WebSocket library (npm install ws). - * <p> - * Two fuctions are exported, ws2tcp proxies from a WebSocket to a TCP Socket and - * tcp2ws proxies from a TCP Socket to a WebSocket. - * @Author Fraser Adams - * @file - */ - -var WebSocket = require('ws'); -var net = require('net'); - -/** - * This function is shared by ws2tcp and tcp2ws and takes care of cleaning up - * and closing the WebSocket and Socket when things close down or error. - * @param sock the TCP Socket instance we're registering cleanup handlers for. - * @param ws the WebSocket instance we're registering cleanup handlers for. - */ -var registerCleanupCallbacks = function(sock, ws) { - var cleanup = function(sock, ws) { - sock.removeAllListeners('close'); - sock.end(); - ws.removeAllListeners('close'); - ws.close(); - }; - - sock.on('close', function() { - cleanup(sock, ws); - }); - - sock.on('error', function (e) { - console.log("socket error: " + e.code); - cleanup(sock, ws); - }); - - ws.on('close', function() { - cleanup(sock, ws); - }); - - ws.on('error', function (e) { - console.log("websocket error: " + e.code); - cleanup(sock, ws); - }); -}; - -/** - * This function establishes a proxy that listens on a specified TCP Socket port - * and proxies data to a WebSocket on the target host listening on the specified - * target port. - * @param lport the listen port. - * @param thost the target host. - * @param tport the target port. - * @param subProtocols a string containing a comma separated list of WebSocket sub-protocols. - */ -var tcp2ws = function(lport, thost, tport, subProtocols) { - var opts = null; - if (subProtocols) { - // The regex trims the string (removes spaces at the beginning and end, - // then splits the string by <any space>,<any space> into an Array. - subProtocols = subProtocols.replace(/^ +| +$/g,"").split(/ *, */); - opts = {'protocol': subProtocols.toString()}; - } - - var server = net.createServer(function(sock) { - var url = 'ws://' + thost + ':' + tport; - var ws = new WebSocket(url, opts); - var ready = false; - var buffer = []; - - registerCleanupCallbacks(sock, ws); - - sock.on('data', function(data) { - if (ready) { - ws.send(data); - } else { - buffer.push(data); - } - }); - - ws.on('open', function () { - if (buffer.length > 0) { - ws.send(Buffer.concat(buffer)); - } - ready = true; - buffer = null; - }); - - ws.on('message', function(m) { - sock.write(m); - }); - }); - server.listen(lport); -}; - -/** - * This function establishes a proxy that listens on a specified WebSocket port - * and proxies data to a TCP Socket on the target host listening on the specified - * target port. - * @param lport the listen port. - * @param thost the target host. - * @param tport the target port. - */ -var ws2tcp = function(lport, thost, tport) { - var server = new WebSocket.Server({port: lport}); - server.on('connection', function(ws) { - var sock = net.connect(tport, thost); - var ready = false; - var buffer = []; - - registerCleanupCallbacks(sock, ws); - - ws.on('message', function(m) { - if (ready) { - sock.write(m); - } else { - buffer.push(m); - } - }); - - sock.on('connect', function() { - if (buffer.length > 0) { - sock.write(Buffer.concat(buffer)); - } - ready = true; - buffer = null; - }); - - sock.on('data', function(data) { - try { - ws.send(data); - } catch (e) { - console.log("error sending: " + e); - } - }); - }); - server.on('error', function(e) { - console.log("websocket server error: " + e.code); - }); -}; - -// Export the two proxy functions. -module.exports.ws2tcp = ws2tcp; -module.exports.tcp2ws = tcp2ws; - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/async.pm ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/async.pm b/examples/perl/messenger/async.pm deleted file mode 100644 index 5cd350b..0000000 --- a/examples/perl/messenger/async.pm +++ /dev/null @@ -1,120 +0,0 @@ -# -# 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. -# - -use qpid_proton; - -package async::CallbackAdapter; - -sub new { - my ($class) = @_; - my ($self) = {}; - - my $messenger = $_[1]; - - $self->{_messenger} = $messenger; - $messenger->set_blocking(0); - $messenger->set_incoming_window(1024); - $messenger->set_outgoing_window(1024); - - my $message = qpid::proton::Message->new(); - $self->{_message} = $message; - $self->{_incoming} = $message; - $self->{_tracked} = {}; - - bless $self, $class; - return $self; -} - -sub run { - my ($self) = @_; - - $self->{_running} = 1; - - my $messenger = $self->{_messenger}; - - $messenger->start(); - $self->on_start(); - - do { - $messenger->work; - $self->process_outgoing; - $self->process_incoming; - } while($self->{_running}); - - $messenger->stop(); - - while(!$messenger->stopped()) { - $messenger->work; - $self->process_outgoing; - $self->process_incoming; - } - - $self->on_stop(); -} - -sub stop { - my ($self) = @_; - - $self->{_running} = 0; -} - -sub process_outgoing { - my ($self) = @_; - my $tracked = $self->{_tracked}; - - foreach $key (keys %{$tracked}) { - my $on_status = $tracked->{$key}; - if (defined($on_status)) { - if (!($on_status eq qpid::proton::Tracker::PENDING)) { - $self->$on_status($status); - $self->{_messenger}->settle($t); - # delete the settled item - undef $tracked->{$key}; - } - } - } -} - -sub process_incoming { - my ($self) = @_; - my $messenger = $self->{_messenger}; - - while ($messenger->incoming > 0) { - my $message = $self->{_message}; - my $t = $messenger->get($message); - - $self->on_receive($message); - $messenger->accept($t); - } -} - -sub send { - my ($self) = @_; - my $messenger = $self->{_messenger}; - my $tracked = $self->{_tracked}; - my $message = $_[1]; - my $on_status = $_[2] || undef; - - my $tracker = $messenger->put($message); - - $tracked->{$tracker} = $on_status if (defined($on_status)); -} - - -1; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/client.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/client.pl b/examples/perl/messenger/client.pl deleted file mode 100755 index a6d8378..0000000 --- a/examples/perl/messenger/client.pl +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use strict; -use warnings; -use Getopt::Long; -use Pod::Usage; - -use qpid_proton; - -my $reply_to = "~/replies"; -my $help = 0; -my $man = 0; - -GetOptions( - "reply_to=s", \$reply_to, - man => \$man, - "help|?" => \$help - ) or pod2usage(2); -pod2usage(1) if $help; -pod2usage(-exitval => 0, -verbose => 2) if $man; - -# get the address to use and show help if it's missing -my $address = $ARGV[0]; -pod2usage(1) if !$address; - -my $messenger = new qpid::proton::Messenger(); -$messenger->start; - -my $message = new qpid::proton::Message(); -$message->set_address($address); -$message->set_reply_to($reply_to); -$message->set_subject("Subject"); -$message->set_content("Yo!"); - -print "Sending to: $address\n"; - -$messenger->put($message); -$messenger->send; - -if($reply_to =~ /^~\//) { - print "Waiting on returned message.\n"; - $messenger->receive(1); - - $messenger->get($message); - print $message->get_address . " " . $message->get_subject . "\n"; -} - -$messenger->stop; - -__END__ - -=head1 NAME - -client - Proton example application for Perl. - -=head1 SYNOPSIS - -client.pl [OPTIONS] <address> <subject> - - Options: - --reply_to - The reply to address to be used. (default: ~/replies) - --help - This help message. - --man - Show the full docementation. - -=over 8 - -=item B<--reply_to> - -Specifies the reply address to be used for responses from the server. - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the man page and exits. - -=back - -=head2 ADDRESS - -The form an address takes is: - -[amqp://]<domain>[/name] - -=cut http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/recv.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/recv.pl b/examples/perl/messenger/recv.pl deleted file mode 100755 index 801f6a2..0000000 --- a/examples/perl/messenger/recv.pl +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use warnings; - -use Scalar::Util qw(reftype); -use Data::Dumper; - -use qpid_proton; - -sub usage { - exit(0); -} - -my @addresses = @ARGV; -@addresses = ("~0.0.0.0") unless $addresses[0]; - -my $messenger = new qpid::proton::Messenger(); -my $msg = new qpid::proton::Message(); - -$messenger->start(); - -foreach (@addresses) -{ - print "Subscribing to $_\n"; - $messenger->subscribe($_); -} - -for(;;) -{ - $messenger->receive(10); - - while ($messenger->incoming() > 0) - { - $messenger->get($msg); - - print "\n"; - print "Address: " . $msg->get_address() . "\n"; - print "Subject: " . $msg->get_subject() . "\n" unless !defined($msg->get_subject()); - print "Body: "; - - my $body = $msg->get_body(); - my $body_type = $msg->get_body_type(); - - if (!defined($body_type)) { - print "The body type wasn't defined!\n"; - } elsif ($body_type == qpid::proton::BOOL) { - print "[BOOL]\n"; - print "" . ($body ? "TRUE" : "FALSE") . "\n"; - } elsif ($body_type == qpid::proton::MAP) { - print "[HASH]\n"; - print Dumper(\%{$body}) . "\n"; - } elsif ($body_type == qpid::proton::ARRAY) { - print "[ARRAY]\n"; - print Data::Dumper->Dump($body) . "\n"; - } elsif ($body_type == qpid::proton::LIST) { - print "[LIST]\n"; - print Data::Dumper->Dump($body) . "\n"; - } else { - print "[$body_type]\n"; - print "$body\n"; - } - - print "Properties:\n"; - my $props = $msg->get_properties(); - foreach (keys $props) { - print "\t$_=$props->{$_}\n"; - } - print "Instructions:\n"; - my $instructions = $msg->get_instructions; - foreach (keys $instructions) { - print "\t$_=" . $instructions->{$_} . "\n"; - } - print "Annotations:\n"; - my $annotations = $msg->get_annotations(); - foreach (keys $annotations) { - print "\t$_=" . $annotations->{$_} . "\n"; - } - } -} - -die $@ if ($@); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/recv_async.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/recv_async.pl b/examples/perl/messenger/recv_async.pl deleted file mode 100755 index 9a2195a..0000000 --- a/examples/perl/messenger/recv_async.pl +++ /dev/null @@ -1,84 +0,0 @@ -# -# 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. -# - -use qpid_proton; -use async; - -package async::Receiver; - -@ISA = (async::CallbackAdapter); - -sub on_start { - my ($self) = @_; - my $args = $_[1] || ("amqp://~0.0.0.0"); - my $messenger = $self->{_messenger}; - - foreach $arg ($args) { - $messenger->subscribe($arg); - } - - $messenger->receive(); -} - -sub on_receive { - my ($self) = @_; - my $msg = $_[1]; - my $message = $self->{_message}; - my $text = ""; - - if (defined($msg->get_body)) { - $text = $msg->get_body; - if ($text eq "die") { - $self->stop; - } - } else { - $text = $message->get_subject; - } - - $text = "" if (!defined($text)); - - print "Received: $text\n"; - - if ($msg->get_reply_to) { - print "Sending reply to: " . $msg->get_reply_to . "\n"; - $message->clear; - $message->set_address($msg->get_reply_to()); - $message->set_body("Reply for ", $msg->get_body); - $self->send($message); - } -} - -sub on_status { - my ($self) = @_; - my $messenger = $self->{_messenger}; - my $status = $_[1]; - - print "Status: ", $status, "\n"; -} - -sub on_stop { - print "Stopped.\n" -} - -package main; - -our $messenger = new qpid::proton::Messenger(); -our $app = new async::Receiver($messenger); - -$app->run(); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/send.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/send.pl b/examples/perl/messenger/send.pl deleted file mode 100755 index 27893ce..0000000 --- a/examples/perl/messenger/send.pl +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use strict; -use warnings; -use Getopt::Std; - -use qpid_proton; - -$Getopt::Std::STANDARD_HELP_VERSION = 1; - -sub VERSION_MESSAGE() { -} - -sub HELP_MESSAGE() { - print "Usage: send.pl [OPTIONS] -a <ADDRESS>\n"; - print "Options:\n"; - print "\t-s - the message subject\n"; - print "\t-C - the message content\n"; - print "\t<ADDRESS> - amqp://<domain>[/<name>]\n"; - print "\t-h - this message\n"; - - exit; -} - -my %options = (); -getopts("a:C:s:h:", \%options) or HELP_MESSAGE(); - -my $address = $options{a} || "amqp://0.0.0.0"; -my $subject = $options{s} || localtime(time); -my $content = $options{C} || ""; - -my $msg = new qpid::proton::Message(); -my $messenger = new qpid::proton::Messenger(); - -$messenger->start(); - -my @messages = @ARGV; -@messages = ("This is a test. " . localtime(time)) unless $messages[0]; - -foreach (@messages) -{ - $msg->set_address($address); - $msg->set_subject($subject); - $msg->set_body($content); - # try a few different body types - my $body_type = int(rand(6)); - $msg->set_property("sent", "" . localtime(time)); - $msg->get_instructions->{"fold"} = "yes"; - $msg->get_instructions->{"spindle"} = "no"; - $msg->get_instructions->{"mutilate"} = "no"; - $msg->get_annotations->{"version"} = 1.0; - $msg->get_annotations->{"pill"} = "RED"; - - SWITCH: { - $body_type == 0 && do { $msg->set_body("It is now " . localtime(time));}; - $body_type == 1 && do { $msg->set_body(rand(65536)); }; - $body_type == 2 && do { $msg->set_body(int(rand(2)), qpid::proton::BOOL); }; - $body_type == 3 && do { $msg->set_body({"foo" => "bar"}); }; - $body_type == 4 && do { $msg->set_body([4, [1, 2, 3.1, 3.4E-5], 8, 15, 16, 23, 42]); }; - $body_type == 5 && do { $msg->set_body(int(rand(65535))); } - } - - $messenger->put($msg); - print "Sent: " . $msg->get_body . " [CONTENT TYPE: " . $msg->get_body_type . "]\n"; -} - -$messenger->send(); -$messenger->stop(); - -die $@ if ($@); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/send_async.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/send_async.pl b/examples/perl/messenger/send_async.pl deleted file mode 100644 index 2f9408a..0000000 --- a/examples/perl/messenger/send_async.pl +++ /dev/null @@ -1,97 +0,0 @@ -# -# 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. -# - -use Getopt::Std; -use qpid_proton; -use async; - -$Getopt::Std::STANDARD_HELP_VERSION = 1; - -sub VERSION_MESSAGE() {} - -sub HELP_MESSAGE() { - print "Usage: send_async.pl [OPTIONS] <msg_0> <msg_1> ...\n"; - print "Options:\n"; - print "\t-a - the message address (def. amqp://0.0.0.0)\n"; - print "\t-r - the reply-to address: //<domain>[/<name>]\n"; - print "\t msg_# - a text string to send\n"; -} - -my %optons = (); -getopts("a:r:", \%options) or usage(); - -our $address = $options{a} || "amqp://0.0.0.0"; -our $replyto = $options{r} || "~/#"; - -package async::Sender; - -@ISA = (async::CallbackAdapter); - -sub on_start { - my ($self) = @_; - my $message = $self->{_message}; - my $messenger = $self->{_messenger}; - my $args = $_[1] || ("Hello world!"); - - print "Started\n"; - - $message->clear; - $message->set_address("amqp://0.0.0.0"); - $message->set_reply_to($replyto) if (defined($replyto)); - - foreach $arg ($args) { - $message->set_body($arg); - if ($replyto) { - $message->set_reply_to($replyto); - } - $self->send($message, "on_status"); - } - - $messenger->receive() if (defined($replyto)); -} - -sub on_status { - my ($self) = @_; - my $messenger = $self->{_messenger}; - my $status = $_[1] || ""; - - print "Status: ", $status, "\n"; -} - -sub on_receive { - my ($self) = @_; - my $message = $_[1]; - my $text = $message->get_body || "[empty]"; - - print "Received: " . $text . "\n"; - - $self->stop(); -} - -sub on_stop { - print "Stopped\n"; -} - - -package main; - -our $msgr = new qpid::proton::Messenger(); -our $app = async::Sender->new($msgr); - -$app->run; http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/perl/messenger/server.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/server.pl b/examples/perl/messenger/server.pl deleted file mode 100755 index c13d4d5..0000000 --- a/examples/perl/messenger/server.pl +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use strict; -use warnings; -use Getopt::Long; -use Pod::Usage; - -use qpid_proton; - -my $help = 0; -my $man = 0; - -GetOptions( - man => \$man, - "help|?" => \$help - ) or pod2usage(2); - -pod2usage(1) if $help; -pod2usage(-exitval => 0, -verbose => 2) if $man; - -pod2usage(2) unless scalar(@ARGV); - -# create a messenger for receiving and holding -# incoming messages -our $messenger = new qpid::proton::Messenger; -$messenger->start; - -# subscribe the messenger to all addresses specified sources -foreach (@ARGV) { - $messenger->subscribe($_); -} - -sub dispatch { - my $request = $_[0]; - my $reply = $_[1]; - - if ($request->get_subject) { - $reply->set_subject("Re: " . $request->get_subject); - } - - $reply->set_properties($request->get_properties); - print "Dispatched " . $request->get_subject . "\n"; - my $properties = $request->get_properties; - foreach (keys %{$properties}) { - my $value = $properties->{%_}; - print "\t$_: $value\n"; - } -} - -our $message = new qpid::proton::Message; -our $reply = new qpid::proton::Message; - -while(1) { - $messenger->receive(1) if $messenger->incoming < 10; - - if ($messenger->incoming > 0) { - $messenger->get($message); - - if ($message->get_reply_to) { - print $message->get_reply_to . "\n"; - $reply->set_address($message->get_reply_to); - $reply->set_correlation_id($message->get_correlation_id); - $reply->set_body($message->get_body); - } - dispatch($message, $reply); - $messenger->put($reply); - $messenger->send; - } -} - -$message->stop; - -__END__ - -=head1 NAME - -server - Proton example server application for Perl. - -=head1 SYNOPSIS - -server.pl [OPTIONS] <addr1> ... <addrn> - - Options: - --help - This help message. - --man - Show the full documentation. - -=over 8 - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the man page and exits. - -=back - -=head2 ADDRESS - -The form an address takes is: - -[amqp://]<domain>[/name] - -=cut http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/php/messenger/recv.php ---------------------------------------------------------------------- diff --git a/examples/php/messenger/recv.php b/examples/php/messenger/recv.php deleted file mode 100644 index 05ece80..0000000 --- a/examples/php/messenger/recv.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -/** - * 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. - **/ - -include("proton.php"); - -$mess = new Messenger(); -$mess->start(); - -if ($argv[1]) { - $mess->subscribe($argv[1]); -} else { - $mess->subscribe("amqp://~0.0.0.0"); -} - -$msg = new Message(); -while (true) { - $mess->recv(10); - while ($mess->incoming) { - try { - $mess->get($msg); - } catch (Exception $e) { - print "$e\n"; - continue; - } - - print "$msg->address, $msg->subject, $msg->body\n"; - } -} - -$mess->stop(); -?> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/php/messenger/send.php ---------------------------------------------------------------------- diff --git a/examples/php/messenger/send.php b/examples/php/messenger/send.php deleted file mode 100644 index 599f7eb..0000000 --- a/examples/php/messenger/send.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -/** - * 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. - **/ - -include("proton.php"); - -$mess = new Messenger(); -$mess->start(); - -$msg = new Message(); -if ($argv[1]) { - $msg->address = $argv[1]; -} else { - $msg->address = "amqp://0.0.0.0"; -} -$msg->subject = "Hello World!"; -$msg->body = "this is a test"; - -$mess->put($msg); -$mess->send(); -print "sent: $msg->subject\n"; - -$mess->stop(); -?> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/README.txt ---------------------------------------------------------------------- diff --git a/examples/python/messenger/README.txt b/examples/python/messenger/README.txt deleted file mode 100644 index c26ba76..0000000 --- a/examples/python/messenger/README.txt +++ /dev/null @@ -1,20 +0,0 @@ -This directory contains example scripts using the messenger API. - - send.py - a simple example of using the messenger API to send messages - recv.py - a simple example of using the messenger API to receive messages - -Note that depending on the address passed into these scripts, you can -use them in either a peer to peer or a brokered scenario. - -For brokered usage: - - recv.py amqp://<broker>/<queue> - - send.py -a amqp://<broker>/<queue> msg_1 ... msg_n - -For peer to peer usage: - - # execute on <host> to receive messages from all local network interfaces - recv.py amqp://~0.0.0.0 - - send.py -a amqp://<host> msg_1 ... msg_n http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/async.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/async.py b/examples/python/messenger/async.py deleted file mode 100755 index a1b0292..0000000 --- a/examples/python/messenger/async.py +++ /dev/null @@ -1,82 +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 sys -from proton import * - -class CallbackAdapter: - - def __init__(self, messenger): - self.messenger = messenger - self.messenger.blocking = False - self.messenger.outgoing_window = 1024 - self.messenger.incoming_window = 1024 - # for application use - self.message = Message() - self._incoming_message = Message() - self.tracked = {} - - def run(self): - self.running = True - self.messenger.start() - self.on_start() - - while self.running: - self.messenger.work() - self._process() - - self.messenger.stop() - - while not self.messenger.stopped: - self.messenger.work() - self._process() - - self.on_stop() - - def stop(self): - self.running = False - - def _process(self): - self._process_outgoing() - self._process_incoming() - - def _process_outgoing(self): - for t, on_status in list(self.tracked.items()): - status = self.messenger.status(t) - if status != PENDING: - on_status(status) - self.messenger.settle(t) - del self.tracked[t] - - def _process_incoming(self): - while self.messenger.incoming: - t = self.messenger.get(self._incoming_message) - try: - self.on_recv(self._incoming_message) - self.messenger.accept(t) - except: - ex = sys.exc_info()[1] - print("Exception:", ex) - self.messenger.reject(t) - - def send(self, message, on_status=None): - t = self.messenger.put(message) - if on_status: - self.tracked[t] = on_status http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/client.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/client.py b/examples/python/messenger/client.py deleted file mode 100755 index 62fc16e..0000000 --- a/examples/python/messenger/client.py +++ /dev/null @@ -1,56 +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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog <addr> <subject>", - description="simple message server") - -parser.add_option("-r", "--reply_to", default="~/replies", - help="address: [amqp://]<domain>[/<name>] (default %default)") - -opts, args = parser.parse_args() - -if len(args) != 2: - parser.error("incorrect number of arguments") - -address, subject = args - -mng = Messenger() -mng.start() - -msg = Message() -msg.address = address -msg.subject = subject -msg.reply_to = opts.reply_to - -mng.put(msg) -mng.send() - -if opts.reply_to[:2] == "~/": - mng.recv(1) - try: - mng.get(msg) - print(msg.address, msg.subject) - except Exception as e: - print(e) - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/recv.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/recv.py b/examples/python/messenger/recv.py deleted file mode 100755 index 5771bd7..0000000 --- a/examples/python/messenger/recv.py +++ /dev/null @@ -1,55 +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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <addr_1> ... <addr_n>", - description="simple message receiver") -parser.add_option("-c", "--certificate", help="path to certificate file") -parser.add_option("-k", "--private-key", help="path to private key file") -parser.add_option("-p", "--password", help="password for private key file") - -opts, args = parser.parse_args() - -if not args: - args = ["amqp://~0.0.0.0"] - -mng = Messenger() -mng.certificate=opts.certificate -mng.private_key=opts.private_key -mng.password=opts.password -mng.start() - -for a in args: - mng.subscribe(a) - -msg = Message() -while True: - mng.recv() - while mng.incoming: - try: - mng.get(msg) - except Exception as e: - print(e) - else: - print(msg.address, msg.subject or "(no subject)", msg.properties, msg.body) - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/recv_async.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/recv_async.py b/examples/python/messenger/recv_async.py deleted file mode 100755 index b38c31a..0000000 --- a/examples/python/messenger/recv_async.py +++ /dev/null @@ -1,56 +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 sys, optparse -from async import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <addr_1> ... <addr_n>", - description="simple message receiver") - -opts, args = parser.parse_args() - -if not args: - args = ["amqp://~0.0.0.0"] - -class App(CallbackAdapter): - - def on_start(self): - print("Started") - for a in args: - print("Subscribing to:", a) - self.messenger.subscribe(a) - self.messenger.recv() - - def on_recv(self, msg): - print("Received:", msg) - if msg.body == "die": - self.stop() - if msg.reply_to: - self.message.clear() - self.message.address = msg.reply_to - self.message.body = "Reply for: %s" % msg.body - print("Replied:", self.message) - self.send(self.message) - - def on_stop(self): - print("Stopped") - -a = App(Messenger()) -a.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/send.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/send.py b/examples/python/messenger/send.py deleted file mode 100755 index c274656..0000000 --- a/examples/python/messenger/send.py +++ /dev/null @@ -1,45 +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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>", - description="simple message sender") -parser.add_option("-a", "--address", default="amqp://0.0.0.0", - help="address: //<domain>[/<name>] (default %default)") - -opts, args = parser.parse_args() -if not args: - args = ["Hello World!"] - -mng = Messenger() -mng.start() - -msg = Message() -for m in args: - msg.address = opts.address - msg.body = str(m) - mng.put(msg) - -mng.send() -print("sent:", ", ".join(args)) - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/send_async.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/send_async.py b/examples/python/messenger/send_async.py deleted file mode 100755 index 50f7a68..0000000 --- a/examples/python/messenger/send_async.py +++ /dev/null @@ -1,64 +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 sys, optparse -from async import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>", - description="simple message sender") -parser.add_option("-a", "--address", default="amqp://0.0.0.0", - help="address: //<domain>[/<name>] (default %default)") -parser.add_option("-r", "--reply_to", help="reply_to: //<domain>[/<name>]") - -opts, args = parser.parse_args() -if not args: - args = ["Hello World!"] - -class App(CallbackAdapter): - - def on_start(self): - print("Started") - self.message.clear() - self.message.address = opts.address - self.message.reply_to = opts.reply_to - for a in args: - self.message.body = a - self.send(self.message, self.on_status) - - if opts.reply_to: - self.messenger.recv() - - def on_status(self, status): - print("Status:", status) - if not opts.reply_to or opts.reply_to[0] != "~": - args.pop(0) - if not args: self.stop() - - def on_recv(self, msg): - print("Received:", msg) - if opts.reply_to and opts.reply_to[0] == "~": - args.pop(0) - if not args: self.stop() - - def on_stop(self): - print("Stopped") - -a = App(Messenger()) -a.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/messenger/server.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/server.py b/examples/python/messenger/server.py deleted file mode 100755 index 8c25879..0000000 --- a/examples/python/messenger/server.py +++ /dev/null @@ -1,62 +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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog <addr_1> ... <addr_n>", - description="simple message server") - -opts, args = parser.parse_args() - -if not args: - args = ["amqp://~0.0.0.0"] - -mng = Messenger() -mng.start() - -for a in args: - mng.subscribe(a) - -def dispatch(request, response): - if request.subject: - response.subject = "Re: %s" % request.subject - response.properties = request.properties - print("Dispatched %s %s" % (request.subject, request.properties)) - -msg = Message() -reply = Message() - -while True: - if mng.incoming < 10: - mng.recv(10) - - if mng.incoming > 0: - mng.get(msg) - if msg.reply_to: - print(msg.reply_to) - reply.address = msg.reply_to - reply.correlation_id = msg.correlation_id - reply.body = msg.body - dispatch(msg, reply) - mng.put(reply) - mng.send() - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/README.md ---------------------------------------------------------------------- diff --git a/examples/python/reactor/README.md b/examples/python/reactor/README.md deleted file mode 100644 index b08fdbd..0000000 --- a/examples/python/reactor/README.md +++ /dev/null @@ -1,34 +0,0 @@ -The examples in this directory provide a basic introduction to the -proton reactor API and are best viewed in the order presented below. - -The examples contain comments that explain things in a tutorial-style -manner. At some point soon this content will be pulled out into a -proper tutorial that references the relevant code snippets from these -examples. Until then please bear with this clumsy style of -presentation. - -This API is present in C as well and most of these examples will -transliterate into C in a fairly straightforward way. - - - hello-world.py - - goodbye-world.py - - - scheduling.py - - counter.py - - count-randomly.py - - - unhandled.py - - reactor-logger.py - - global-logger.py - - delegates.py - - - handlers.py - - - echo.py - - cat.py - - - send.py - - recv.py - - - tornado-hello-world.py - - tornado-send.py http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/cat.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/cat.py b/examples/python/reactor/cat.py deleted file mode 100755 index 82ebd27..0000000 --- a/examples/python/reactor/cat.py +++ /dev/null @@ -1,57 +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 sys, os -from proton.reactor import Reactor - -class Echo: - - def __init__(self, source): - self.source = source - - def on_selectable_init(self, event): - sel = event.context # XXX: no selectable property yet - - # We can configure a selectable with any file descriptor we want. - sel.fileno(self.source.fileno()) - # Ask to be notified when the file is readable. - sel.reading = True - event.reactor.update(sel) - - def on_selectable_readable(self, event): - sel = event.context - - # The on_selectable_readable event tells us that there is data - # to be read, or the end of stream has been reached. - data = os.read(sel.fileno(), 1024) - if data: - print(data, end=' ') - else: - sel.terminate() - event.reactor.update(sel) - -class Program: - - def on_reactor_init(self, event): - event.reactor.selectable(Echo(open(sys.argv[1]))) - -r = Reactor(Program()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/count-randomly.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/count-randomly.py b/examples/python/reactor/count-randomly.py deleted file mode 100755 index fb3709a..0000000 --- a/examples/python/reactor/count-randomly.py +++ /dev/null @@ -1,78 +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, random -from proton.reactor import Reactor - -# Let's try to modify our counter example. In addition to counting to -# 10 in quarter second intervals, let's also print out a random number -# every half second. This is not a super easy thing to express in a -# purely sequential program, but not so difficult using events. - -class Counter: - - def __init__(self, limit): - self.limit = limit - self.count = 0 - - def on_timer_task(self, event): - self.count += 1 - print(self.count) - if not self.done(): - event.reactor.schedule(0.25, self) - - # add a public API to check for doneness - def done(self): - return self.count >= self.limit - -class Program: - - def on_reactor_init(self, event): - self.start = time.time() - print("Hello, World!") - - # Save the counter instance in an attribute so we can refer to - # it later. - self.counter = Counter(10) - event.reactor.schedule(0.25, self.counter) - - # Now schedule another event with a different handler. Note - # that the timer tasks go to separate handlers, and they don't - # interfere with each other. - event.reactor.schedule(0.5, self) - - def on_timer_task(self, event): - # keep on shouting until we are done counting - print("Yay, %s!" % random.randint(10, 100)) - if not self.counter.done(): - event.reactor.schedule(0.5, self) - - def on_reactor_final(self, event): - print("Goodbye, World! (after %s long seconds)" % (time.time() - self.start)) - -# In hello-world.py we said the reactor exits when there are no more -# events to process. While this is true, it's not actually complete. -# The reactor exits when there are no more events to process and no -# possibility of future events arising. For that reason the reactor -# will keep running until there are no more scheduled events and then -# exit. -r = Reactor(Program()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/counter.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/counter.py b/examples/python/reactor/counter.py deleted file mode 100755 index 7c8167a..0000000 --- a/examples/python/reactor/counter.py +++ /dev/null @@ -1,61 +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 Counter: - - def __init__(self, limit): - self.limit = limit - self.count = 0 - - def on_timer_task(self, event): - self.count += 1 - print(self.count) - if self.count < self.limit: - # A recurring task can be acomplished by just scheduling - # another event. - event.reactor.schedule(0.25, self) - -class Program: - - def on_reactor_init(self, event): - self.start = time.time() - print("Hello, World!") - - # Note that unlike the previous scheduling example, we pass in - # a separate object for the handler. This means that the timer - # event we just scheduled will not be seen by Program as it is - # being handled by the Counter instance we create. - event.reactor.schedule(0.25, Counter(10)) - - def on_reactor_final(self, event): - print("Goodbye, World! (after %s long seconds)" % (time.time() - self.start)) - -# In hello-world.py we said the reactor exits when there are no more -# events to process. While this is true, it's not actually complete. -# The reactor exits when there are no more events to process and no -# possibility of future events arising. For that reason the reactor -# will keep running until there are no more scheduled events and then -# exit. -r = Reactor(Program()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/delegates.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/delegates.py b/examples/python/reactor/delegates.py deleted file mode 100755 index 1a8e1e9..0000000 --- a/examples/python/reactor/delegates.py +++ /dev/null @@ -1,49 +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 - -# Events know how to dispatch themselves to handlers. By combining -# this with on_unhandled, you can provide a kind of inheritance -# between handlers using delegation. - -class Hello: - - def on_reactor_init(self, event): - print("Hello, World!") - -class Goodbye: - - def on_reactor_final(self, event): - print("Goodbye, World!") - -class Program: - - def __init__(self, *delegates): - self.delegates = delegates - - def on_unhandled(self, name, event): - for d in self.delegates: - event.dispatch(d) - -r = Reactor(Program(Hello(), Goodbye())) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/echo.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/echo.py b/examples/python/reactor/echo.py deleted file mode 100755 index 17529d9..0000000 --- a/examples/python/reactor/echo.py +++ /dev/null @@ -1,62 +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 sys, os -from proton.reactor import Reactor - -class Echo: - - def __init__(self, source): - self.source = source - - def on_selectable_init(self, event): - sel = event.context # XXX: no selectable property yet - - # We can configure a selectable with any file descriptor we want. - sel.fileno(self.source.fileno()) - # Ask to be notified when the file is readable. - sel.reading = True - event.reactor.update(sel) - - def on_selectable_readable(self, event): - sel = event.context - - # The on_selectable_readable event tells us that there is data - # to be read, or the end of stream has been reached. - data = os.read(sel.fileno(), 1024) - if data: - print(data, end=' ') - else: - sel.terminate() - event.reactor.update(sel) - -class Program: - - def on_reactor_init(self, event): - # Every selectable is a possible source of future events. Our - # selectable stays alive until it reads the end of stream - # marker. This will keep the whole reactor running until we - # type Control-D. - print("Type whatever you want and then use Control-D to exit:") - event.reactor.selectable(Echo(sys.stdin)) - -r = Reactor(Program()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/global-logger.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/global-logger.py b/examples/python/reactor/global-logger.py deleted file mode 100755 index 3cbe11c..0000000 --- a/examples/python/reactor/global-logger.py +++ /dev/null @@ -1,59 +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 - -# Not every event goes to the reactor's event handler. If we have a -# separate handler for something like a scheduled task, then those -# events aren't logged by the logger associated with the reactor's -# handler. Sometimes this is useful if you don't want to see them, but -# sometimes you want the global picture. - -class Logger: - - def on_unhandled(self, name, event): - print("LOG:", name, event) - -class Task: - - def on_timer_task(self, event): - print("Mission accomplished!") - -class Program: - - def on_reactor_init(self, event): - print("Hello, World!") - event.reactor.schedule(0, Task()) - - def on_reactor_final(self, event): - print("Goodbye, World!") - -r = Reactor(Program()) - -# In addition to having a regular handler, the reactor also has a -# global handler that sees every event. By adding the Logger to the -# global handler instead of the regular handler, we can log every -# single event that occurs in the system regardless of whether or not -# there are specific handlers associated with the objects that are the -# target of those events. -r.global_handler.add(Logger()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/goodbye-world.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/goodbye-world.py b/examples/python/reactor/goodbye-world.py deleted file mode 100755 index f251c8a..0000000 --- a/examples/python/reactor/goodbye-world.py +++ /dev/null @@ -1,47 +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 -from proton.reactor import Reactor - -# So far the reactive hello-world doesn't look too different from a -# regular old non-reactive hello-world. The on_reactor_init method can -# be used roughly as a 'main' method would. A program that only uses -# that one event, however, isn't going to be very reactive. By using -# other events, we can write a fully reactive program. - -class Program: - - # As before we handle the reactor init event. - def on_reactor_init(self, event): - print("Hello, World!") - - # In addition to an initial event, the reactor also produces an - # event when it is about to exit. This may not behave much - # differently than just putting the goodbye print statement inside - # on_reactor_init, but as we grow our program, this piece of it - # will always be what happens last, and will always happen - # regardless of what other paths the main logic of our program - # might take. - def on_reactor_final(self, event): - print("Goodbye, World!") - -r = Reactor(Program()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/handlers.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/handlers.py b/examples/python/reactor/handlers.py deleted file mode 100755 index ee8d807..0000000 --- a/examples/python/reactor/handlers.py +++ /dev/null @@ -1,49 +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 World: - - def on_reactor_init(self, event): - print("World!") - -class Goodbye: - - def on_reactor_final(self, event): - print("Goodbye, World!") - -class Hello: - - def __init__(self): - # When an event dispatches itself to a handler, it also checks - # if that handler has a "handlers" attribute and dispatches - # the event to any children. - self.handlers = [World(), Goodbye()] - - # The parent handler always receives the event first. - def on_reactor_init(self, event): - print("Hello", end=' ') - -r = Reactor(Hello()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/hello-world.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/hello-world.py b/examples/python/reactor/hello-world.py deleted file mode 100755 index f1708db..0000000 --- a/examples/python/reactor/hello-world.py +++ /dev/null @@ -1,43 +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 -from proton.reactor import Reactor - -# 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!") - -# When you construct a reactor, you give it a handler. -r = Reactor(Program()) - -# When you call run, the reactor will process events. The reactor init -# event is what kicks off everything else. When the reactor has no -# more events to process, it exits. -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/reactor-logger.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/reactor-logger.py b/examples/python/reactor/reactor-logger.py deleted file mode 100755 index 2d3f9de..0000000 --- a/examples/python/reactor/reactor-logger.py +++ /dev/null @@ -1,55 +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 Logger: - - def on_unhandled(self, name, event): - print("LOG:", name, event) - -class Program: - - def on_reactor_init(self, event): - print("Hello, World!") - - def on_reactor_final(self, event): - print("Goodbye, World!") - -# You can pass multiple handlers to a reactor when you construct it. -# Each of these handlers will see every event the reactor sees. By -# combining this with on_unhandled, you can log each event that goes -# to the reactor. -r = Reactor(Program(), Logger()) -r.run() - -# Note that if you wanted to add the logger later, you could also -# write the above as below. All arguments to the reactor are just -# added to the default handler for the reactor. - -def logging_enabled(): - return False - -r = Reactor(Program()) -if logging_enabled(): - r.handler.add(Logger()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/recv.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/recv.py b/examples/python/reactor/recv.py deleted file mode 100755 index c6f07f1..0000000 --- a/examples/python/reactor/recv.py +++ /dev/null @@ -1,49 +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 -from proton import Message -from proton.reactor import Reactor -from proton.handlers import CHandshaker, CFlowController - -class Program: - - def __init__(self): - self.handlers = [CHandshaker(), CFlowController()] - self.message = Message() - - def on_reactor_init(self, event): - # Create an amqp acceptor. - event.reactor.acceptor("0.0.0.0", 5672) - # There is an optional third argument to the Reactor.acceptor - # call. Using it, we could supply a handler here that would - # become the handler for all accepted connections. If we omit - # it, the reactor simply inherets all the connection events. - - def on_delivery(self, event): - # XXX: we could make rcv.recv(self.message) work here to - # compliment the similar thing on send - rcv = event.receiver - if rcv and self.message.recv(rcv): - print(self.message) - event.delivery.settle() - -r = Reactor(Program()) -r.run() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/python/reactor/scheduling.py ---------------------------------------------------------------------- diff --git a/examples/python/reactor/scheduling.py b/examples/python/reactor/scheduling.py deleted file mode 100755 index 8956821..0000000 --- a/examples/python/reactor/scheduling.py +++ /dev/null @@ -1,52 +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: - - def on_reactor_init(self, event): - self.start = time.time() - print("Hello, World!") - - # We can schedule a task event for some point in the future. - # This will cause the reactor to stick around until it has a - # chance to process the event. - - # The first argument is the delay. The second argument is the - # handler for the event. We are just using self for now, but - # we could pass in another object if we wanted. - task = event.reactor.schedule(1.0, self) - - # We can ignore the task if we want to, but we can also use it - # to pass stuff to the handler. - task.something_to_say = "Yay" - - def on_timer_task(self, event): - task = event.context # xxx: don't have a task property on event yet - print(task.something_to_say, "my task is complete!") - - def on_reactor_final(self, event): - print("Goodbye, World! (after %s long seconds)" % (time.time() - self.start)) - -r = Reactor(Program()) -r.run() --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
