You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jr...@apache.org on 2017/09/29 00:13:04 UTC
[1/3] qpid-proton git commit: PROTON-1585: Remove messenger and
reactor examples
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: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[3/3] qpid-proton git commit: PROTON-1585: Remove messenger and
reactor examples
Posted by jr...@apache.org.
PROTON-1585: Remove messenger and reactor examples
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/db3ee828
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/db3ee828
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/db3ee828
Branch: refs/heads/master
Commit: db3ee8284fc0d43c1101feb2dcd12e3e900865db
Parents: bbeb78c
Author: Justin Ross <jr...@apache.org>
Authored: Tue Sep 26 15:42:52 2017 -0700
Committer: Justin Ross <jr...@apache.org>
Committed: Thu Sep 28 17:06:15 2017 -0700
----------------------------------------------------------------------
examples/CMakeLists.txt | 2 +-
examples/javascript/messenger/client.js | 103 --
examples/javascript/messenger/drain.js | 70 -
examples/javascript/messenger/proxy.js | 105 --
examples/javascript/messenger/qpid-config.js | 1511 -------------------
examples/javascript/messenger/recv.js | 69 -
examples/javascript/messenger/send.html | 122 --
examples/javascript/messenger/send.js | 105 --
examples/javascript/messenger/server.js | 81 -
examples/javascript/messenger/spout.js | 71 -
examples/javascript/messenger/ws2tcp.js | 166 --
examples/perl/messenger/async.pm | 120 --
examples/perl/messenger/client.pl | 105 --
examples/perl/messenger/recv.pl | 99 --
examples/perl/messenger/recv_async.pl | 84 --
examples/perl/messenger/send.pl | 88 --
examples/perl/messenger/send_async.pl | 97 --
examples/perl/messenger/server.pl | 123 --
examples/php/messenger/recv.php | 49 -
examples/php/messenger/send.php | 41 -
examples/python/messenger/README.txt | 20 -
examples/python/messenger/async.py | 82 -
examples/python/messenger/client.py | 56 -
examples/python/messenger/recv.py | 55 -
examples/python/messenger/recv_async.py | 56 -
examples/python/messenger/send.py | 45 -
examples/python/messenger/send_async.py | 64 -
examples/python/messenger/server.py | 62 -
examples/python/reactor/README.md | 34 -
examples/python/reactor/cat.py | 57 -
examples/python/reactor/count-randomly.py | 78 -
examples/python/reactor/counter.py | 61 -
examples/python/reactor/delegates.py | 49 -
examples/python/reactor/echo.py | 62 -
examples/python/reactor/global-logger.py | 59 -
examples/python/reactor/goodbye-world.py | 47 -
examples/python/reactor/handlers.py | 49 -
examples/python/reactor/hello-world.py | 43 -
examples/python/reactor/reactor-logger.py | 55 -
examples/python/reactor/recv.py | 49 -
examples/python/reactor/scheduling.py | 52 -
examples/python/reactor/send.py | 92 --
examples/python/reactor/tornado-hello-world.py | 42 -
examples/python/reactor/tornado-send.py | 84 --
examples/python/reactor/tornado_app.py | 93 --
examples/python/reactor/unhandled.py | 35 -
46 files changed, 1 insertion(+), 4691 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 45b3162..bed9f34 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -30,7 +30,7 @@ if (BUILD_CPP)
add_subdirectory(cpp)
endif()
-install(DIRECTORY c cpp go javascript perl php
+install(DIRECTORY c cpp go
DESTINATION ${PROTON_SHARE}/examples)
install(DIRECTORY python
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/client.js
----------------------------------------------------------------------
diff --git a/examples/javascript/messenger/client.js b/examples/javascript/messenger/client.js
deleted file mode 100755
index d128503..0000000
--- a/examples/javascript/messenger/client.js
+++ /dev/null
@@ -1,103 +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 client for use with server.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 subject = "UK.WEATHER";
- var replyTo = "~/replies";
- var msgtext = "Hello World!";
- var tracker = null;
-
- var message = new proton.Message();
- var messenger = new proton.Messenger();
-
- var pumpData = function() {
- while (messenger.incoming()) {
- var t = messenger.get(message);
-
- console.log("Reply:");
- console.log("Address: " + message.getAddress());
- console.log("Subject: " + message.getSubject());
-
- // body is the body as a native JavaScript Object, useful for most real cases.
- //console.log("Content: " + message.body);
-
- // data is the body as a proton.Data Object, used in this case because
- // format() returns exactly the same representation as recv.c
- console.log("Content: " + message.data.format());
-
- messenger.accept(t);
- messenger.stop();
- }
-
- 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 client.js [-r replyTo] [-s subject] <addr> (default " + address + ")");
- console.log("Options:");
- console.log(" -r <reply to> The message replyTo (default " + replyTo + ")");
- console.log(" -s <subject> The message subject (default " + subject + ")");
- 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 === '-r') {
- replyTo = val;
- } else if (arg === '-s') {
- subject = val;
- }
- } else {
- address = arg;
- }
- }
- }
-
- messenger.on('error', function(error) {console.log(error);});
- messenger.on('work', pumpData);
- messenger.setOutgoingWindow(1024);
- messenger.recv(); // Receive as many messages as messenger can buffer.
- messenger.start();
-
- message.setAddress(address);
- message.setSubject(subject);
- message.setReplyTo(replyTo);
- message.body = msgtext;
-
- tracker = messenger.put(message);
-} else {
- console.error("client.js should be run in Node.js");
-}
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/drain.js
----------------------------------------------------------------------
diff --git a/examples/javascript/messenger/drain.js b/examples/javascript/messenger/drain.js
deleted file mode 100755
index 1df6fd4..0000000
--- a/examples/javascript/messenger/drain.js
+++ /dev/null
@@ -1,70 +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("drain not implemented yet");
- process.exit(0);
-
- var address = "amqp://~0.0.0.0";
- var message = new proton.Message();
- var messenger = new proton.Messenger();
-
- var pumpData = function() {
- while (messenger.incoming()) {
- var t = messenger.get(message);
-
- console.log("Address: " + message.getAddress());
- console.log("Subject: " + message.getSubject());
-
- // body is the body as a native JavaScript Object, useful for most real cases.
- //console.log("Content: " + message.body);
-
- // data is the body as a proton.Data Object, used in this case because
- // format() returns exactly the same representation as recv.c
- console.log("Content: " + message.data.format());
-
- messenger.accept(t);
- }
- };
-
- var args = process.argv.slice(2);
- if (args.length > 0) {
- if (args[0] === '-h' || args[0] === '--help') {
- console.log("Usage: recv <addr> (default " + address + ").");
- process.exit(0);
- }
-
- address = args[0];
- }
-
- 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("drain.js should be run in Node.js");
-}
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/proxy.js
----------------------------------------------------------------------
diff --git a/examples/javascript/messenger/proxy.js b/examples/javascript/messenger/proxy.js
deleted file mode 100755
index cac5cf5..0000000
--- a/examples/javascript/messenger/proxy.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.
- *
- */
-
-/**
- * proxy.js is a simple node.js command line application that uses the ws2tcp.js
- * library to proxy from a WebSocket to a TCP Socket or vice versa.
- * <p>
- * Usage: node proxy.js [options]
- * Options:");
- * -p <listen port>, --port <listen port> (default 5673 for ws2tcp
- * 5672 for tcp2ws)
- * -t <target port>, --tport <target port> (default listen port - 1 for ws2tcp
- * listen port + 1 for tcp2ws)
- * -h <target host>, --thost <target host> (default 0.0.0.0)
- * -m <ws2tcp or tcp2ws>, --method <ws2tcp or tcp2ws> (default ws2tcp)
- * @Author Fraser Adams
- * @file
- */
-
-// Check if the environment is Node.js and if not log an error and exit.
-if (typeof process === 'object' && typeof require === 'function') {
- var proxy = require('./ws2tcp.js');
-
- var lport = 5673;
- var tport = lport - 1;
- var thost = '0.0.0.0';
- var method = 'ws2tcp';
-
- var args = process.argv.slice(2);
- if (args.length > 0) {
- if (args[0] === '-h' || args[0] === '--help') {
- console.log("Usage: node proxy.js [options]");
- console.log("Options:");
- console.log(" -p <listen port>, --port <listen port> (default " + lport + " for ws2tcp");
- console.log(" " + tport + " for tcp2ws)");
- console.log(" -t <target port>, --tport <target port> (default listen port - 1 for ws2tcp");
- console.log(" listen port + 1 for tcp2ws)");
- console.log(" -h <target host>, --thost <target host> (default " + thost + ")");
- console.log(" -m <ws2tcp or tcp2ws>, --method <ws2tcp or tcp2ws> (default " + method + ")");
- process.exit(0);
- }
-
- var lportSet = false;
- var tportSet = false;
- for (var i = 0; i < args.length; i++) {
- var arg = args[i];
- if (arg.charAt(0) === '-') {
- i++;
- var val = args[i];
- if (arg === '-p' || arg === '--port') {
- lport = val;
- lportSet = true;
- } else if (arg === '-t' || arg === '--tport') {
- tport = val;
- tportSet = true;
- } else if (arg === '-h' || arg === '--thost') {
- thost = val;
- } else if (arg === '-m' || arg === '--method') {
- method = val;
- }
- }
- }
-
- if (method === 'tcp2ws' && !lportSet) {
- lport--;
- }
-
- if (!tportSet) {
- tport = (method === 'ws2tcp') ? lport - 1 : +lport + 1;
- }
- }
-
- if (method === 'tcp2ws') {
- console.log("Proxying tcp -> ws");
- console.log("Forwarding port " + lport + " to " + thost + ":" + tport);
- proxy.tcp2ws(lport, thost, tport, 'AMQPWSB10');
- } else if (method === 'ws2tcp') {
- console.log("Proxying ws -> tcp");
- console.log("Forwarding port " + lport + " to " + thost + ":" + tport);
- proxy.ws2tcp(lport, thost, tport);
- } else {
- console.error("Method must be either ws2tcp or tcp2ws.");
- }
-} else {
- console.error("proxy.js should be run in Node.js");
-}
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/qpid-config.js
----------------------------------------------------------------------
diff --git a/examples/javascript/messenger/qpid-config.js b/examples/javascript/messenger/qpid-config.js
deleted file mode 100755
index cf7201b..0000000
--- a/examples/javascript/messenger/qpid-config.js
+++ /dev/null
@@ -1,1511 +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.
- *
- */
-
-/**
- * Port of qpid-config to JavaScript for Node.js, mainly intended as a demo to
- * illustrate using QMF2 in JavaScript using the proton.Messenger JS binding.
- * It illustrates a few things including how to use Messenger completely
- * asynchronously including using an async request/response pattern with
- * correlation IDs. It also proves interoperability of AMQP Map, List etc.
- * between C++ and JavaScript as QMF2 is pretty much all about Lists of Maps.
- * <p>
- * The actual QMF2 code is pretty simple as we're just doing a basic getObjects
- * it's made all the simpler because we can use JavaScript object literals as
- * the JavaScript binding serialises and deserialises directly between JavaScript
- * Objects and Lists and the AMQP type system so something that can be quite
- * involved in languages like C++ and Java becomes quite simple in JavaScript,
- * though the asynchronous nature of JavaScript provides its own opportunities
- * for complication best illustrated by the need for the correlator object.
- */
-
-// Check if the environment is Node.js and if not log an error and exit.
-if (typeof process === 'object' && typeof require === 'function') {
-
- var qmf = {}; // Create qmf namespace object.
- qmf.Console = function() { // qmf.Console Constructor.
- var proton = require("qpid-proton-messenger");
- var message = new proton.Message();
- var messenger = new proton.Messenger();
-
- var brokerAddress = '';
- var replyTo = '';
-
- /**
- * The correlator object is a mechanism used to correlate requests with
- * their aynchronous responses. It might possible be better to make use
- * of Promises to implement part of this behaviour but a mechanism would
- * still be needed to correlate a request with its response callback in
- * order to wrap things up in a Promise, so much of the behaviour of this
- * object would still be required. In addition it seemed to make sense to
- * make this QMF2 implementation fairly free of dependencies and using
- * Promises would require external libraries. Instead the correlator
- * implements "Promise-like" semantics, you might say a broken Promise :-)
- * <p>
- * in particular the request method behaves a *bit* like Promise.all()
- * though it is mostly fake and takes an array of functions that call
- * the add() method which is really the method used to associate response
- * objects by correlationID. The then method is used to register a
- * listener that will be called when all the requests that have been
- * registered have received responses.
- * TODO error/timeout handling.
- */
- var correlator = {
- _resolve: null,
- _objects: {},
- add: function(id) {
- this._objects[id] = {complete: false, list: null};
- },
- request: function() {
- this._resolve = function() {console.log("Warning: No resolver has been set")};
- return this;
- },
- then: function(resolver) {
- this._resolve = resolver ? resolver : this._resolve;
- },
- resolve: function() {
- var opcode = message.properties['qmf.opcode'];
- var correlationID = message.getCorrelationID();
- var resp = this._objects[correlationID];
- if (opcode === '_query_response') {
- if (resp.list) {
- Array.prototype.push.apply(resp.list, message.body); // This is faster than concat.
- } else {
- resp.list = message.body;
- }
-
- var partial = message.properties['partial'];
- if (!partial) {
- resp.complete = true;
- }
-
- this._objects[correlationID] = resp;
- this._checkComplete();
- } else if (opcode === '_method_response' || opcode === '_exception') {
- resp.list = message.body;
- resp.complete = true;
- this._objects[correlationID] = resp;
- this._checkComplete();
- } else {
- console.error("Bad Message response, qmf.opcode = " + opcode);
- }
- },
- _checkComplete: function() {
- var response = {};
- for (var id in this._objects) {
- var object = this._objects[id];
- if (object.complete) {
- response[id] = object.list;
- } else {
- return;
- }
- }
-
- this._objects = {}; // Clear state ready for next call.
- this._resolve(response.method ? response.method : response);
- }
- }; // End of correlator object definition.
-
- var pumpData = function() {
- while (messenger.incoming()) {
- // The second parameter forces Binary payloads to be decoded as
- // strings this is useful because the broker QMF Agent encodes
- // strings as AMQP binary unfortunately.
- var t = messenger.get(message, true);
- correlator.resolve();
- messenger.accept(t);
- }
-
- if (messenger.isStopped()) {
- message.free();
- messenger.free();
- }
- };
-
- this.getObjects = function(packageName, className) {
- message.setAddress(brokerAddress);
- message.setSubject('broker');
- message.setReplyTo(replyTo);
- message.setCorrelationID(className);
- message.properties = {
- "routing-key": "broker", // Added for Java Broker
- "x-amqp-0-10.app-id": "qmf2",
- "method": "request",
- "qmf.opcode": "_query_request",
- };
- message.body = {
- "_what": "OBJECT",
- "_schema_id": {
- "_package_name": packageName,
- "_class_name": className
- }
- };
-
- correlator.add(className);
- messenger.put(message);
- };
-
- this.invokeMethod = function(object, method, arguments) {
- var correlationID = 'method';
- message.setAddress(brokerAddress);
- message.setSubject('broker');
- message.setReplyTo(replyTo);
- message.setCorrelationID(correlationID);
- message.properties = {
- "routing-key": "broker", // Added for Java Broker
- "x-amqp-0-10.app-id": "qmf2",
- "method": "request",
- "qmf.opcode": "_method_request",
- };
- message.body = {
- "_object_id": object._object_id,
- "_method_name" : method,
- "_arguments" : arguments
- };
-
- correlator.add(correlationID);
- messenger.put(message);
- };
-
- this.addConnection = function(addr, callback) {
- brokerAddress = addr + '/qmf.default.direct';
- var replyAddress = addr + '/#';
-
- messenger.on('subscription', function(subscription) {
- var subscriptionAddress = subscription.getAddress();
- var splitAddress = subscriptionAddress.split('/');
- replyTo = splitAddress[splitAddress.length - 1];
- callback();
- });
-
- messenger.subscribe(replyAddress);
- }
-
- this.destroy = function() {
- messenger.stop();
- }
-
- this.request = function() {return correlator.request();}
-
- messenger.on('error', function(error) {console.log(error);});
- messenger.on('work', pumpData);
- messenger.setOutgoingWindow(1024);
- messenger.recv(); // Receive as many messages as messenger can buffer.
- messenger.start();
- }; // End of qmf.Console
-
-/************************* qpid-config business logic ************************/
-
- var brokerAgent = new qmf.Console();
-
- var _usage =
- 'Usage: qpid-config [OPTIONS]\n' +
- ' qpid-config [OPTIONS] exchanges [filter-string]\n' +
- ' qpid-config [OPTIONS] queues [filter-string]\n' +
- ' qpid-config [OPTIONS] add exchange <type> <name> [AddExchangeOptions]\n' +
- ' qpid-config [OPTIONS] del exchange <name>\n' +
- ' qpid-config [OPTIONS] add queue <name> [AddQueueOptions]\n' +
- ' qpid-config [OPTIONS] del queue <name> [DelQueueOptions]\n' +
- ' qpid-config [OPTIONS] bind <exchange-name> <queue-name> [binding-key]\n' +
- ' <for type xml> [-f -|filename]\n' +
- ' <for type header> [all|any] k1=v1 [, k2=v2...]\n' +
- ' qpid-config [OPTIONS] unbind <exchange-name> <queue-name> [binding-key]\n' +
- ' qpid-config [OPTIONS] reload-acl\n' +
- ' qpid-config [OPTIONS] add <type> <name> [--argument <property-name>=<property-value>]\n' +
- ' qpid-config [OPTIONS] del <type> <name>\n' +
- ' qpid-config [OPTIONS] list <type> [--show-property <property-name>]\n';
-
- var usage = function() {
- console.log(_usage);
- process.exit(-1);
- };
-
- var _description =
- 'Examples:\n' +
- '\n' +
- '$ qpid-config add queue q\n' +
- '$ qpid-config add exchange direct d -a localhost:5672\n' +
- '$ qpid-config exchanges -b 10.1.1.7:10000\n' +
- '$ qpid-config queues -b guest/guest@broker-host:10000\n' +
- '\n' +
- 'Add Exchange <type> values:\n' +
- '\n' +
- ' direct Direct exchange for point-to-point communication\n' +
- ' fanout Fanout exchange for broadcast communication\n' +
- ' topic Topic exchange that routes messages using binding keys with wildcards\n' +
- ' headers Headers exchange that matches header fields against the binding keys\n' +
- ' xml XML Exchange - allows content filtering using an XQuery\n' +
- '\n' +
- '\n' +
- 'Queue Limit Actions:\n' +
- '\n' +
- ' none (default) - Use broker\'s default policy\n' +
- ' reject - Reject enqueued messages\n' +
- ' ring - Replace oldest unacquired message with new\n' +
- '\n' +
- 'Replication levels:\n' +
- '\n' +
- ' none - no replication\n' +
- ' configuration - replicate queue and exchange existence and bindings, but not messages.\n' +
- ' all - replicate configuration and messages\n';
-
- var _options =
- 'Options:\n' +
- ' -h, --help show this help message and exit\n' +
- '\n' +
- ' General Options:\n' +
- ' -t <secs>, --timeout=<secs>\n' +
- ' Maximum time to wait for broker connection (in\n' +
- ' seconds)\n' +
- ' -r, --recursive Show bindings in queue or exchange list\n' +
- ' -b <address>, --broker=<address>\n' +
- ' Address of qpidd broker with syntax:\n' +
- ' [username/password@] hostname | ip-address [:<port>]\n' +
- ' -a <address>, --broker-addr=<address>\n' +
- /* TODO Connection options
- ' --sasl-mechanism=<mech>\n' +
- ' SASL mechanism for authentication (e.g. EXTERNAL,\n' +
- ' ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n' +
- ' automatically picks the most secure available\n' +
- ' mechanism - use this option to override.\n' +
- ' --ssl-certificate=<cert>\n' +
- ' Client SSL certificate (PEM Format)\n' +
- ' --ssl-key=<key> Client SSL private key (PEM Format)\n' +
- ' --ha-admin Allow connection to a HA backup broker.\n' +
- */
- '\n' +
- ' Options for Listing Exchanges and Queues:\n' +
- ' --ignore-default Ignore the default exchange in exchange or queue list\n' +
- '\n' +
- ' Options for Adding Exchanges and Queues:\n' +
- ' --alternate-exchange=<aexname>\n' +
- ' Name of the alternate-exchange for the new queue or\n' +
- ' exchange. Exchanges route messages to the alternate\n' +
- ' exchange if they are unable to route them elsewhere.\n' +
- ' Queues route messages to the alternate exchange if\n' +
- ' they are rejected by a subscriber or orphaned by queue\n' +
- ' deletion.\n' +
- ' --durable The new queue or exchange is durable.\n' +
- ' --replicate=<level>\n' +
- ' Enable automatic replication in a HA cluster. <level>\n' +
- ' is \'none\', \'configuration\' or \'all\').\n' +
- '\n' +
- ' Options for Adding Queues:\n' +
- ' --file-count=<n> Number of files in queue\'s persistence journal\n' +
- ' --file-size=<n> File size in pages (64KiB/page)\n' +
- ' --max-queue-size=<n>\n' +
- ' Maximum in-memory queue size as bytes\n' +
- ' --max-queue-count=<n>\n' +
- ' Maximum in-memory queue size as a number of messages\n' +
- ' --limit-policy=<policy>\n' +
- ' Action to take when queue limit is reached\n' +
- ' --lvq-key=<key> Last Value Queue key\n' +
- ' --generate-queue-events=<n>\n' +
- ' If set to 1, every enqueue will generate an event that\n' +
- ' can be processed by registered listeners (e.g. for\n' +
- ' replication). If set to 2, events will be generated\n' +
- ' for enqueues and dequeues.\n' +
- ' --flow-stop-size=<n>\n' +
- ' Turn on sender flow control when the number of queued\n' +
- ' bytes exceeds this value.\n' +
- ' --flow-resume-size=<n>\n' +
- ' Turn off sender flow control when the number of queued\n' +
- ' bytes drops below this value.\n' +
- ' --flow-stop-count=<n>\n' +
- ' Turn on sender flow control when the number of queued\n' +
- ' messages exceeds this value.\n' +
- ' --flow-resume-count=<n>\n' +
- ' Turn off sender flow control when the number of queued\n' +
- ' messages drops below this value.\n' +
- ' --group-header=<header-name>\n' +
- ' Enable message groups. Specify name of header that\n' +
- ' holds group identifier.\n' +
- ' --shared-groups Allow message group consumption across multiple\n' +
- ' consumers.\n' +
- ' --argument=<NAME=VALUE>\n' +
- ' Specify a key-value pair to add to queue arguments\n' +
- ' --start-replica=<broker-url>\n' +
- ' Start replication from the same-named queue at\n' +
- ' <broker-url>\n' +
- '\n' +
- ' Options for Adding Exchanges:\n' +
- ' --sequence Exchange will insert a \'qpid.msg_sequence\' field in\n' +
- ' the message header\n' +
- ' --ive Exchange will behave as an \'initial-value-exchange\',\n' +
- ' keeping a reference to the last message forwarded and\n' +
- ' enqueuing that message to newly bound queues.\n' +
- '\n' +
- ' Options for Deleting Queues:\n' +
- ' --force Force delete of queue even if it\'s currently used or\n' +
- ' it\'s not empty\n' +
- ' --force-if-not-empty\n' +
- ' Force delete of queue even if it\'s not empty\n' +
- ' --force-if-used Force delete of queue even if it\'s currently used\n' +
- '\n' +
- ' Options for Declaring Bindings:\n' +
- ' -f <file.xq>, --file=<file.xq>\n' +
- ' For XML Exchange bindings - specifies the name of a\n' +
- ' file containing an XQuery.\n' +
- '\n' +
- ' Formatting options for \'list\' action:\n' +
- ' --show-property=<property-name>\n' +
- ' Specify a property of an object to be included in\n' +
- ' output\n';
-
- var REPLICATE_LEVELS = {"none" : true, "configuration": true, "all": true};
- var DEFAULT_PROPERTIES = {"exchange": {"name": true, "type": true, "durable": true},
- "queue": {"name": true, "durable": true, "autoDelete": true}};
-
- var getValue = function(r) {
- var value = null;
- if (r.length === 2) {
- value = r[1];
- if (!isNaN(value)) {
- value = parseInt(value);
- }
- }
-
- return value;
- };
-
- var config = {
- _recursive : false,
- _host : 'guest:guest@localhost:5673', // Note 5673 not 5672 as we use WebSocket transport.
- _connTimeout : 10,
- _ignoreDefault : false,
- _altern_ex : null,
- _durable : false,
- _replicate : null,
- _if_empty : true,
- _if_unused : true,
- _fileCount : null,
- _fileSize : null,
- _maxQueueSize : null,
- _maxQueueCount : null,
- _limitPolicy : null,
- _msgSequence : false,
- _lvq_key : null,
- _ive : null,
- _eventGeneration: null,
- _file : null,
- _flowStopCount : null,
- _flowResumeCount: null,
- _flowStopSize : null,
- _flowResumeSize : null,
- _msgGroupHeader : null,
- _sharedMsgGroup : false,
- _extra_arguments: [],
- _start_replica : null,
- _returnCode : 0,
- _list_properties: null,
-
- getOptions: function() {
- var options = {};
- for (var a = 0; a < this._extra_arguments.length; a++) {
- var r = this._extra_arguments[a].split('=');
- options[r[0]] = getValue(r);
- }
- return options;
- }
- };
-
- var FILECOUNT = 'qpid.file_count';
- var FILESIZE = 'qpid.file_size';
- var MAX_QUEUE_SIZE = 'qpid.max_size';
- var MAX_QUEUE_COUNT = 'qpid.max_count';
- var POLICY_TYPE = 'qpid.policy_type';
- var LVQ_KEY = 'qpid.last_value_queue_key';
- var MSG_SEQUENCE = 'qpid.msg_sequence';
- var IVE = 'qpid.ive';
- var QUEUE_EVENT_GENERATION = 'qpid.queue_event_generation';
- var FLOW_STOP_COUNT = 'qpid.flow_stop_count';
- var FLOW_RESUME_COUNT = 'qpid.flow_resume_count';
- var FLOW_STOP_SIZE = 'qpid.flow_stop_size';
- var FLOW_RESUME_SIZE = 'qpid.flow_resume_size';
- var MSG_GROUP_HDR_KEY = 'qpid.group_header_key';
- var SHARED_MSG_GROUP = 'qpid.shared_msg_group';
- var REPLICATE = 'qpid.replicate';
-
- /**
- * There are various arguments to declare that have specific program
- * options in this utility. However there is now a generic mechanism for
- * passing arguments as well. The SPECIAL_ARGS list contains the
- * arguments for which there are specific program options defined
- * i.e. the arguments for which there is special processing on add and
- * list
- */
- var SPECIAL_ARGS={};
- SPECIAL_ARGS[FILECOUNT] = true;
- SPECIAL_ARGS[FILESIZE] = true;
- SPECIAL_ARGS[MAX_QUEUE_SIZE] = true;
- SPECIAL_ARGS[MAX_QUEUE_COUNT] = true;
- SPECIAL_ARGS[POLICY_TYPE] = true;
- SPECIAL_ARGS[LVQ_KEY] = true;
- SPECIAL_ARGS[MSG_SEQUENCE] = true;
- SPECIAL_ARGS[IVE] = true;
- SPECIAL_ARGS[QUEUE_EVENT_GENERATION] = true;
- SPECIAL_ARGS[FLOW_STOP_COUNT] = true;
- SPECIAL_ARGS[FLOW_RESUME_COUNT] = true;
- SPECIAL_ARGS[FLOW_STOP_SIZE] = true;
- SPECIAL_ARGS[FLOW_RESUME_SIZE] = true;
- SPECIAL_ARGS[MSG_GROUP_HDR_KEY] = true;
- SPECIAL_ARGS[SHARED_MSG_GROUP] = true;
- SPECIAL_ARGS[REPLICATE] = true;
-
- // Returns a String representation of an ObjectID.
- var oid = function(id) {
- return id._agent_epoch + ':' + id._object_name
- };
-
- // Check if the supplied name contains the supplied filter String.
- var filterMatch = function(name, filter) {
- if (filter === '') {
- return true;
- }
- if (name.indexOf(filter) === -1) {
- return false;
- }
- return true;
- };
-
- // Take the supplied List of QMF2 Objects and return a Map keyed by ObjectID.
- var idMap = function(list) {
- var map = {};
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- map[oid(item._object_id)] = item;
- }
- return map;
- };
-
- // Pretty-print the supplied Object.
- var renderObject = function(obj, list) {
- if (!obj) {
- return '';
- }
- var string = '';
- var addComma = false;
- for (var prop in obj) {
- if (addComma) {
- string += ', ';
- }
- if (obj.hasOwnProperty(prop)) {
- if (list) {
- if (SPECIAL_ARGS[prop]) continue;
- string += " --argument " + prop + "=" + obj[prop];
- } else {
- string += "'" + prop + "'" + ": '" + obj[prop] + "'";
- addComma = true;
- }
- }
- }
-
- if (addComma) {
- return '{' + string + '}';
- } else {
- if (list) {
- return string;
- } else {
- return '';
- }
- }
- };
-
- /**
- * The following methods illustrate the QMF2 class query mechanism which returns
- * the list of QMF Objects for the specified class that are currently present
- * on the Broker. The Schema <qpid>/cpp/src/qpid/broker/management-schema.xml
- * describes the properties and statistics of each Management Object.
- * <p>
- * One slightly subtle part of QMF is that certain Objects are associated via
- * references, for example Binding contains queueRef and exchangeRef, which lets
- * Objects link to each other using their _object_id property.
- * <p>
- * The implementation of these methods attempts to follow the same general flow
- * as the equivalent method in the "canonical" python based qpid-config version
- * but has the added complication that JavaScript is entirely asynchronous.
- * The approach that has been taken is to use the correlator object that lets a
- * callback function be registered via the "then" method and actually calls the
- * callback when all of the requests specified in the request method have
- * returned their results (which get passed as the callback parameter).
- */
-
- var overview = function() {
- brokerAgent.request(
- // Send the QMF query requests for the specified classes.
- brokerAgent.getObjects('org.apache.qpid.broker', 'queue'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'exchange')
- ).then(function(objects) {
- var exchanges = objects.exchange;
- var queues = objects.queue;
- console.log("Total Exchanges: " + exchanges.length);
- var etype = {};
- for (var i = 0; i < exchanges.length; i++) {
- var exchange = exchanges[i]._values;
- if (!etype[exchange.type]) {
- etype[exchange.type] = 1;
- } else {
- etype[exchange.type]++;
- }
- }
- for (var typ in etype) {
- var pad = Array(16 - typ.length).join(' ');
- console.log(pad + typ + ": " + etype[typ]);
- }
-
- console.log("\n Total Queues: " + queues.length);
- var durable = 0;
- for (var i = 0; i < queues.length; i++) {
- var queue = queues[i]._values;
- if (queue.durable) {
- durable++;
- }
- }
- console.log(" durable: " + durable);
- console.log(" non-durable: " + (queues.length - durable));
- brokerAgent.destroy();
- });
- };
-
- var exchangeList = function(filter) {
- brokerAgent.request(
- // Send the QMF query requests for the specified classes.
- brokerAgent.getObjects('org.apache.qpid.broker', 'exchange')
- ).then(function(objects) {
- var exchanges = objects.exchange;
- var exMap = idMap(exchanges);
- var caption1 = "Type ";
- var caption2 = "Exchange Name";
- var maxNameLen = caption2.length;
- var found = false;
- for (var i = 0; i < exchanges.length; i++) {
- var exchange = exchanges[i]._values;
- if (filterMatch(exchange.name, filter)) {
- if (exchange.name.length > maxNameLen) {
- maxNameLen = exchange.name.length;
- }
- found = true;
- }
- }
- if (!found) {
- config._returnCode = 1;
- return;
- }
-
- var pad = Array(maxNameLen + 1 - caption2.length).join(' ');
- console.log(caption1 + caption2 + pad + " Attributes");
- console.log(Array(maxNameLen + caption1.length + 13).join('='));
-
- for (var i = 0; i < exchanges.length; i++) {
- var exchange = exchanges[i]._values;
- if (config._ignoreDefault && !exchange.name) continue;
- if (filterMatch(exchange.name, filter)) {
- var pad1 = Array(11 - exchange.type.length).join(' ');
- var pad2 = Array(maxNameLen + 2 - exchange.name.length).join(' ');
- var string = exchange.type + pad1 + exchange.name + pad2;
- var args = exchange.arguments ? exchange.arguments : {};
- if (exchange.durable) {
- string += ' --durable';
- }
- if (args[REPLICATE]) {
- string += ' --replicate=' + args[REPLICATE];
- }
- if (args[MSG_SEQUENCE]) {
- string += ' --sequence';
- }
- if (args[IVE]) {
- string += ' --ive';
- }
- if (exchange.altExchange) {
- string += ' --alternate-exchange=' + exMap[oid(exchange.altExchange)]._values.name;
- }
- console.log(string);
- }
- }
- brokerAgent.destroy();
- });
- };
-
- var exchangeListRecurse = function(filter) {
- brokerAgent.request(
- // Send the QMF query requests for the specified classes.
- brokerAgent.getObjects('org.apache.qpid.broker', 'queue'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'exchange'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'binding')
- ).then(function(objects) {
- var exchanges = objects.exchange;
- var bindings = objects.binding;
- var queues = idMap(objects.queue);
-
- for (var i = 0; i < exchanges.length; i++) {
- var exchange = exchanges[i];
- var exchangeId = oid(exchange._object_id);
- exchange = exchange._values;
-
- if (config._ignoreDefault && !exchange.name) continue;
- if (filterMatch(exchange.name, filter)) {
- console.log("Exchange '" + exchange.name + "' (" + exchange.type + ")");
- for (var j = 0; j < bindings.length; j++) {
- var bind = bindings[j]._values;
- var exchangeRef = oid(bind.exchangeRef);
-
- if (exchangeRef === exchangeId) {
- var queue = queues[oid(bind.queueRef)];
- var queueName = queue ? queue._values.name : "<unknown>";
- console.log(" bind [" + bind.bindingKey + "] => " + queueName +
- " " + renderObject(bind.arguments));
- }
- }
- }
- }
- brokerAgent.destroy();
- });
- };
-
- var queueList = function(filter) {
- brokerAgent.request(
- // Send the QMF query requests for the specified classes.
- brokerAgent.getObjects('org.apache.qpid.broker', 'queue'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'exchange')
- ).then(function(objects) {
- var queues = objects.queue;
- var exMap = idMap(objects.exchange);
- var caption = "Queue Name";
- var maxNameLen = caption.length;
- var found = false;
- for (var i = 0; i < queues.length; i++) {
- var queue = queues[i]._values;
- if (filterMatch(queue.name, filter)) {
- if (queue.name.length > maxNameLen) {
- maxNameLen = queue.name.length;
- }
- found = true;
- }
- }
- if (!found) {
- config._returnCode = 1;
- return;
- }
-
- var pad = Array(maxNameLen + 1 - caption.length).join(' ');
- console.log(caption + pad + " Attributes");
- console.log(Array(maxNameLen + caption.length + 3).join('='));
-
- for (var i = 0; i < queues.length; i++) {
- var queue = queues[i]._values;
- if (filterMatch(queue.name, filter)) {
- var pad2 = Array(maxNameLen + 2 - queue.name.length).join(' ');
- var string = queue.name + pad2;
- var args = queue.arguments ? queue.arguments : {};
- if (queue.durable) {
- string += ' --durable';
- }
- if (args[REPLICATE]) {
- string += ' --replicate=' + args[REPLICATE];
- }
- if (queue.autoDelete) {
- string += ' auto-del';
- }
- if (queue.exclusive) {
- string += ' excl';
- }
- if (args[FILESIZE]) {
- string += ' --file-size=' + args[FILESIZE];
- }
- if (args[FILECOUNT]) {
- string += ' --file-count=' + args[FILECOUNT];
- }
- if (args[MAX_QUEUE_SIZE]) {
- string += ' --max-queue-size=' + args[MAX_QUEUE_SIZE];
- }
- if (args[MAX_QUEUE_COUNT]) {
- string += ' --max-queue-count=' + args[MAX_QUEUE_COUNT];
- }
- if (args[POLICY_TYPE]) {
- string += ' --limit-policy=' + args[POLICY_TYPE].replace("_", "-");
- }
- if (args[LVQ_KEY]) {
- string += ' --lvq-key=' + args[LVQ_KEY];
- }
- if (args[QUEUE_EVENT_GENERATION]) {
- string += ' --generate-queue-events=' + args[QUEUE_EVENT_GENERATION];
- }
- if (queue.altExchange) {
- string += ' --alternate-exchange=' + exMap[oid(queue.altExchange)]._values.name;
- }
- if (args[FLOW_STOP_SIZE]) {
- string += ' --flow-stop-size=' + args[FLOW_STOP_SIZE];
- }
- if (args[FLOW_RESUME_SIZE]) {
- string += ' --flow-resume-size=' + args[FLOW_RESUME_SIZE];
- }
- if (args[FLOW_STOP_COUNT]) {
- string += ' --flow-stop-count=' + args[FLOW_STOP_COUNT];
- }
- if (args[FLOW_RESUME_COUNT]) {
- string += ' --flow-resume-count=' + args[FLOW_RESUME_COUNT];
- }
- if (args[MSG_GROUP_HDR_KEY]) {
- string += ' --group-header=' + args[MSG_GROUP_HDR_KEY];
- }
- if (args[SHARED_MSG_GROUP] === 1) {
- string += ' --shared-groups';
- }
- string += ' ' + renderObject(args, true);
- console.log(string);
- }
- }
- brokerAgent.destroy();
- });
- };
-
- var queueListRecurse = function(filter) {
- brokerAgent.request(
- // Send the QMF query requests for the specified classes.
- brokerAgent.getObjects('org.apache.qpid.broker', 'queue'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'exchange'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'binding')
- ).then(function(objects) {
- var queues = objects.queue;
- var bindings = objects.binding;
- var exchanges = idMap(objects.exchange);
-
- for (var i = 0; i < queues.length; i++) {
- var queue = queues[i];
- var queueId = oid(queue._object_id);
- queue = queue._values;
-
- if (filterMatch(queue.name, filter)) {
- console.log("Queue '" + queue.name + "'");
- for (var j = 0; j < bindings.length; j++) {
- var bind = bindings[j]._values;
- var queueRef = oid(bind.queueRef);
-
- if (queueRef === queueId) {
- var exchange = exchanges[oid(bind.exchangeRef)];
- var exchangeName = "<unknown>";
- if (exchange) {
- exchangeName = exchange._values.name;
- if (exchangeName === '') {
- if (config._ignoreDefault) continue;
- exchangeName = "''";
- }
- }
-
- console.log(" bind [" + bind.bindingKey + "] => " + exchangeName +
- " " + renderObject(bind.arguments));
- }
- }
- }
- }
- brokerAgent.destroy();
- });
- };
-
- /**
- * The following methods implement adding and deleting various Broker Management
- * Objects via QMF. Although <qpid>/cpp/src/qpid/broker/management-schema.xml
- * describes the basic method schema, for example:
- * <method name="create" desc="Create an object of the specified type">
- * <arg name="type" dir="I" type="sstr" desc="The type of object to create"/>
- * <arg name="name" dir="I" type="sstr" desc="The name of the object to create"/>
- * <arg name="properties" dir="I" type="map" desc="Type specific object properties"/>
- * <arg name="strict" dir="I" type="bool" desc="If specified, treat unrecognised object properties as an error"/ >
- * </method>
- *
- * <method name="delete" desc="Delete an object of the specified type">
- * <arg name="type" dir="I" type="sstr" desc="The type of object to delete"/>
- * <arg name="name" dir="I" type="sstr" desc="The name of the object to delete"/>
- * <arg name="options" dir="I" type="map" desc="Type specific object options for deletion"/>
- * </method>
- *
- * What the schema doesn't do however is to explain what the properties/options
- * Map values actually mean, unfortunately these aren't documented anywhere so
- * the only option is to look in the code, the best place to look is in:
- * <qpid>/cpp/src/qpid/broker/Broker.cpp, the method Broker::ManagementMethod is
- * the best place to start, then Broker::createObject and Broker::deleteObject
- * even then it's pretty hard to figure out all that is possible.
- */
-
- var handleMethodResponse = function(response, dontStop) {
- if (response._arguments) {
- //console.log(response._arguments);
- } if (response._values) {
- console.error("Exception from Agent: " + renderObject(response._values));
- }
- // Mostly we want to stop the Messenger Event loop and exit when a QMF method
- // returns, but sometimes we don't, the dontStop flag prevents this behaviour.
- if (!dontStop) {
- brokerAgent.destroy();
- }
- }
-
- var addExchange = function(args) {
- if (args.length < 2) {
- usage();
- }
-
- var etype = args[0];
- var ename = args[1];
- var declArgs = {};
-
- declArgs['exchange-type'] = etype;
-
- for (var a = 0; a < config._extra_arguments.length; a++) {
- var r = config._extra_arguments[a].split('=');
- declArgs[r[0]] = getValue(r);
- }
-
- if (config._msgSequence) {
- declArgs[MSG_SEQUENCE] = 1;
- }
-
- if (config._ive) {
- declArgs[IVE] = 1;
- }
-
- if (config._altern_ex) {
- declArgs['alternate-exchange'] = config._altern_ex;
- }
-
- if (config._durable) {
- declArgs['durable'] = 1;
- }
-
- if (config._replicate) {
- declArgs[REPLICATE] = config._replicate;
- }
-
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(broker, 'create', {
- "type": "exchange",
- "name": ename,
- "properties": declArgs,
- "strict": true})
- ).then(handleMethodResponse);
- });
- };
-
- var delExchange = function(args) {
- if (args.length < 1) {
- usage();
- }
-
- var ename = args[0];
-
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(broker, 'delete', {
- "type": "exchange",
- "name": ename})
- ).then(handleMethodResponse);
- });
- };
-
- var addQueue = function(args) {
- if (args.length < 1) {
- usage();
- }
-
- var qname = args[0];
- var declArgs = {};
-
- for (var a = 0; a < config._extra_arguments.length; a++) {
- var r = config._extra_arguments[a].split('=');
- declArgs[r[0]] = getValue(r);
- }
-
- if (config._durable) {
- // allow the default fileCount and fileSize specified
- // in qpid config file to take prededence
- if (config._fileCount) {
- declArgs[FILECOUNT] = config._fileCount;
- }
- if (config._fileSize) {
- declArgs[FILESIZE] = config._fileSize;
- }
- }
-
- if (config._maxQueueSize != null) {
- declArgs[MAX_QUEUE_SIZE] = config._maxQueueSize;
- }
-
- if (config._maxQueueCount != null) {
- declArgs[MAX_QUEUE_COUNT] = config._maxQueueCount;
- }
-
- if (config._limitPolicy) {
- if (config._limitPolicy === 'none') {
- } else if (config._limitPolicy === 'reject') {
- declArgs[POLICY_TYPE] = 'reject';
- } else if (config._limitPolicy === 'ring') {
- declArgs[POLICY_TYPE] = 'ring';
- }
- }
-
- if (config._lvq_key) {
- declArgs[LVQ_KEY] = config._lvq_key;
- }
-
- if (config._eventGeneration) {
- declArgs[QUEUE_EVENT_GENERATION] = config._eventGeneration;
- }
-
- if (config._flowStopSize != null) {
- declArgs[FLOW_STOP_SIZE] = config._flowStopSize;
- }
-
- if (config._flowResumeSize != null) {
- declArgs[FLOW_RESUME_SIZE] = config._flowResumeSize;
- }
-
- if (config._flowStopCount != null) {
- declArgs[FLOW_STOP_COUNT] = config._flowStopCount;
- }
-
- if (config._flowResumeCount != null) {
- declArgs[FLOW_RESUME_COUNT] = config._flowResumeCount;
- }
-
- if (config._msgGroupHeader) {
- declArgs[MSG_GROUP_HDR_KEY] = config._msgGroupHeader;
- }
-
- if (config._sharedMsgGroup) {
- declArgs[SHARED_MSG_GROUP] = 1;
- }
-
- if (config._altern_ex) {
- declArgs['alternate-exchange'] = config._altern_ex;
- }
-
- if (config._durable) {
- declArgs['durable'] = 1;
- }
-
- if (config._replicate) {
- declArgs[REPLICATE] = config._replicate;
- }
-
- // This block is a little complex and untidy, the real issue is that the
- // correlator object isn't as good as a real Promise and doesn't support
- // chaining of "then" calls, so where we have complex dependencies we still
- // get somewhat into "callback hell". TODO improve the correlator.
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(broker, 'create', {
- "type": "queue",
- "name": qname,
- "properties": declArgs,
- "strict": true})
- ).then(function(response) {
- if (config._start_replica) {
- handleMethodResponse(response, true); // The second parameter prevents exiting.
- // TODO test this stuff!
- brokerAgent.request(
- brokerAgent.getObjects('org.apache.qpid.ha', 'habroker') // Not sure if this is correct
- ).then(function(objects) {
- if (objects.habroker.length > 0) {
- var habroker = objects.habroker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(habroker, 'replicate', {
- "broker": config._start_replica,
- "queue": qname})
- ).then(handleMethodResponse);
- } else {
- brokerAgent.destroy();
- }
- });
- } else {
- handleMethodResponse(response);
- }
- });
- });
- };
-
- var delQueue = function(args) {
- if (args.length < 1) {
- usage();
- }
-
- var qname = args[0];
-
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(broker, 'delete', {
- "type": "queue",
- "name": qname,
- "options": {"if_empty": config._if_empty,
- "if_unused": config._if_unused}})
- ).then(handleMethodResponse);
- });
- };
-
- var snarf_header_args = function(args) {
- if (args.length < 2) {
- console.log("Invalid args to bind headers: need 'any'/'all' plus conditions");
- return false;
- }
-
- var op = args[0];
- if (op === 'all' || op === 'any') {
- kv = {};
- var bindings = Array.prototype.slice.apply(args, [1]);
- for (var i = 0; i < bindings.length; i++) {
- var binding = bindings[i];
- binding = binding.split(",")[0];
- binding = binding.split("=");
- kv[binding[0]] = binding[1];
- }
- kv['x-match'] = op;
- return kv;
- } else {
- console.log("Invalid condition arg to bind headers, need 'any' or 'all', not '" + op + "'");
- return false;
- }
- };
-
- var bind = function(args) {
- if (args.length < 2) {
- usage();
- }
-
- var ename = args[0];
- var qname = args[1];
- var key = '';
-
- if (args.length > 2) {
- key = args[2];
- }
-
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker'),
- brokerAgent.getObjects('org.apache.qpid.broker', 'exchange') // Get exchanges to look up exchange type.
- ).then(function(objects) {
- var exchanges = objects.exchange;
-
- var etype = '';
- for (var i = 0; i < exchanges.length; i++) {
- var exchange = exchanges[i]._values;
- if (exchange.name === ename) {
- etype = exchange.type;
- break;
- }
- }
-
- // type of the xchg determines the processing of the rest of
- // argv. if it's an xml xchg, we want to find a file
- // containing an x-query, and pass that. if it's a headers
- // exchange, we need to pass either "any" or all, followed by a
- // map containing key/value pairs. if neither of those, extra
- // args are ignored.
- var declArgs = {};
- if (etype === 'xml') {
-
-
- } else if (etype === 'headers') {
- declArgs = snarf_header_args(Array.prototype.slice.apply(args, [3]));
- }
- //console.log(declArgs);
-
- if (typeof declArgs !== 'object') {
- process.exit(1);
- }
-
- var broker = objects.broker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(broker, 'create', {
- "type": "binding",
- "name": ename + '/' + qname + '/' + key,
- "properties": declArgs,
- "strict": true})
- ).then(handleMethodResponse);
- });
-
- /*
-
- ok = True
- _args = {}
- if not res:
- pass
- elif res.type == "xml":
- # this checks/imports the -f arg
- [ok, xquery] = snarf_xquery_args()
- _args = { "xquery" : xquery }
- else:
- if res.type == "headers":
- [ok, op, kv] = snarf_header_args(args[3:])
- _args = kv
- _args["x-match"] = op
-
- if not ok:
- sys.exit(1)
-
- self.broker.bind(ename, qname, key, _args)
- */
-
- };
-
- var unbind = function(args) {
- if (args.length < 2) {
- usage();
- }
-
- var ename = args[0];
- var qname = args[1];
- var key = '';
-
- if (args.length > 2) {
- key = args[2];
- }
-
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- brokerAgent.invokeMethod(broker, 'delete', {
- "type": "binding",
- "name": ename + '/' + qname + '/' + key})
- ).then(handleMethodResponse);
- });
- };
-
- /**
- * The following methods are "generic" create and delete methods to for arbitrary
- * Management Objects e.g. Incoming, Outgoing, Domain, Topic, QueuePolicy,
- * TopicPolicy etc. use --argument k1=v1 --argument k2=v2 --argument k3=v3 to
- * pass arbitrary arguments as key/value pairs to the Object being created/deleted,
- * for example to add a topic object that uses the fanout exchange:
- * ./qpid-config.js add topic fanout --argument exchange=amq.fanout \
- * --argument qpid.max_size=1000000 --argument qpid.policy_type=ring
- */
-
- var createObject = function(type, name, args) {
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- // Create an object of the specified type.
- brokerAgent.invokeMethod(broker, 'create', {
- "type": type,
- "name": name,
- "properties": args,
- "strict": true})
- ).then(handleMethodResponse);
- });
- };
-
- var deleteObject = function(type, name, args) {
- brokerAgent.request(
- // We invoke the CRUD methods on the broker object.
- brokerAgent.getObjects('org.apache.qpid.broker', 'broker')
- ).then(function(objects) {
- var broker = objects.broker[0];
- brokerAgent.request(
- // Create an object of the specified type and name.
- brokerAgent.invokeMethod(broker, 'delete', {
- "type": type,
- "name": name,
- "options": args})
- ).then(handleMethodResponse);
- });
- };
-
- /**
- * This is a "generic" mechanism for listing arbitrary Management Objects.
- */
- var listObjects = function(type) {
- brokerAgent.request(
- brokerAgent.getObjects('org.apache.qpid.broker', type)
- ).then(function(objects) {
- // The correlator passes an object containing responses for all of the
- // supplied requests so we index it by the supplied type to get our response.
- objects = objects[type];
-
- // Collect available attributes, stringify the values and compute the max
- // length of the value of each attribute so that we can later create a table.
- var attributes = {};
- var lengths = {};
- for (var i = 0; i < objects.length; i++) {
- var object = objects[i];
- object = object._values;
- for (var prop in object) {
- if (typeof object[prop] === 'object') { // Stringify Object properties.
- // Check if property is an ObjectID (reference property),
- // if so replace with the "name" part of the OID.
- if (object[prop]['_object_name']) {
- var parts = object[prop]['_object_name'].split(':');
- object[prop] = parts[parts.length - 1];
- } else {
- // Stringify general Object properties.
- object[prop] = renderObject(object[prop]);
- }
- } else {
- object[prop] = object[prop].toString(); // Stringify other property types.
- }
-
- if (!lengths[prop] || object[prop].length > lengths[prop]) { // Compute lengths.
- lengths[prop] = object[prop].length > prop.length ? object[prop].length : prop.length;
- }
-
- if (!config._list_properties || config._list_properties[prop]) { // Do we want this property?
- attributes[prop] = true;
- }
- }
- }
-
- if (!config._list_properties && DEFAULT_PROPERTIES[type]) {
- attributes = DEFAULT_PROPERTIES[type];
- }
-
- // Using the information we've previously prepared now render a table
- // showing the required property values.
- var desired = [];
- var header = ''; // Table header showing the property names.
- if (attributes['name']) {
- desired.push('name');
- delete attributes['name'];
- header += 'name' + Array(lengths['name'] + 2 - 4).join(' ');
- }
-
- for (var prop in attributes) {
- desired.push(prop);
- header += prop + Array(lengths[prop] + 2 - prop.length).join(' ');
- }
-
- console.log("Objects of type '" + type + "'");
- console.log(header);
- console.log(Array(header.length).join('='));
- for (var i = 0; i < objects.length; i++) {
- var object = objects[i];
- object = object._values;
- var string = '';
- for (var j = 0; j < desired.length; j++) {
- var key = desired[j];
- string += object[key] + Array(lengths[key] + 2 - object[key].length).join(' ');
- }
-
- console.log(string);
- }
-
- brokerAgent.destroy();
- });
- };
-
- var reloadAcl = function() {
- brokerAgent.request(
- brokerAgent.getObjects('org.apache.qpid.acl', 'acl')
- ).then(function(objects) {
- if (objects.acl.length > 0) {
- var acl = objects.acl[0];
- brokerAgent.request(
- // Create an object of the specified type.
- brokerAgent.invokeMethod(acl, 'reloadACLFile', {})
- ).then(handleMethodResponse);
- } else {
- console.log("Failed: No ACL Loaded in Broker");
- brokerAgent.destroy();
- }
- });
- };
-
-
- /********************* process command line options **********************/
-
- var params = [];
- var extra_arguments = [];
- var args = process.argv.slice(2);
- if (args.length > 0) {
- if (args[0] === '-h' || args[0] === '--help') {
- console.log(_usage);
- console.log(_description);
- console.log(_options);
- process.exit(0);
- }
-
- for (var i = 0; i < args.length; i++) {
- var arg = args[i];
- if (arg === '-r' || arg === '--recursive') {
- config._recursive = true;
- } else if (arg === '--ignore-default') {
- config._ignoreDefault = true;
- } else if (arg === '--durable') {
- config._durable = true;
- } else if (arg === '--shared-groups') {
- config._sharedMsgGroup = true;
- } else if (arg === '--sequence') {
- config._sequence = true;
- } else if (arg === '--ive') {
- config._ive = true;
- } else if (arg === '--force') {
- config._if_empty = false;
- config._if_unused = false;
- } else if (arg === '--force-if-not-empty') {
- config._if_empty = false;
- } else if (arg === '--force-if-used') {
- config._if_unused = false;
- } else if (arg === '--sequence') {
- config._msgSequence = true;
- } else if (arg.charAt(0) === '-') {
- i++;
- var val = args[i];
- if (arg === '-t' || arg === '--timeout') {
- config._connTimeout = parseInt(val);
- if (config._connTimeout === 0) {
- config._connTimeout = null;
- }
- } else if (arg === '-b' || arg === '--broker' || arg === '-a' || arg === '--broker-addr') {
- if (val != null) {
- config._host = val;
- }
- } else if (arg === '--alternate-exchange') {
- config._altern_ex = val;
- } else if (arg === '--replicate') {
- if (!REPLICATE_LEVELS[val]) {
- console.error("Invalid replication level " + val + ", should be one of 'none', 'configuration' or 'all'");
- }
- config._replicate = val;
- } else if (arg === '--file-count') {
- config._fileCount = parseInt(val);
- } else if (arg === '--file-size') {
- config._fileSize = parseInt(val);
- } else if (arg === '--max-queue-size') {
- config._maxQueueSize = parseInt(val);
- } else if (arg === '--max-queue-count') {
- config._maxQueueCount = parseInt(val);
- } else if (arg === '--limit-policy') {
- config._limitPolicy = val;
- } else if (arg === '--lvq-key') {
- config._lvq_key = val;
- } else if (arg === '--generate-queue-events') {
- config._eventGeneration = parseInt(val);
- } else if (arg === '--flow-stop-size') {
- config._flowStopSize = parseInt(val);
- } else if (arg === '--flow-resume-size') {
- config._flowResumeSize = parseInt(val);
- } else if (arg === '--flow-stop-count') {
- config._flowStopCount = parseInt(val);
- } else if (arg === '--flow-resume-count') {
- config._flowResumeCount = parseInt(val);
- } else if (arg === '--group-header') {
- config._msgGroupHeader = val;
- } else if (arg === '--argument') {
- extra_arguments.push(val);
- } else if (arg === '--start-replica') {
- config._start_replica = val;
- } else if (arg === '--f' || arg === '--file') { // TODO Won't work in node.js
- config._file = val;
- } else if (arg === '--show-property') {
- if (config._list_properties === null) {
- config._list_properties = {};
- }
- config._list_properties[val] = true;
- }
- } else {
- params.push(arg);
- }
- }
- }
-
- config._extra_arguments = extra_arguments;
-
- // The command only *actually* gets called when the QMF connection has actually
- // been established so we wrap up the function we want to get called in a lambda.
- var command = function() {overview();};
- if (params.length > 0) {
- var cmd = params[0];
- var modifier = '';
- if (params.length > 1) {
- modifier = params[1];
- }
-
- if (cmd === 'exchanges') {
- if (config._recursive) {
- command = function() {exchangeListRecurse(modifier);};
- } else {
- command = function() {exchangeList(modifier);};
- }
- } else if (cmd === 'queues') {
- if (config._recursive) {
- command = function() {queueListRecurse(modifier);};
- } else {
- command = function() {queueList(modifier);};
- }
- } else if (cmd === 'add') {
- if (modifier === 'exchange') {
- command = function() {addExchange(Array.prototype.slice.apply(params, [2]));};
- } else if (modifier === 'queue') {
- command = function() {addQueue(Array.prototype.slice.apply(params, [2]));};
- } else if (params.length > 2) {
- command = function() {createObject(modifier, params[2], config.getOptions());};
- } else {
- usage();
- }
- } else if (cmd === 'del') {
- if (modifier === 'exchange') {
- command = function() {delExchange(Array.prototype.slice.apply(params, [2]));};
- } else if (modifier === 'queue') {
- command = function() {delQueue(Array.prototype.slice.apply(params, [2]));};
- } else if (params.length > 2) {
- command = function() {deleteObject(modifier, params[2], {});};
- } else {
- usage();
- }
- } else if (cmd === 'bind') {
- command = function() {bind(Array.prototype.slice.apply(params, [1]));};
- } else if (cmd === 'unbind') {
- command = function() {unbind(Array.prototype.slice.apply(params, [1]));};
- } else if (cmd === 'reload-acl') {
- command = function() {reloadAcl();};
- } else if (cmd === 'list' && params.length > 1) {
- command = function() {listObjects(modifier);};
- } else {
- usage();
- }
- }
-
- //console.log(config._host);
- brokerAgent.addConnection(config._host, command);
-} else {
- console.error("qpid-config.js should be run in Node.js");
-}
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/recv.js
----------------------------------------------------------------------
diff --git a/examples/javascript/messenger/recv.js b/examples/javascript/messenger/recv.js
deleted file mode 100755
index 79afb20..0000000
--- a/examples/javascript/messenger/recv.js
+++ /dev/null
@@ -1,69 +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");
-
- var address = "amqp://~0.0.0.0";
- var message = new proton.Message();
- var messenger = new proton.Messenger();
-
- var pumpData = function() {
- while (messenger.incoming()) {
- var t = messenger.get(message);
-
- console.log("Address: " + message.getAddress());
- console.log("Subject: " + message.getSubject());
-
- // body is the body as a native JavaScript Object, useful for most real cases.
- //console.log("Content: " + message.body);
-
- // data is the body as a proton.Data Object, used in this case because
- // format() returns exactly the same representation as recv.c
- console.log("Content: " + message.data.format());
-
- messenger.accept(t);
- }
- };
-
- var args = process.argv.slice(2);
- if (args.length > 0) {
- if (args[0] === '-h' || args[0] === '--help') {
- console.log("Usage: node recv.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("recv.js should be run in Node.js");
-}
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db3ee828/examples/javascript/messenger/send.html
----------------------------------------------------------------------
diff --git a/examples/javascript/messenger/send.html b/examples/javascript/messenger/send.html
deleted file mode 100644
index a33e025..0000000
--- a/examples/javascript/messenger/send.html
+++ /dev/null
@@ -1,122 +0,0 @@
-<!DOCTYPE html> <!-- HTML5 doctype -->
-
-<!--
- 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.
--->
-
-<html>
-
-<head>
- <title>Simple Proton Messenger Send Example</title>
- <meta http-equiv="content-type" content="text/html;charset=utf-8" />
-
-<!--
- Import the Messenger Binding proton.js. Note that this simple example pulls
- it from the node_modules/qpid-proton/lib, which is created by the build process
- so that the node.js based examples "just work", in a real Web App you would
- clearly need to copy the proton.js to your own server.
-
- In actual fact the CMake build actually builds proton.js into the directory:
- <build>/proton-c/bindings/javascript
- where <build> is the build directory created to run cmake from, it is then
- copied to the node_modules/qpid-proton/lib directory.
-
- 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.
--->
-<script type="text/javascript">PROTON_TOTAL_MEMORY = 50000000;</script>
-<script type="text/javascript" src="../../../node_modules/qpid-proton-messenger/lib/proton-messenger.js"></script>
-
-<script type="text/javascript">
-var message = new proton.Message();
-var messenger = new proton.Messenger();
-
-var sendMessage = function() {
- var address = document.getElementById("address").value;
- var subject = document.getElementById("subject").value;
- var body = document.getElementById("body").value;
-
-console.log("sendMessage");
-console.log("address = " + address);
-console.log("subject = " + subject);
-console.log("body = " + body);
-
- message.setAddress(address);
- message.setSubject(subject);
- message.body = body;
-
- messenger.put(message);
- messenger.send();
-};
-
-var errorHandler = function(error) {
- console.log("Received error " + error);
-};
-
-messenger.on('error', errorHandler);
-messenger.start();
-
-</script>
-
-<style>
-body
-{
- font: 13px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif;
- overflow-x: hidden; /* Hide horizontal scrollbar */
- background: #dddddd;
-}
-
-label
-{
- display: block;
- font-size: 17px;
-}
-
-input, textarea
-{
- font-size: 13px;
- margin-bottom: 10px;
-}
-</style>
-
-</head>
-
-<body>
-<div>
- <label for="address">Address:</label>
- <input type="text" id="address" size="40"
- placeholder="amqp://user:password@host:port"
- name="address" value="amqp://guest:guest@0.0.0.0" />
-</div>
-<div>
- <label for="subject">Subject:</label>
- <input type="text" id="subject" size="40"
- name="subject" value="Browser Message" />
-</div>
-<div>
- <label for="body">Message:</label>
- <textarea id="body" name="body" rows="4" cols="40">Hello From Browser!</textarea>
-</div>
-<div>
- <input type="button" value="send" onclick="sendMessage()"/>
-</div>
-</body>
-
-</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/3] qpid-proton git commit: PROTON-1585: Remove messenger and
reactor examples
Posted by jr...@apache.org.
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: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org