http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/LICENSE ---------------------------------------------------------------------- diff --git a/examples/engine/java/LICENSE b/examples/engine/java/LICENSE deleted file mode 100644 index ad410e1..0000000 --- a/examples/engine/java/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed 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. \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/drain ---------------------------------------------------------------------- diff --git a/examples/engine/java/drain b/examples/engine/java/drain deleted file mode 100755 index a277ced..0000000 --- a/examples/engine/java/drain +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# 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. -# -mvn -q -e exec:java -Dexec.mainClass=org.apache.qpid.proton.examples.Drain -Dexec.args="$*" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/pom.xml ---------------------------------------------------------------------- diff --git a/examples/engine/java/pom.xml b/examples/engine/java/pom.xml deleted file mode 100644 index bf334b0..0000000 --- a/examples/engine/java/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.qpid</groupId> - <artifactId>proton-project</artifactId> - <version>0.17.0-SNAPSHOT</version> - <relativePath>../../../pom.xml</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>proton-j-engine-demo</artifactId> - <name>proton-j-engine-demo</name> - - <dependencies> - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>proton-j</artifactId> - <version>${project.parent.version}</version> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/server ---------------------------------------------------------------------- diff --git a/examples/engine/java/server b/examples/engine/java/server deleted file mode 100755 index 84a167c..0000000 --- a/examples/engine/java/server +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# 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. -# -mvn -q -e exec:java -Dexec.mainClass=org.apache.qpid.proton.examples.Server -Dexec.args="$*" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/spout ---------------------------------------------------------------------- diff --git a/examples/engine/java/spout b/examples/engine/java/spout deleted file mode 100755 index 42cd0c7..0000000 --- a/examples/engine/java/spout +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# 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. -# -mvn -q -e exec:java -Dexec.mainClass=org.apache.qpid.proton.examples.Spout -Dexec.args="$*" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Drain.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Drain.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Drain.java deleted file mode 100644 index 8b93886..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Drain.java +++ /dev/null @@ -1,127 +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. - * - */ -package org.apache.qpid.proton.examples; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Collector; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Receiver; - -public class Drain extends BaseHandler { - - private int count; - private boolean block; - private int received; - private boolean quiet; - - public Drain(int count, boolean block, boolean quiet) { - this.count = count; - this.block = block; - this.quiet = quiet; - } - - @Override - public void onLinkLocalOpen(Event evt) { - Link link = evt.getLink(); - if (link instanceof Receiver) { - Receiver receiver = (Receiver) link; - - if (block) { - receiver.flow(count); - } else { - receiver.drain(count); - } - } - } - - @Override - public void onLinkFlow(Event evt) { - Link link = evt.getLink(); - if (link instanceof Receiver) { - Receiver receiver = (Receiver) link; - - if (!receiver.draining()) { - receiver.getSession().getConnection().close(); - } - } - } - - @Override - public void onDelivery(Event evt) { - Delivery dlv = evt.getDelivery(); - if (dlv.getLink() instanceof Receiver) { - Receiver receiver = (Receiver) dlv.getLink(); - - if (!dlv.isPartial()) { - byte[] bytes = new byte[dlv.pending()]; - receiver.recv(bytes, 0, bytes.length); - Message msg = new Message(bytes); - - if (!quiet) { - System.out.println(String.format("Got message: %s", msg)); - } - received++; - dlv.settle(); - } - - if ((received >= count) || (!block && !receiver.draining())) { - receiver.getSession().getConnection().close(); - } - } - } - - @Override - public void onConnectionRemoteClose(Event evt) { - System.out.println(String.format("Got %s messages", received)); - } - - public static void main(String[] argv) throws Exception { - List<String> switches = new ArrayList<String>(); - List<String> args = new ArrayList<String>(); - for (String s : argv) { - if (s.startsWith("-")) { - switches.add(s); - } else { - args.add(s); - } - } - - boolean quiet = switches.contains("-q"); - String address = args.isEmpty() || !args.get(0).startsWith("/") ? "//localhost" : args.remove(0); - int count = args.isEmpty() ? 1 : Integer.parseInt(args.remove(0)); - boolean block = switches.contains("-b"); - - Collector collector = Collector.Factory.create(); - - Drain drain = new Drain(count, block, quiet); - Driver driver = new Driver(collector, drain); - - Pool pool = new Pool(collector); - pool.incoming(address, null); - - driver.run(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Driver.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Driver.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Driver.java deleted file mode 100644 index 7412dc6..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Driver.java +++ /dev/null @@ -1,265 +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. - * - */ -package org.apache.qpid.proton.examples; - -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Collector; -import org.apache.qpid.proton.engine.EndpointState; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Handler; -import org.apache.qpid.proton.engine.Sasl; -import org.apache.qpid.proton.engine.Transport; -import org.apache.qpid.proton.engine.TransportException; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.StandardSocketOptions; -import java.nio.ByteBuffer; -import java.nio.channels.Selector; -import java.nio.channels.SelectionKey; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.util.UUID; - - -/** - * Driver - * - */ - -public class Driver extends BaseHandler -{ - - final private Collector collector; - final private Handler[] handlers; - final private Selector selector; - - public Driver(Collector collector, Handler ... handlers) throws IOException { - this.collector = collector; - this.handlers = handlers; - this.selector = Selector.open(); - } - - public void listen(String host, int port) throws IOException { - new Acceptor(host, port); - } - - public void run() throws IOException { - while (true) { - processEvents(); - - // I don't know if there is a better way to do this, but - // the only way canceled selection keys are removed from - // the key set is via a select operation, so we do this - // first to figure out whether we should exit. Without - // this we would block indefinitely when there are only - // cancelled keys remaining. - selector.selectNow(); - if (selector.keys().isEmpty()) { - selector.close(); - return; - } - - selector.selectedKeys().clear(); - selector.select(); - - for (SelectionKey key : selector.selectedKeys()) { - Selectable selectable = (Selectable) key.attachment(); - selectable.selected(); - } - } - } - - public void processEvents() { - while (true) { - Event ev = collector.peek(); - if (ev == null) break; - ev.dispatch(this); - for (Handler h : handlers) { - ev.dispatch(h); - } - collector.pop(); - } - } - - @Override - public void onTransport(Event evt) { - Transport transport = evt.getTransport(); - ChannelHandler ch = (ChannelHandler) transport.getContext(); - ch.selected(); - } - - @Override - public void onConnectionLocalOpen(Event evt) { - Connection conn = evt.getConnection(); - if (conn.getRemoteState() == EndpointState.UNINITIALIZED) { - // Give the connection a [random] container-id - conn.setContainer(UUID.randomUUID().toString()); - try { - new Connector(conn); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - - private interface Selectable { - void selected() throws IOException; - } - - private class Acceptor implements Selectable { - - final private ServerSocketChannel socket; - final private SelectionKey key; - - Acceptor(String host, int port) throws IOException { - socket = ServerSocketChannel.open(); - socket.configureBlocking(false); - socket.bind(new InetSocketAddress(host, port)); - socket.setOption(StandardSocketOptions.SO_REUSEADDR, true); - key = socket.register(selector, SelectionKey.OP_ACCEPT, this); - } - - public void selected() throws IOException { - SocketChannel sock = socket.accept(); - System.out.println("ACCEPTED: " + sock); - Connection conn = Connection.Factory.create(); - conn.collect(collector); - Transport transport = Transport.Factory.create(); - Sasl sasl = transport.sasl(); - sasl.setMechanisms("ANONYMOUS"); - sasl.server(); - sasl.done(Sasl.PN_SASL_OK); - transport.bind(conn); - new ChannelHandler(sock, SelectionKey.OP_READ, transport); - } - } - - private class ChannelHandler implements Selectable { - - final SocketChannel socket; - final SelectionKey key; - final Transport transport; - - ChannelHandler(SocketChannel socket, int ops, Transport transport) throws IOException { - this.socket = socket; - socket.configureBlocking(false); - key = socket.register(selector, ops, this); - this.transport = transport; - transport.setContext(this); - } - - boolean update() { - if (socket.isConnected()) { - int c = transport.capacity(); - int p = transport.pending(); - if (key.isValid()) { - key.interestOps((c != 0 ? SelectionKey.OP_READ : 0) | - (p > 0 ? SelectionKey.OP_WRITE : 0)); - } - if (c < 0 && p < 0) { - return true; - } else { - return false; - } - } else { - return false; - } - } - - public void selected() { - if (!key.isValid()) { return; } - - try { - if (key.isConnectable()) { - System.out.println("CONNECTED: " + socket); - socket.finishConnect(); - } - - if (key.isReadable()) { - int c = transport.capacity(); - if (c > 0) { - ByteBuffer tail = transport.tail(); - int n = socket.read(tail); - if (n > 0) { - try { - transport.process(); - } catch (TransportException e) { - e.printStackTrace(); - } - } else if (n < 0) { - transport.close_tail(); - } - } - } - - if (key.isWritable()) { - int p = transport.pending(); - if (p > 0) { - ByteBuffer head = transport.head(); - int n = socket.write(head); - if (n > 0) { - transport.pop(n); - } else if (n < 0) { - transport.close_head(); - } - } - } - - if (update()) { - transport.unbind(); - System.out.println("CLOSING: " + socket); - socket.close(); - } - } catch (IOException e) { - transport.unbind(); - System.out.println(String.format("CLOSING(%s): %s", e, socket)); - try { - socket.close(); - } catch (IOException e2) { - throw new RuntimeException(e2); - } - } - - } - - } - - private static Transport makeTransport(Connection conn) { - Transport transport = Transport.Factory.create(); - Sasl sasl = transport.sasl(); - sasl.setMechanisms("ANONYMOUS"); - sasl.client(); - transport.bind(conn); - return transport; - } - - private class Connector extends ChannelHandler { - - Connector(Connection conn) throws IOException { - super(SocketChannel.open(), SelectionKey.OP_CONNECT, makeTransport(conn)); - System.out.println("CONNECTING: " + conn.getHostname()); - socket.connect(new InetSocketAddress(conn.getHostname(), 5672)); - } - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/FlowController.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/FlowController.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/FlowController.java deleted file mode 100644 index d22a637..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/FlowController.java +++ /dev/null @@ -1,80 +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. - * - */ -package org.apache.qpid.proton.examples; - -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Receiver; - -/** - * FlowController - * - */ - -public class FlowController extends BaseHandler -{ - - final private int window; - - public FlowController(int window) { - this.window = window; - } - - private void topUp(Receiver rcv) { - int delta = window - rcv.getCredit(); - rcv.flow(delta); - } - - @Override - public void onLinkLocalOpen(Event evt) { - Link link = evt.getLink(); - if (link instanceof Receiver) { - topUp((Receiver) link); - } - } - - @Override - public void onLinkRemoteOpen(Event evt) { - Link link = evt.getLink(); - if (link instanceof Receiver) { - topUp((Receiver) link); - } - } - - @Override - public void onLinkFlow(Event evt) { - Link link = evt.getLink(); - if (link instanceof Receiver) { - topUp((Receiver) link); - } - } - - @Override - public void onDelivery(Event evt) { - Link link = evt.getLink(); - if (link instanceof Receiver) { - topUp((Receiver) link); - } - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Handshaker.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Handshaker.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Handshaker.java deleted file mode 100644 index c53d0f8..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Handshaker.java +++ /dev/null @@ -1,88 +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. - * - */ -package org.apache.qpid.proton.examples; - -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.EndpointState; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Session; - -/** - * Handshaker - * - */ - -public class Handshaker extends BaseHandler -{ - - @Override - public void onConnectionRemoteOpen(Event evt) { - Connection conn = evt.getConnection(); - if (conn.getLocalState() == EndpointState.UNINITIALIZED) { - conn.open(); - } - } - - @Override - public void onSessionRemoteOpen(Event evt) { - Session ssn = evt.getSession(); - if (ssn.getLocalState() == EndpointState.UNINITIALIZED) { - ssn.open(); - } - } - - @Override - public void onLinkRemoteOpen(Event evt) { - Link link = evt.getLink(); - if (link.getLocalState() == EndpointState.UNINITIALIZED) { - link.setSource(link.getRemoteSource()); - link.setTarget(link.getRemoteTarget()); - link.open(); - } - } - - @Override - public void onConnectionRemoteClose(Event evt) { - Connection conn = evt.getConnection(); - if (conn.getLocalState() != EndpointState.CLOSED) { - conn.close(); - } - } - - @Override - public void onSessionRemoteClose(Event evt) { - Session ssn = evt.getSession(); - if (ssn.getLocalState() != EndpointState.CLOSED) { - ssn.close(); - } - } - - @Override - public void onLinkRemoteClose(Event evt) { - Link link = evt.getLink(); - if (link.getLocalState() != EndpointState.CLOSED) { - link.close(); - } - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Message.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Message.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Message.java deleted file mode 100644 index b439f69..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Message.java +++ /dev/null @@ -1,83 +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. - * - */ -package org.apache.qpid.proton.examples; - -import java.nio.ByteBuffer; -import java.util.Arrays; - - -/** - * Message - * - */ - -public class Message -{ - private final byte[] bytes; - - /** - * These bytes are expected to be AMQP encoded. - */ - public Message(byte[] bytes) { - this.bytes = bytes; - } - - private static final byte[] PREFIX = {(byte)0x00, (byte)0x53, (byte)0x77, (byte)0xb1}; - - private static byte[] encodeString(String string) { - byte[] utf8 = string.getBytes(); - byte[] result = new byte[PREFIX.length + 4 + utf8.length]; - ByteBuffer bbuf = ByteBuffer.wrap(result); - bbuf.put(PREFIX); - bbuf.putInt(utf8.length); - bbuf.put(utf8); - return result; - } - - public Message(String string) { - // XXX: special case string encoding for now - this(encodeString(string)); - } - - public byte[] getBytes() { - return bytes; - } - - public String toString() { - StringBuilder bld = new StringBuilder(); - bld.append("Message("); - for (byte b : bytes) { - if (b >= 32 && b < 127) { - bld.append((char) b); - } else { - bld.append("\\x"); - String hex = Integer.toHexString(0xFF & b); - if (hex.length() < 2) { - bld.append("0"); - } - bld.append(hex); - } - } - bld.append(')'); - return bld.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Pool.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Pool.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Pool.java deleted file mode 100644 index bb5bf86..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Pool.java +++ /dev/null @@ -1,153 +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. - * - */ -package org.apache.qpid.proton.examples; - -import org.apache.qpid.proton.engine.Collector; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Session; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.engine.Receiver; - -import org.apache.qpid.proton.amqp.messaging.Source; -import org.apache.qpid.proton.amqp.messaging.Target; - -import java.util.HashMap; -import java.util.Map; - -/** - * Pool - * - */ - -public class Pool -{ - - final private Collector collector; - final private Map<String,Connection> connections; - - final private LinkConstructor<Sender> outgoingConstructor = new LinkConstructor<Sender> () { - public Sender create(Session ssn, String remote, String local) { - return newOutgoing(ssn, remote, local); - } - }; - final private LinkConstructor<Receiver> incomingConstructor = new LinkConstructor<Receiver> () { - public Receiver create(Session ssn, String remote, String local) { - return newIncoming(ssn, remote, local); - } - }; - - final private LinkResolver<Sender> outgoingResolver; - final private LinkResolver<Receiver> incomingResolver; - - public Pool(Collector collector, final Router router) { - this.collector = collector; - connections = new HashMap<String,Connection>(); - - if (router != null) { - outgoingResolver = new LinkResolver<Sender>() { - public Sender resolve(String address) { - return router.getOutgoing(address).choose(); - } - }; - incomingResolver = new LinkResolver<Receiver>() { - public Receiver resolve(String address) { - return router.getIncoming(address).choose(); - } - }; - } else { - outgoingResolver = new LinkResolver<Sender>() { - public Sender resolve(String address) { return null; } - }; - incomingResolver = new LinkResolver<Receiver>() { - public Receiver resolve(String address) { return null; } - }; - } - } - - public Pool(Collector collector) { - this(collector, null); - } - - private <T extends Link> T resolve(String remote, String local, - LinkResolver<T> resolver, - LinkConstructor<T> constructor) { - String host = remote.substring(2).split("/", 2)[0]; - T link = resolver.resolve(remote); - if (link == null) { - Connection conn = connections.get(host); - if (conn == null) { - conn = Connection.Factory.create(); - conn.collect(collector); - conn.setHostname(host); - conn.open(); - connections.put(host, conn); - } - - Session ssn = conn.session(); - ssn.open(); - - link = constructor.create(ssn, remote, local); - link.open(); - } - return link; - } - - public Sender outgoing(String target, String source) { - return resolve(target, source, outgoingResolver, outgoingConstructor); - } - - public Receiver incoming(String source, String target) { - return resolve(source, target, incomingResolver, incomingConstructor); - } - - public Sender newOutgoing(Session ssn, String remote, String local) { - Sender snd = ssn.sender(String.format("%s-%s", local, remote)); - Source src = new Source(); - src.setAddress(local); - snd.setSource(src); - Target tgt = new Target(); - tgt.setAddress(remote); - snd.setTarget(tgt); - return snd; - } - - public Receiver newIncoming(Session ssn, String remote, String local) { - Receiver rcv = ssn.receiver(String.format("%s-%s", remote, local)); - Source src = new Source(); - src.setAddress(remote); - rcv.setSource(src); - Target tgt = new Target(); - tgt.setAddress(remote); - rcv.setTarget(tgt); - return rcv; - } - - public static interface LinkConstructor<T extends Link> { - T create(Session session, String remote, String local); - } - - public static interface LinkResolver<T extends Link> { - T resolve(String remote); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Router.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Router.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Router.java deleted file mode 100644 index 873f16c..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Router.java +++ /dev/null @@ -1,191 +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. - * - */ -package org.apache.qpid.proton.examples; - -import org.apache.qpid.proton.amqp.transport.Source; -import org.apache.qpid.proton.amqp.transport.Target; -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ThreadLocalRandom; - - -/** - * Router - * - */ - -public class Router extends BaseHandler -{ - - public static class Routes<T extends Link> { - - List<T> routes = new ArrayList<T>(); - - void add(T route) { - routes.add(route); - } - - void remove(T route) { - routes.remove(route); - } - - int size() { - return routes.size(); - } - - public T choose() { - if (routes.isEmpty()) { return null; } - ThreadLocalRandom rand = ThreadLocalRandom.current(); - int idx = rand.nextInt(0, routes.size()); - return routes.get(idx); - } - - } - - private static final Routes<Sender> EMPTY_OUT = new Routes<Sender>(); - private static final Routes<Receiver> EMPTY_IN = new Routes<Receiver>(); - - final private Map<String,Routes<Sender>> outgoing = new HashMap<String,Routes<Sender>>(); - final private Map<String,Routes<Receiver>> incoming = new HashMap<String,Routes<Receiver>>(); - - public Router() {} - - private String getAddress(Source source) { - if (source == null) { - return null; - } else { - return source.getAddress(); - } - } - - private String getAddress(Target target) { - if (target == null) { - return null; - } else { - return target.getAddress(); - } - } - - public String getAddress(Sender snd) { - String source = getAddress(snd.getSource()); - String target = getAddress(snd.getTarget()); - return source != null ? source : target; - } - - public String getAddress(Receiver rcv) { - return getAddress(rcv.getTarget()); - } - - public Routes<Sender> getOutgoing(String address) { - Routes<Sender> routes = outgoing.get(address); - if (routes == null) { return EMPTY_OUT; } - return routes; - } - - public Routes<Receiver> getIncoming(String address) { - Routes<Receiver> routes = incoming.get(address); - if (routes == null) { return EMPTY_IN; } - return routes; - } - - private void add(Sender snd) { - String address = getAddress(snd); - Routes<Sender> routes = outgoing.get(address); - if (routes == null) { - routes = new Routes<Sender>(); - outgoing.put(address, routes); - } - routes.add(snd); - } - - private void remove(Sender snd) { - String address = getAddress(snd); - Routes<Sender> routes = outgoing.get(address); - if (routes != null) { - routes.remove(snd); - if (routes.size() == 0) { - outgoing.remove(address); - } - } - } - - private void add(Receiver rcv) { - String address = getAddress(rcv); - Routes<Receiver> routes = incoming.get(address); - if (routes == null) { - routes = new Routes<Receiver>(); - incoming.put(address, routes); - } - routes.add(rcv); - } - - private void remove(Receiver rcv) { - String address = getAddress(rcv); - Routes<Receiver> routes = incoming.get(address); - if (routes != null) { - routes.remove(rcv); - if (routes.size() == 0) { - incoming.remove(address); - } - } - } - - private void add(Link link) { - if (link instanceof Sender) { - add((Sender) link); - } else { - add((Receiver) link); - } - } - - private void remove(Link link) { - if (link instanceof Sender) { - remove((Sender) link); - } else { - remove((Receiver) link); - } - } - - @Override - public void onLinkLocalOpen(Event evt) { - add(evt.getLink()); - } - - @Override - public void onLinkLocalClose(Event evt) { - remove(evt.getLink()); - } - - @Override - public void onLinkFinal(Event evt) { - remove(evt.getLink()); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Server.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Server.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Server.java deleted file mode 100644 index 3e00bd5..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Server.java +++ /dev/null @@ -1,179 +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. - * - */ -package org.apache.qpid.proton.examples; - -import org.apache.qpid.proton.amqp.messaging.Accepted; -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Collector; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; - -import java.io.IOException; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Server - * - */ - -public class Server extends BaseHandler -{ - - private class MessageStore { - - Map<String,Deque<Message>> messages = new HashMap<String,Deque<Message>>(); - - void put(String address, Message message) { - Deque<Message> queue = messages.get(address); - if (queue == null) { - queue = new ArrayDeque<Message>(); - messages.put(address, queue); - } - queue.add(message); - } - - Message get(String address) { - Deque<Message> queue = messages.get(address); - if (queue == null) { return null; } - Message msg = queue.remove(); - if (queue.isEmpty()) { - messages.remove(address); - } - return msg; - } - - } - - final private MessageStore messages = new MessageStore(); - final private Router router; - private boolean quiet; - private int tag = 0; - - public Server(Router router, boolean quiet) { - this.router = router; - this.quiet = quiet; - } - - private byte[] nextTag() { - return String.format("%s", tag++).getBytes(); - } - - private int send(String address) { - return send(address, null); - } - - private int send(String address, Sender snd) { - if (snd == null) { - Router.Routes<Sender> routes = router.getOutgoing(address); - snd = routes.choose(); - if (snd == null) { - return 0; - } - } - - int count = 0; - while (snd.getCredit() > 0 && snd.getQueued() < 1024) { - Message msg = messages.get(address); - if (msg == null) { - snd.drained(); - return count; - } - Delivery dlv = snd.delivery(nextTag()); - byte[] bytes = msg.getBytes(); - snd.send(bytes, 0, bytes.length); - dlv.settle(); - count++; - if (!quiet) { - System.out.println(String.format("Sent message(%s): %s", address, msg)); - } - } - - return count; - } - - @Override - public void onLinkFlow(Event evt) { - Link link = evt.getLink(); - if (link instanceof Sender) { - Sender snd = (Sender) link; - send(router.getAddress(snd), snd); - } - } - - @Override - public void onDelivery(Event evt) { - Delivery dlv = evt.getDelivery(); - Link link = dlv.getLink(); - if (link instanceof Sender) { - dlv.settle(); - } else { - Receiver rcv = (Receiver) link; - if (!dlv.isPartial()) { - byte[] bytes = new byte[dlv.pending()]; - rcv.recv(bytes, 0, bytes.length); - String address = router.getAddress(rcv); - Message message = new Message(bytes); - messages.put(address, message); - dlv.disposition(Accepted.getInstance()); - dlv.settle(); - if (!quiet) { - System.out.println(String.format("Got message(%s): %s", address, message)); - } - send(address); - } - } - } - - public static final void main(String[] argv) throws IOException { - List<String> switches = new ArrayList<String>(); - List<String> args = new ArrayList<String>(); - for (String s : argv) { - if (s.startsWith("-")) { - switches.add(s); - } else { - args.add(s); - } - } - - boolean quiet = switches.contains("-q"); - String host = !args.isEmpty() && !Character.isDigit(args.get(0).charAt(0)) ? - args.remove(0) : "localhost"; - int port = !args.isEmpty() ? Integer.parseInt(args.remove(0)) : 5672; - - Collector collector = Collector.Factory.create(); - Router router = new Router(); - Driver driver = new Driver(collector, new Handshaker(), - new FlowController(1024), router, - new Server(router, quiet)); - driver.listen(host, port); - driver.run(); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Spout.java ---------------------------------------------------------------------- diff --git a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Spout.java b/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Spout.java deleted file mode 100644 index 1d70aca..0000000 --- a/examples/engine/java/src/main/java/org/apache/qpid/proton/examples/Spout.java +++ /dev/null @@ -1,116 +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. - * - */ -package org.apache.qpid.proton.examples; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Collector; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Link; -import org.apache.qpid.proton.engine.Sender; - -public class Spout extends BaseHandler -{ - private int count; - private int sent; - private int settled; - private boolean quiet; - - public Spout(int count, boolean quiet) { - this.count = count; - this.quiet = quiet; - } - - @Override - public void onLinkFlow(Event evt) { - Link link = evt.getLink(); - if (link instanceof Sender) { - Sender sender = (Sender) link; - while ((sent < count) && sender.getCredit() > 0) { - Delivery dlv = sender.delivery(String.format("spout-%s", sent).getBytes()); - - Message msg = new Message(String.format("Hello World! [%s]", sent)); - byte[] bytes = msg.getBytes(); - sender.send(bytes, 0, bytes.length); - sender.advance(); - - if (!quiet) { - System.out.println(String.format("Sent %s to %s: %s", new String(dlv.getTag()), - sender.getTarget().getAddress(), msg)); - } - sent++; - } - } - } - - @Override - public void onDelivery(Event evt) { - Delivery dlv = evt.getDelivery(); - if (dlv.remotelySettled()) { - if (!quiet) { - System.out.println(String.format("Settled %s: %s", new String(dlv.getTag()), dlv.getRemoteState())); - } - dlv.settle(); - settled++; - } - - if (settled >= count) { - dlv.getLink().getSession().getConnection().close(); - } - } - - @Override - public void onConnectionRemoteClose(Event evt) { - System.out.println("settled: " + settled); - } - - public static void main(String[] argv) throws Exception { - List<String> switches = new ArrayList<String>(); - List<String> args = new ArrayList<String>(); - for (String s : argv) { - if (s.startsWith("-")) { - switches.add(s); - } else { - args.add(s); - } - } - - boolean quiet = switches.contains("-q"); - String address = !args.isEmpty() && args.get(0).startsWith("/") ? - args.remove(0) : "//localhost"; - int count = !args.isEmpty() ? Integer.parseInt(args.remove(0)) : 1; - - Collector collector = Collector.Factory.create(); - - Spout spout = new Spout(count, quiet); - - Driver driver = new Driver(collector, spout); - - Pool pool = new Pool(collector); - pool.outgoing(address, null); - - driver.run(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/messenger/README.txt ---------------------------------------------------------------------- diff --git a/examples/java/messenger/README.txt b/examples/java/messenger/README.txt deleted file mode 100644 index 20d3788..0000000 --- a/examples/java/messenger/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -This directory contains java examples that use the messenger API. -Based on the python examples in ../py - - Send.java - a simple example of using the messenger API to send messages - Recv.java - 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: - java Recv.class amqp://<broker>/<queue> - java Send.class -a amqp://<broker>/<queue> msg_1 ... msg_n - -For peer to peer usage: - # execute on <host> to receive messages from all local network interfaces - java Recv.class amqp://~0.0.0.0 - java Send.class -a amqp://<host> msg_1 ... msg_n - -Or, use the shell scripts "recv" and "send" to run the java programs: -recv [-v] [-n MAXMESSAGES] [-a ADDRESS] ... [-a ADDRESS] -send [-a ADDRESS] [-s SUBJECT] MESSAGE ... MESSAGE - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/messenger/pom.xml ---------------------------------------------------------------------- diff --git a/examples/java/messenger/pom.xml b/examples/java/messenger/pom.xml deleted file mode 100644 index a23a4a3..0000000 --- a/examples/java/messenger/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.qpid</groupId> - <artifactId>proton-project</artifactId> - <version>0.17.0-SNAPSHOT</version> - <relativePath>../../..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>proton-j-messenger-example</artifactId> - <name>proton-j-messenger-example</name> - - <dependencies> - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>proton-j</artifactId> - <version>${project.parent.version}</version> - </dependency> - </dependencies> - - <scm> - <url>http://svn.apache.org/viewvc/qpid/proton/</url> - </scm> -</project> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/messenger/recv ---------------------------------------------------------------------- diff --git a/examples/java/messenger/recv b/examples/java/messenger/recv deleted file mode 100755 index 862700c..0000000 --- a/examples/java/messenger/recv +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/bash -# -# 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. -# - -# Usage: recv [-v] [-n MAXMESSAGES] [-a ADDRESS]*" -# Subscribes to the given amqp addresses (by default, to amqp://localhost/test), -# and prints messages received, upt to MAXMESSAGES. -# Prints message headers and body; -v means print all message properties. - -HERE=$(cd $(dirname $0); pwd) -TOP=$(cd $(dirname $0); cd ../../..; pwd) -LIBS=$HERE/target/classes:$TOP/proton-j/target/classes -JFLAGS="-Djava.util.logging.config.file=$HERE/recv.trace.props -cp $LIBS" -java -cp $LIBS org.apache.qpid.proton.example.Recv "$@" - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/messenger/send ---------------------------------------------------------------------- diff --git a/examples/java/messenger/send b/examples/java/messenger/send deleted file mode 100755 index e7b4b67..0000000 --- a/examples/java/messenger/send +++ /dev/null @@ -1,29 +0,0 @@ -#! /bin/bash -# -# 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. -# - -# Usage: send [-a ADDRESS] [-s SUBJECT] MESSAGE ... MESSAGE -# sends each arg as a text-message to the given adress (by default, to amqp://localhost/test) - -HERE=$(cd $(dirname $0); pwd) -TOP=$(cd $(dirname $0); cd ../../..; pwd) -LIBS=$HERE/target/classes:$TOP/proton-j/target/classes -JFLAGS="-Djava.util.logging.config.file=$HERE/send.trace.props -cp $LIBS" -java -cp $LIBS org.apache.qpid.proton.example.Send "$@" - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Recv.java ---------------------------------------------------------------------- diff --git a/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Recv.java b/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Recv.java deleted file mode 100644 index 3934cff..0000000 --- a/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Recv.java +++ /dev/null @@ -1,133 +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. - * - */ -package org.apache.qpid.proton.example; - -import org.apache.qpid.proton.message.Message; -import org.apache.qpid.proton.messenger.Messenger; -import org.apache.qpid.proton.messenger.impl.MessengerImpl; -import org.apache.qpid.proton.amqp.messaging.ApplicationProperties; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Example/test of the java Messenger/Message API. - * Based closely qpid src/proton/examples/messenger/py/recv.py - * @author [email protected] - * @since 8/4/2013 - * @deprecated Messenger will be removed from upcoming proton-j releases. - */ -@Deprecated -public class Recv { - private static Logger tracer = Logger.getLogger("proton.example"); - private boolean verbose = false; - private int maxct = 0; - private List<String> addrs = new ArrayList<String>(); - - private static void usage() { - System.err.println("Usage: recv [-v] [-n MAXCT] [-a ADDRESS]*"); - System.exit(2); - } - - private Recv(String args[]) { - int i = 0; - while (i < args.length) { - String arg = args[i++]; - if (arg.startsWith("-")) { - if ("-v".equals(arg)) { - verbose = true; - } else if ("-a".equals(arg)) { - addrs.add(args[i++]); - } else if ("-n".equals(arg)) { - maxct = Integer.valueOf(args[i++]); - } else { - System.err.println("unknown option " + arg); - usage(); - } - } else { - usage(); - } - } - if (addrs.size() == 0) { - addrs.add("amqp://~0.0.0.0"); - } - } - - private static String safe(Object o) { - return String.valueOf(o); - } - - private void print(int i, Message msg) { - StringBuilder b = new StringBuilder("message: "); - b.append(i).append("\n"); - b.append("Address: ").append(msg.getAddress()).append("\n"); - b.append("Subject: ").append(msg.getSubject()).append("\n"); - if (verbose) { - b.append("Props: ").append(msg.getProperties()).append("\n"); - b.append("App Props: ").append(msg.getApplicationProperties()).append("\n"); - b.append("Msg Anno: ").append(msg.getMessageAnnotations()).append("\n"); - b.append("Del Anno: ").append(msg.getDeliveryAnnotations()).append("\n"); - } else { - ApplicationProperties p = msg.getApplicationProperties(); - String s = (p == null) ? "null" : safe(p.getValue()); - b.append("Headers: ").append(s).append("\n"); - } - b.append(msg.getBody()).append("\n"); - b.append("END").append("\n"); - System.out.println(b.toString()); - } - - private void run() { - try { - Messenger mng = new MessengerImpl(); - mng.start(); - for (String a : addrs) { - mng.subscribe(a); - } - int ct = 0; - boolean done = false; - while (!done) { - mng.recv(); - while (mng.incoming() > 0) { - Message msg = mng.get(); - ++ct; - print(ct, msg); - if (maxct > 0 && ct >= maxct) { - done = true; - break; - } - } - } - mng.stop(); - } catch (Exception e) { - tracer.log(Level.SEVERE, "proton error", e); - } - } - - public static void main(String args[]) { - Recv o = new Recv(args); - o.run(); - } -} - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Send.java ---------------------------------------------------------------------- diff --git a/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Send.java b/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Send.java deleted file mode 100644 index 6f4a919..0000000 --- a/examples/java/messenger/src/main/java/org/apache/qpid/proton/example/Send.java +++ /dev/null @@ -1,104 +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. - * - */ -package org.apache.qpid.proton.example; - -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.message.Message; -import org.apache.qpid.proton.message.impl.MessageImpl; -import org.apache.qpid.proton.messenger.Messenger; -import org.apache.qpid.proton.messenger.impl.MessengerImpl; - -import java.io.IOException; -import java.util.Arrays; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Example/test of the java Messenger/Message API. - * Based closely qpid src/proton/examples/messenger/py/send.py - * @author [email protected] - * @since 8/4/2013 - * @deprecated Messenger will be removed from upcoming proton-j releases. - */ -@Deprecated -public class Send { - - private static Logger tracer = Logger.getLogger("proton.example"); - private String address = "amqp://0.0.0.0"; - private String subject; - private String[] bodies = new String[]{"Hello World!"}; - - private static void usage() { - System.err.println("Usage: send [-a ADDRESS] [-s SUBJECT] MSG+"); - System.exit(2); - } - - private Send(String args[]) { - int i = 0; - while (i < args.length) { - String arg = args[i++]; - if (arg.startsWith("-")) { - if ("-a".equals(arg)) { - address = args[i++]; - } else if ("-s".equals(arg)) { - subject = args[i++]; - } else { - System.err.println("unknown option " + arg); - usage(); - } - } else { - --i; - break; - } - } - - if(i != args.length) - { - bodies = Arrays.copyOfRange(args, i, args.length); - } - } - - private void run() { - try { - Messenger mng = new MessengerImpl(); - mng.start(); - Message msg = new MessageImpl(); - msg.setAddress(address); - if (subject != null) msg.setSubject(subject); - for (String body : bodies) { - msg.setBody(new AmqpValue(body)); - mng.put(msg); - } - mng.send(); - mng.stop(); - } catch (Exception e) { - tracer.log(Level.SEVERE, "proton error", e); - } - } - - public static void main(String args[]) { - Send o = new Send(args); - o.run(); - } -} - - - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/reactor/.gitignore ---------------------------------------------------------------------- diff --git a/examples/java/reactor/.gitignore b/examples/java/reactor/.gitignore deleted file mode 100644 index 5e56e04..0000000 --- a/examples/java/reactor/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/reactor/README.md ---------------------------------------------------------------------- diff --git a/examples/java/reactor/README.md b/examples/java/reactor/README.md deleted file mode 100644 index c6b532f..0000000 --- a/examples/java/reactor/README.md +++ /dev/null @@ -1,55 +0,0 @@ -The Reactor API provides a means to dispatch events occurring across -one or more connections. It can be used purely as a dispatch tool -alongside your own I/O mechanism, however by default it is configured -with a handler that provides I/O for you. - -When programming with the reactor it is important to understand the -dispatch model used to process events. Every event is associated with -a context object, i.e. the *target* object upon which the event -occurred. These objects are contained either directly or indirectly -within the Reactor: - - Delivery --> Link --> Session --> Connection --+ - | - Task --+--> Reactor - | - Selectable --+ - - -Each event is dispatched first to a target-specific handler, and -second to a global handler. The target-specific handler for an event -is located by searching from the event context up through the -hierarchy (terminating with the Reactor) and retrieving the most -specific handler found. - -This means that any handler set on the Reactor could receive events -targeting any object. For example if no handlers are associated with a -Connection or any of its child objects, then the Reactor's handler -will receive all the events for that Connection. - -Putting a handler on any child, e.g. a Connection or Session or Link -will prevent any handlers set on the ancestors of that object from -seeing any events targeted for that object or its children unless that -handler specifically chooses to delegate those events up to the -parent, e.g. by overriding onUnhandled and delegating. - -The global handler (used to dispatch all events after the -target-specific handler is invoked) can be accessed and modified using -Reactor.set/getGlobalHandler. This can be useful for a number of -reasons, e.g. you could log all events by doing this: - - reactor.getGlobalHandler().add(new LoggerHandler()); - -Where LoggerHandler does this: - - public void onUnhandled(Event evt) { - System.out.println(evt); - } - -The above trick is particularly useful for debugging. - -Handlers themselves can have child handlers which will automatically -delegate the event to those children *after* dispatching the event to -itself. The default global handler is what provides the default I/O -behavior of the reactor. To use the reactor as a pure dispatch -mechanism you can simply set the global handler to null. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/reactor/pom.xml ---------------------------------------------------------------------- diff --git a/examples/java/reactor/pom.xml b/examples/java/reactor/pom.xml deleted file mode 100644 index 3ca3ec3..0000000 --- a/examples/java/reactor/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.qpid</groupId> - <artifactId>proton-project</artifactId> - <version>0.17.0-SNAPSHOT</version> - <relativePath>../../..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>proton-j-reactor-examples</artifactId> - <name>proton-j-reactor-examples</name> - - <dependencies> - <dependency> - <groupId>org.apache.qpid</groupId> - <artifactId>proton-j</artifactId> - <version>${project.parent.version}</version> - </dependency> - </dependencies> - - <scm> - <url>http://svn.apache.org/viewvc/qpid/proton/</url> - </scm> -</project> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/examples/java/reactor/run ---------------------------------------------------------------------- diff --git a/examples/java/reactor/run b/examples/java/reactor/run deleted file mode 100755 index 51bd155..0000000 --- a/examples/java/reactor/run +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# 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. -# - -CLASS=$1 -shift -mvn -q -e exec:java -Dexec.mainClass=org.apache.qpid.proton.example.reactor.${CLASS} -Dexec.args="$*" --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
