activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject [09/18] Porting apollo examples structure to ActiveMQ 5.9.
Date Thu, 10 Oct 2013 14:40:32 GMT
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/QueueRoundTrip/QueueRoundTrip.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/QueueRoundTrip/QueueRoundTrip.java b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/QueueRoundTrip/QueueRoundTrip.java
new file mode 100644
index 0000000..9732501
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/QueueRoundTrip/QueueRoundTrip.java
@@ -0,0 +1,242 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * 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.
+ 
+Sample Application
+
+Queue/PTP
+Send and receive using multiple sessions and a temporary queue
+
+This sample shows the round trip time for a message being sent to the broker
+and received. A temporary queue is used to guarantee that each instance of this
+sample receives its own messages only.
+
+Usage:
+
+    java QueueRoundTrip -b <broker:port> -u <username> -p <password> -n <numTests> -h
+        Optional Parameters:
+        -b  broker:port    Broker name and port of your message server
+                            Default: tcp://localhost:61616
+        -u  username       Default: user (username required)
+        -p  password       Default: password (not checked)
+        -n  numTests       The number of messages to be sent/received
+                           Default: 100
+        -h                 Prints help screen.
+ */
+import org.apache.activemq.*;
+
+
+public class QueueRoundTrip
+{
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD    = "password";
+    private static final String DEFAULT_USER_NAME   = "user";
+    private static final int DEFAULT_NUM_TESTS      = 100;
+
+    private static final int msgSize = 1400;
+    private static byte[] msgBody = new byte[msgSize];
+
+    private javax.jms.ConnectionFactory factory = null;
+    private javax.jms.Connection connection     = null;
+    private javax.jms.Session sendSession       = null;
+    private javax.jms.Session receiveSession    = null;
+    private javax.jms.MessageProducer sender    = null;
+    private javax.jms.MessageConsumer receiver  = null;
+
+    private void QueueRoundTripper(String broker, String username, String password, int numTests){
+
+        try
+        {
+            //Set up two sessions, one for sending and the other for receiving
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connection = factory.createConnection(username, password);
+            sendSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
+            receiveSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println ("error: Cannot connect to broker- " + broker + ".\n");
+            jmse.printStackTrace ();
+            System.exit(1);
+        }
+
+        try
+        {
+            //Set up a temporary Queue:
+            javax.jms.TemporaryQueue tempQueue = sendSession.createTemporaryQueue();
+            receiver = receiveSession.createConsumer(tempQueue);
+            sender = sendSession.createProducer(tempQueue);
+            connection.start();
+        }
+        catch (javax.jms.JMSException jmse){
+            System.err.println("error: Connection couldn't be started.\n");
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        //Send messages using Temporary Queue:
+        try {
+            System.out.println("QueueRoundTrip application:");
+            System.out.println("===========================");
+            System.out.println("Sending Messages to Temporary Queue...");
+
+            //create a message to send
+            javax.jms.BytesMessage msg = sendSession.createBytesMessage();
+            msg.writeBytes(msgBody);
+
+            //send and receive the message the specified number of times:
+            long time = System.currentTimeMillis();
+            for (int i = 0; i < numTests; i++){
+                sender.send(msg);
+                msg = (javax.jms.BytesMessage)receiver.receive();
+            }
+            time = System.currentTimeMillis()-time;
+
+            System.out.println("\nTime for " + numTests + " sends and receives:\t\t" +
+                                time + "ms\n" +
+                                "Average Time per message:\t\t\t" + (float)time/(float)numTests + "ms\n");
+            System.out.println("\n\nPress Enter to close this window.");
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            stdin.readLine();
+            System.exit(0);
+        }
+
+        catch (javax.jms.JMSException jmse) {
+            System.err.println("error: message not sent/received.\n");
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        catch (java.io.IOException ioe) {
+            ioe.printStackTrace();
+        }
+
+
+    }
+
+        /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            connection.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    public static void main (String argv[])
+    {
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = DEFAULT_USER_NAME;
+        String password  = DEFAULT_PASSWORD;
+        int numTests = DEFAULT_NUM_TESTS;
+
+        // Check parameters
+        if(argv.length > 0){
+            for (int i = 0; i < argv.length; i++) {
+                String arg = argv[i];
+
+                // Options
+                if (!arg.startsWith("-")) {
+                    System.err.println ("error: unexpected argument - "+arg);
+                    printUsage();
+                    System.exit(1);
+                }
+                else {
+                    if (arg.equals("-b")) {
+                        if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                            System.err.println("error: missing broker name:port");
+                            System.exit(1);
+                        }
+                        broker = argv[++i];
+                        continue;
+                    }
+
+                    if (arg.equals("-u")) {
+                        if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                            System.err.println("error: missing user name");
+                            System.exit(1);
+                        }
+                        username = argv[++i];
+                        continue;
+                    }
+
+                    if (arg.equals("-p")) {
+                        if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                            System.err.println("error: missing password");
+                            System.exit(1);
+                        }
+                        password = argv[++i];
+                        continue;
+                    }
+                    if (arg.equals("-n")) {
+                        if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                            System.err.println("error: missing number of test to run.");
+                            System.exit(1);
+                        }
+                        numTests = (new Integer(argv[++i])).intValue();
+                        continue;
+                    }
+
+                    if (arg.equals("-h")) {
+                        printUsage();
+                        System.exit(1);
+                    }
+                }
+            }
+        }
+
+        // create the payload
+        byte charToWrite = (0x30);
+        for (int i = 0; i < msgSize; i++)
+        {
+            msgBody[i] = charToWrite;
+            charToWrite = (byte) ((int) charToWrite + (int) 0x01);
+            if (charToWrite == (0x39))
+            {
+                charToWrite = (0x30);
+            }
+        }
+
+        // Start the JMS client for the test.
+        QueueRoundTrip queueRoundTripper = new QueueRoundTrip();
+        queueRoundTripper.QueueRoundTripper(broker, username, password, numTests);
+
+    }
+
+    private static void printUsage()
+    {
+        StringBuffer use = new StringBuffer();
+
+        use.append("Usage:\n");
+        use.append("java QueueRoundTrip (options)...\n\n");
+        use.append("options:\n");
+        use.append("-b  broker:port    Broker name and port of your message server\n");
+        use.append("                   Default: tcp://localhost:61616\n");
+        use.append("-u  username       Default: user (username required)\n");
+        use.append("-p  password       Default: password (not checked)\n");
+        use.append("-n  numTests       The number of messages to be sent/received\n");
+        use.append("                   Default: 100\n");
+        use.append("-h                 This help screen");
+        System.err.println (use);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Replier.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Replier.java b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Replier.java
new file mode 100644
index 0000000..a7f521a
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Replier.java
@@ -0,0 +1,338 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * 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.
+ 
+Sample Application
+
+Writing a Basic JMS Application with Point-to-Point Queues,
+using:
+    - Synchronous Request/Reply
+    - javax.jms.QueueRequestor class
+    - JMSReplyTo Header
+
+When this program runs, it waits for messages on the queue,
+"SampleQ1" (by default).
+When that message arrives, a response based on the request
+is sent back to the "Requestor" specified in the JMSReplyTo header.
+
+This sample replies with a simple text manipulation of the request;
+the text is either folded to all UPPERCASE or all lowercase.
+
+Usage:
+  java Replier -b <broker:port> -u <username> -p <password> -qr <queue> -m <code>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+                     Default: SampleReplier
+      -p password    password for user (not checked)
+                     Default: password
+      -qr queue      name of queue for receiving requests
+                     Default:  Q1
+      -m mode        replier mode (uppercase, or lowercase)
+                     Default: uppercase
+
+Suggested demonstration:
+  - In a console window with the environment set,
+    start a copy of the Replier. For example:
+       java Replier -u SampleQReplier
+  - In another console window, start a Requestor.
+    For example:
+       java Requestor -u SampleQRequestor
+  - Enter text in the Requestor window then press Enter.
+    The Replier responds with the message in all uppercase characters.
+  - Start other Requestors with different user names to see that
+    replies are not broadcast to all users. For example:
+       java Requestor -u SampleRequestorFoo
+
+  - Start other Repliers.
+  - See that only one replier is receiving messages,(as it should).
+  - See the Requestor only receives one response.
+       java Replier -u toLower -m lowercase
+
+ */
+import org.apache.activemq.*;
+
+
+public class Replier
+    implements javax.jms.MessageListener
+{
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_USER_NAME = "SampleReplier";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final String DEFAULT_QUEUE = "Q1";
+    private static final String DEFAULT_MODE = "uppercase";
+    private static final int UPPERCASE = 0;
+    private static final int LOWERCASE = 1;
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session session = null;
+    private javax.jms.MessageProducer replier = null;
+
+    private int imode = UPPERCASE;
+
+    /** Create JMS client for sending and receiving messages. */
+    private void start ( String broker, String username, String password, String rQueue, String mode)
+    {
+        // Set the operation mode
+        imode = (mode.equals("uppercase")) ? UPPERCASE : LOWERCASE;
+
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            session = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Receivers to application queues as well as a Sender
+        // to use for JMS replies.
+        try
+        {
+            javax.jms.Queue queue = session.createQueue (rQueue);
+            javax.jms.MessageConsumer receiver = session.createConsumer(queue);
+            receiver.setMessageListener(this);
+            replier = session.createProducer(null);  // Queue will be set for each reply
+            // Now that all setup is complete, start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+            exit();
+        }
+
+        try
+        {
+            // Read standard input waiting for "EXIT" command.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            while ( true )
+            {
+                   System.out.println ("\nReplier application:\n"
+			            					+ "============================\n"
+			            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+											+ "The application gets requests with JMSReplyTo set on the " + DEFAULT_QUEUE + " queue."
+											+ "The message is transformed to all uppercase or all lowercase, and then returned to the requestor."
+			                                + "The Requestor application displays the result.\n\n"
+			                                + "Enter EXIT or press Ctrl+C to close the Replier.\n");
+                String s = stdin.readLine();
+                if ( s == null || s.equalsIgnoreCase("EXIT"))
+                {
+                    System.out.println ("\nStopping Replier. Please wait..\n>");
+                    exit();
+                }
+           }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+    }
+
+    /**
+     * Handle the message.
+     * (as specified in the javax.jms.MessageListener interface).
+     *
+     * IMPORTANT NOTES:
+     * (1)We must follow the design paradigm for JMS
+     *    synchronous requests.  That is, we must:
+     *     - get the message
+     *     - look for the header specifying JMSReplyTo
+     *     - send a reply to the queue specified there.
+     *    Failing to follow these steps might leave the originator
+     *    of the request waiting forever.
+     * (2)Unlike the 'Talk' sample and others using an asynchronous
+     *    message listener, it is possible here to use ONLY
+     *    ONE SESSION because the messages being sent are sent from
+     *    the same thread of control handling message delivery. For
+     *    more information see the JMS spec v1.0.2 section 4.4.6.
+     *
+     * OPTIONAL BEHAVIOR: The following actions taken by the
+     * message handler represent good programming style, but are
+     * not required by the design paradigm for JMS requests.
+     *   - set the JMSCorrelationID (tying the response back to
+     *     the original request.
+     *   - use transacted session "commit" so receipt of request
+     *     won't happen without the reply being sent.
+     *
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( "[Request] " + string );
+
+                // Check for a ReplyTo Queue
+                javax.jms.Queue replyQueue = (javax.jms.Queue) aMessage.getJMSReplyTo();
+                if (replyQueue != null)
+                {
+                    // Send the modified message back.
+                    javax.jms.TextMessage reply =  session.createTextMessage();
+                    if (imode == UPPERCASE)
+                        reply.setText("Uppercasing-" + string.toUpperCase());
+                    else
+                        reply.setText("Lowercasing-" + string.toLowerCase());
+                    reply.setJMSCorrelationID(aMessage.getJMSMessageID());
+                    replier.send (replyQueue, reply);
+                    session.commit();
+                }
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources cleanly and exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = DEFAULT_USER_NAME;
+        String password  = DEFAULT_PASSWORD;
+        String queue     = DEFAULT_QUEUE;
+        String mode      = DEFAULT_MODE;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-qr")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing queue");
+                    System.exit(1);
+                }
+                queue = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-m")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing mode");
+                    System.exit(1);
+                }
+                mode = argv[++i];
+                if (!(mode.equals("uppercase") || mode.equals("lowercase"))) {
+                    System.err.println("error: mode must be 'uppercase' or 'lowercase'");
+                    System.exit(1);
+                }
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client.
+        Replier replier = new Replier ();
+        replier.start (broker, username, password, queue, mode);
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java Replier (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name.\n");
+        use.append("               Default broker: "+DEFAULT_USER_NAME+"\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -m mode      Replier operating mode - uppercase or lowercase.\n");
+        use.append("               Default mode: "+DEFAULT_MODE+"\n");
+        use.append("  -qr queue    Specify name of queue for receiving.\n");
+        use.append("               Default queue: "+DEFAULT_QUEUE+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Requestor.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Requestor.java b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Requestor.java
new file mode 100644
index 0000000..73a2338
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/RequestReply/Requestor.java
@@ -0,0 +1,247 @@
+/*
+Copyright 2001-2008, Progress Software Corporation -  All Rights Reserved
+
+Sample Application
+
+Writing a Basic JMS Application with Point-to-Point Queues,
+using:
+    - Synchronous Request/Reply
+    - javax.jms.QueueRequestor class
+    - JMSReplyTo Header
+
+When this program runs, it reads input from System.in
+and then sends the text as a message to the queue, "Q1"
+(by default).
+
+A "Replier" class should be waiting for the request.
+It will reply with a message.
+
+NOTE: Unlike the Publish-Subscribe example, you need
+not run the Replier first.  However, this Requestor
+will block until the Replier is started to service the queue.
+
+Usage:
+  java Requestor -b <broker:port> -u <username> -p <password> -qs <queue>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+                     Default: SampleRequestor
+      -p password    password for user (not checked)
+                     Default: password
+      -qs queue      name of queue for sending requests
+                     Default: SampleQ1
+
+Suggested demonstration:
+  - In a console window with the environment set,
+    start a copy of the Replier. For example:
+       java Replier -u SampleQReplier
+  - In another console window, start a Requestor.
+    For example:
+       java Requestor -u SampleQRequestor
+  - Enter text in the Requestor window then press Enter.
+    The Replier responds with the message in all uppercase characters.
+  - Start other Requestors with different user names to see that
+    replies are not broadcast to all users. For example:
+       java Requestor -u SampleRequestorFoo
+  - Start other Repliers.
+  - See that only one replier is receiving messages,(as it should).
+  - See the Requestor only receives one response.
+       java Replier -u toLower -m lowercase
+
+*/
+import org.apache.activemq.*;
+
+
+public class Requestor
+{
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_USER_NAME = "SampleRequestor";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final String DEFAULT_QUEUE = "Q1";
+
+    private javax.jms.QueueConnection connect = null;
+    private javax.jms.QueueSession session = null;
+    private javax.jms.QueueRequestor requestor = null;
+
+    /** Create JMS client for sending messages. */
+    private void start ( String broker, String username, String password, String sQueue)
+    {
+        // Create a connection.
+        try
+        {
+            javax.jms.QueueConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createQueueConnection (username, password);
+            session = connect.createQueueSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create the Queue and QueueRequestor for sending requests.
+        javax.jms.Queue queue = null;
+        try
+        {
+            queue = session.createQueue (sQueue);
+            requestor = new javax.jms.QueueRequestor(session, queue);
+
+            // Now that all setup is complete, start the Connection.
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+            exit();
+        }
+
+        try
+        {
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            System.out.println ("\nRequestor application:\n"
+			            					+ "============================\n"
+			            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+											+ "The application uses a QueueRequestor to on the " + DEFAULT_QUEUE + " queue."
+											+ "The Replier application gets the message, and transforms it."
+			                                + "The Requestor application displays the result.\n\n"
+			                                + "Type some mixed case text, and then press Enter to make a request.\n");
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 )
+                {
+                    javax.jms.TextMessage msg = session.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // Instead of sending, we will use the QueueRequestor.
+                    javax.jms.Message response = requestor.request(msg);
+                    // The message should be a TextMessage.  Just report it.
+                    javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response;
+                    System.out.println( "[Reply] " + textMessage.getText() );
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources cleanly and exit. */
+    private void exit()
+    {
+        try
+        {
+            requestor.close();
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = DEFAULT_USER_NAME;
+        String password  = DEFAULT_PASSWORD;
+        String queue     = DEFAULT_QUEUE;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-qs")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing queue");
+                    System.exit(1);
+                }
+                queue = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client for sending requests.
+        Requestor requestor = new Requestor();
+        requestor.start (broker, username, password, queue);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java Requestor (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name.\n");
+        use.append("               Default broker: "+DEFAULT_USER_NAME+"\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -qs queue    Specify name of queue for sending.\n");
+        use.append("               Default queue: "+DEFAULT_QUEUE+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/SelectorTalk/SelectorTalk.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/SelectorTalk/SelectorTalk.java b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/SelectorTalk/SelectorTalk.java
new file mode 100644
index 0000000..f2609e7
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/SelectorTalk/SelectorTalk.java
@@ -0,0 +1,351 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * 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.
+ 
+Sample Application
+
+Writing a Basic JMS Application using Point-to-Point (Queues) with
+a Message Selector
+
+This sample starts up with a username, and the queues you are
+sending on, and receiving on.
+
+When messages are sent to a queue a property is set in the message header to
+a property value supplied on the command line. A separate command line
+value is used as a message selector for messages in the receive queue. In this
+sample we choose to create a property named "Department"
+
+Writing a line and pressing enter will send the message only to the
+indicated 'Talk' partner (or QueueReceiver).
+
+Usage:
+  java SelectorTalk -b <broker:port> -u <username> -p <password> -qs <queue> -qr <queue>
+            -s <selection>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    password for user (not checked)
+      -qr queue      name of queue to receive
+      -qs queue      name of queue to send
+      -s selector    the message selection value
+
+You must specify either a queue for sending or receiving (or both) as well as
+a value with which to select received messages.
+
+
+Suggested demonstration:
+  - In separate console windows with the environment set,
+    start instances of the application under unique user names.
+    For example:
+       java SelectorTalk -u BOB -s SALES -qr  Q1 -qs  Q2
+       java SelectorTalk -u SALLY -s SALES -qr  Q2 -qs   Q1
+  - Enter text and then press Enter to send the message.
+  - See messages appear under the user's indicated name.
+  - Try changing the message selector on one console and note that it will
+    no longer receive messages.
+  - Stop a session by pressing CTRL+C in its console window.
+
+*/
+import org.apache.activemq.*;
+
+public class SelectorTalk
+    implements javax.jms.MessageListener
+{
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String PROPERTY_NAME = "Department";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final int    MESSAGE_LIFESPAN = 1800000;  // milliseconds (30 minutes)
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session sendSession = null;
+    private javax.jms.Session receiveSession = null;
+    private javax.jms.MessageProducer sender = null;
+
+    /** Create JMS client for sending and receiving messages. */
+    private void talker( String broker, String username, String password, String rQueue, String sQueue, String selection)
+    {
+        // Create a connection.
+        try
+         {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            sendSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            receiveSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Sender and Receiver 'Talk' queues
+        try
+        {
+            if (sQueue != null)
+            {
+                javax.jms.Queue sendQueue = sendSession.createQueue (sQueue);
+                sender = sendSession.createProducer(sendQueue);
+            }
+            if (rQueue != null)
+            {
+                //NOTE: the Queue Receiver is set up with the Message Selector:
+                javax.jms.Queue receiveQueue = receiveSession.createQueue (rQueue);
+                javax.jms.MessageConsumer qReceiver = receiveSession.createConsumer(receiveQueue, PROPERTY_NAME + " = \'" + selection + "\'");
+                qReceiver.setMessageListener(this);
+                connect.start();
+            }
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+            exit();
+        }
+
+        try
+        {
+            if (rQueue != null)
+               System.out.println ("");
+            else
+               System.out.println ("\nNo receiving queue specified.\n");
+
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            if (sQueue != null)
+                System.out.println ("SelectorTalk application:\n"
+			            	      + "=========================\n"
+			            	  + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+							  + "The application will send messages with " + PROPERTY_NAME + " set to " + selection + " to the " + sQueue + " queue.\n"
+                              + "The application creates a receiver on the " + rQueue + " queue selecting only messages where " + PROPERTY_NAME + " is " + selection + ".\n\n"
+
+							  + "Type some text, and then press Enter to publish it as a TextMesssage from " + username + ".\n");
+            else
+                System.out.println ("\nPress CTRL-C to exit.\n");
+
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 && sQueue != null)
+                {
+                    javax.jms.TextMessage msg = sendSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // NOTE: here we set the property for each sent message.
+                    msg.setStringProperty(PROPERTY_NAME, selection);
+                    sender.send( msg,
+                                 javax.jms.DeliveryMode.PERSISTENT,
+                                 javax.jms.Message.DEFAULT_PRIORITY,
+                                 MESSAGE_LIFESPAN);
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+        // Close the connection.
+        exit();
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    	= DEFAULT_BROKER_NAME;
+        String username  	= null;
+        String password  	= DEFAULT_PASSWORD;
+        String qSender		= null;
+        String qReceiver	= null;
+        String selection    = null;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+            // Options
+            if (!arg.startsWith("-")) {
+                System.err.println ("error: unexpected argument - "+arg);
+                printUsage();
+                System.exit(1);
+            }
+            else {
+                if (arg.equals("-b")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing broker name:port");
+                        System.exit(1);
+                    }
+                    broker = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-u")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing user name");
+                        System.exit(1);
+                    }
+                    username = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-p")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing password");
+                        System.exit(1);
+                    }
+                    password = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-qr")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing receive queue parameter");
+                        System.exit(1);
+                    }
+                    qReceiver = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-qs")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing send queue parameter");
+                        System.exit(1);
+                    }
+                    qSender = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-s")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing selectiion");
+                        System.exit(1);
+                    }
+                    selection = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-h")) {
+                    printUsage();
+                    System.exit(1);
+                }
+            }
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        if (qReceiver == null && qSender == null) {
+            System.err.println ("error: receive queue, or send queue, must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        if (selection == null) {
+            System.err.println ("error: selection must be supplied (e.g. -s SALES)\n");
+            printUsage();
+            System.exit(1);
+        }
+
+
+        // Start the JMS client for the "Talk".
+        SelectorTalk talk = new SelectorTalk();
+        talk.talker (broker, username, password, qReceiver, qSender, selection);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java SelectorTalk (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b  name:port Specify name:port of broker.\n");
+        use.append("                Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u  name      Specify unique user name. (Required)\n");
+        use.append("  -p  password  Specify password for user.\n");
+        use.append("                Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -qr queue     Specify queue for receiving messages.\n");
+        use.append("  -qs queue     Specify queue for sending messages.\n");
+        use.append("  -s  selection required, selection used to receive messages.\n");
+        use.append("  -h            This help screen.\n");
+        System.err.println (use);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/Talk/Talk.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/Talk/Talk.java b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/Talk/Talk.java
new file mode 100644
index 0000000..e849fcc
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/Talk/Talk.java
@@ -0,0 +1,332 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * 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.
+ 
+Sample Application
+
+Writing a Basic JMS Application using Point-to-Point (Queues).
+This sample starts up with a username, and the queues you are
+sending on, and receiving on.
+
+Writing a line and pressing enter will send the message only to the
+indicated 'Talk' partner (or QueueReceiver).
+
+Usage:
+  java Talk -b <broker:port> -u <username> -p <password> -qs <queue> -qr <queue>
+      -b broker:port points to your message broker
+                Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    password for user (not checked)
+      -qr queue      name of queue to receive
+      -qs queue      name of queue to send
+
+You must specify either a queue for sending or receiving (or both).
+
+
+Suggested demonstration:
+  - In separate console windows with the environment set,
+    start instances of the application under unique user names.
+    For example:
+       java Talk -b localhost:2506 -u SALES -qr  Q1 -qs  Q2
+       java Talk -b localhost:2506 -u MARKETTING -qr  Q2 -qs  Q1
+  - Enter text and then press Enter to send the message.
+  - A message is consumed by only one of the receivers on a queue.
+  - Stop a session by pressing CTRL+C in its console window.
+
+*/
+import org.apache.activemq.*;
+
+
+public class Talk
+    implements javax.jms.MessageListener
+{
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final int    MESSAGE_LIFESPAN = 1800000;  // milliseconds (30 minutes)
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session sendSession = null;
+    private javax.jms.Session receiveSession = null;
+    private javax.jms.MessageProducer sender = null;
+
+    /** Create JMS client for sending and receiving messages. */
+    private void talker( String broker, String username, String password, String rQueue, String sQueue)
+    {
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            sendSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            receiveSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Sender and Receiver 'Talk' queues
+        try
+        {
+            if (sQueue != null)
+            {
+                javax.jms.Queue sendQueue = sendSession.createQueue (sQueue);
+                sender = sendSession.createProducer(sendQueue);
+            }
+            if (rQueue != null)
+            {
+                javax.jms.Queue receiveQueue = receiveSession.createQueue (rQueue);
+                javax.jms.MessageConsumer qReceiver = receiveSession.createConsumer(receiveQueue);
+                qReceiver.setMessageListener(this);
+                // Now that 'receive' setup is complete, start the Connection
+                connect.start();
+            }
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+            exit();
+        }
+
+        try
+        {
+            if (rQueue != null)
+               System.out.println ("");
+            else
+               System.out.println ("\nNo receiving queue specified.\n");
+
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            if (sQueue != null)
+                System.out.println ("\nTalk application:\n"
+            					+ "=================\n"
+            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+								+ "The application will send messages to the " + sQueue + " queue.\n"
+                                + "The application creates a receiver on the " + rQueue + " queue to consume any messages allocated to it.\n\n"
+                                + "Type some text, and then press Enter to send it as a TextMesssage from " + username + ".\n");
+
+            else
+                System.out.println ("\nPress CTRL-C to exit.\n");
+
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 && sQueue != null)
+                {
+                    javax.jms.TextMessage msg = sendSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // Queues usually are used for PERSISTENT messages.
+                    // Hold messages for 30 minutes (1,800,000 millisecs).
+                    sender.send( msg,
+                                 javax.jms.DeliveryMode.PERSISTENT,
+                                 javax.jms.Message.DEFAULT_PRIORITY,
+                                 MESSAGE_LIFESPAN);
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+        // Close the connection.
+        exit();
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+             // Otherwise report that invalid message arrived.
+            if (aMessage instanceof javax.jms.TextMessage)
+            {
+            	javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            	// This handler reads a single String from the
+            	// message and prints it to the standard output.
+            	try
+            	{
+                	String string = textMessage.getText();
+                	System.out.println( string );
+           		}
+            	catch (javax.jms.JMSException jmse)
+            	{
+            	    jmse.printStackTrace();
+            	}
+          	}
+			else
+			{
+			    System.out.println ("Warning: A message was discarded because it could not be processed " +
+			                                    "as a javax.jms.TextMessage.");
+			 }
+
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    	= DEFAULT_BROKER_NAME;
+        String username  	= null;
+        String password  	= DEFAULT_PASSWORD;
+        String qSender		= null;
+        String qReceiver	= null;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+            // Options
+            if (!arg.startsWith("-")) {
+                System.err.println ("error: unexpected argument - "+arg);
+                printUsage();
+                System.exit(1);
+            }
+            else {
+                if (arg.equals("-b")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing broker name:port");
+                        System.exit(1);
+                    }
+                    broker = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-u")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing user name");
+                        System.exit(1);
+                    }
+                    username = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-p")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing password");
+                        System.exit(1);
+                    }
+                    password = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-qr")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing receive queue parameter");
+                        System.exit(1);
+                    }
+                    qReceiver = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-qs")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing send queue parameter");
+                        System.exit(1);
+                    }
+                    qSender = argv[++i];
+                    continue;
+                }
+
+
+                if (arg.equals("-h")) {
+                    printUsage();
+                    System.exit(1);
+                }
+            }
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        if (qReceiver == null && qSender == null) {
+            System.err.println ("error: receive queue, or send queue, must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client for the "Talk".
+        Talk talk = new Talk();
+        talk.talker (broker, username, password, qReceiver, qSender);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java Talk (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name. (Required)\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -qr queue    Specify queue for receiving messages.\n");
+        use.append("  -qs queue    Specify queue for sending messages.\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/TransactedTalk/TransactedTalk.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/TransactedTalk/TransactedTalk.java b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/TransactedTalk/TransactedTalk.java
new file mode 100644
index 0000000..783a7f4
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/QueuePTPSamples/TransactedTalk/TransactedTalk.java
@@ -0,0 +1,360 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * 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.
+ 
+Sample Application
+
+Writing a Basic JMS Application with Point-to-Point Queues,
+using:
+    - Send and Receive
+    - Transacted Sessions
+    - Multiple Sessions
+
+This sample starts up with a username, and the queues you are
+sending on, and receiving on.
+
+Continue writing lines and pressing enter to buffer messages until a
+specific key word is used to confirm the messages or to completely
+forget them.
+
+Messages are buffered and sent when a specific string is seen ("COMMIT").
+Messages buffered can be discarded by entering a specified string ("CANCEL").
+
+Usage:
+  java TransactedTalk -b <broker:port> -u <username> -p <password> -qs <queue> -qr <queue>
+      -b broker:port points to your message broker
+                Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    password for user (not checked)
+      -qr queue      name of queue to receive
+      -qs queue      name of queue to send
+
+You must specify either a queue for sending or receiving (or both).
+
+Suggested demonstration:
+  - In separate console windows with the environment set,
+    start instances of the application under unique user names.
+    For example:
+       java TransactedTalk -u OPERATIONS -qr  Q1 -qs  Q2
+       java TransactedTalk -u FACILITIES -qr  Q2 -qs  Q1
+  - Type some text and then press Enter.
+  - Repeat to create a batch of messages.
+  - Send the batched messages by entering the text "COMMIT"
+  - Discard the batched messages by entering the text "CANCEL"
+  - Stop a session by pressing CTRL+C in its console window.
+
+*/
+
+import org.apache.activemq.*;
+
+public class TransactedTalk
+    implements javax.jms.MessageListener
+{
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final int    MESSAGE_LIFESPAN = 1800000;  // milliseconds (30 minutes)
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session sendSession = null;
+    private javax.jms.Session receiveSession = null;
+    private javax.jms.MessageProducer sender = null;
+
+
+
+
+    /** Create JMS client for sending and receiving messages. */
+    private void talker( String broker, String username, String password, String rQueue, String sQueue)
+    {
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            // We want to be able up commit/rollback messages sent,
+            // but not affect messages received.  Therefore, we need two sessions.
+            sendSession = connect.createSession(true,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            receiveSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Sender and Receiver 'Talk' queues
+        try
+        {
+            if (sQueue != null)
+            {
+                javax.jms.Queue sendQueue = sendSession.createQueue (sQueue);
+                sender = sendSession.createProducer(sendQueue);
+            }
+            if (rQueue != null)
+            {
+                javax.jms.Queue receiveQueue = receiveSession.createQueue (rQueue);
+                javax.jms.MessageConsumer qReceiver = receiveSession.createConsumer(receiveQueue);
+                qReceiver.setMessageListener(this);
+                // Now that 'receive' setup is complete, start the Connection
+                connect.start();
+            }
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+            exit();
+        }
+
+        try
+        {
+            if (rQueue != null)
+               System.out.println ("");
+            else
+               System.out.println ("\nNo receiving queue specified.\n");
+
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+
+            if (sQueue != null){
+                    System.out.println ("TransactedTalk application:");
+	                System.out.println ("===========================" );
+                    System.out.println ("The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".");
+					System.out.println ("The application will stage messages to " + sQueue + " until you either commit them or roll them back.");
+				    System.out.println ("The application receives messages on " + rQueue + " to consume any committed messages sent there.\n");
+                    System.out.println ("1. Enter text to send and then press Enter to stage the message.");
+                    System.out.println ("2. Add a few messages to the transaction batch.");
+                    System.out.println ("3. Then, either:");
+                    System.out.println ("     o Enter the text 'COMMIT', and press Enter to send all the staged messages.");
+                    System.out.println ("     o Enter the text 'CANCEL', and press Enter to drop the staged messages waiting to be sent.");
+            }
+            else
+                System.out.println ("\nPress CTRL-C to exit.\n");
+
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if (s.trim().equals("CANCEL"))
+                {
+                    // Rollback the messages. A new transaction is implicitly
+                    // started for following messages.
+                    System.out.print ("Cancelling messages...");
+                    sendSession.rollback();
+                    System.out.println ("Staged messages have been cleared.");
+                }
+                else if ( s.length() > 0 && sQueue != null)
+                {
+                    javax.jms.TextMessage msg = sendSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // Queues usually are used for PERSISTENT messages.
+                    // Hold messages for 30 minutes (1,800,000 millisecs).
+                    sender.send( msg,
+                                 javax.jms.DeliveryMode.PERSISTENT,
+                                 javax.jms.Message.DEFAULT_PRIORITY,
+                                 MESSAGE_LIFESPAN);
+                    // See if we should send the messages
+                    if (s.trim().equals("COMMIT"))
+                    {
+                        // Commit (send) the messages. A new transaction is
+                        // implicitly  started for following messages.
+                        System.out.print ("Committing messages...");
+                        sendSession.commit();
+                        System.out.println ("Staged messages have all been sent.");
+                    }
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+        // Close the connection.
+        exit();
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            sendSession.rollback(); // Rollback any uncommitted messages.
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    	= DEFAULT_BROKER_NAME;
+        String username  	= null;
+        String password  	= DEFAULT_PASSWORD;
+        String qSender		= null;
+        String qReceiver	= null;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+            // Options
+            if (!arg.startsWith("-")) {
+                System.err.println ("error: unexpected argument - "+arg);
+                printUsage();
+                System.exit(1);
+            }
+            else {
+                if (arg.equals("-b")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing broker name:port");
+                        System.exit(1);
+                    }
+                    broker = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-u")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing user name");
+                        System.exit(1);
+                    }
+                    username = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-p")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing password");
+                        System.exit(1);
+                    }
+                    password = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-qr")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing receive queue parameter");
+                        System.exit(1);
+                    }
+                    qReceiver = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-qs")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing send queue parameter");
+                        System.exit(1);
+                    }
+                    qSender = argv[++i];
+                    continue;
+                }
+
+
+                if (arg.equals("-h")) {
+                    printUsage();
+                    System.exit(1);
+                }
+            }
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        if (qReceiver == null && qSender == null) {
+            System.err.println ("error: receive queue, or send queue, must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client for the "Talk".
+        TransactedTalk tranTalk = new TransactedTalk();
+        tranTalk.talker (broker, username, password, qReceiver, qSender);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java TransactedTalk (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name. (Required)\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -qr queue    Specify queue for receiving messages.\n");
+        use.append("  -qs queue    Specify queue for sending messages.\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/Chat/Chat.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/Chat/Chat.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/Chat/Chat.java
new file mode 100644
index 0000000..1ede2bc
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/Chat/Chat.java
@@ -0,0 +1,262 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * 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.
+ 
+Sample Application
+
+Writing a Basic JMS Application using Publish and Subscribe
+
+This sample publishes and subscribes to a specified topic.
+Text you enter is published and then received by all subscribers.
+
+Usage:
+  java Chat -b <broker:port> -u <username> -p <password>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    password for user (not checked)
+
+Suggested demonstration:
+  - In separate console windows with the environment set,
+    start instances of the application
+    under unique user names.
+    For example:
+       java Chat -b tcp://localhost:61616 -u SALES
+       java Chat -b tcp://localhost:61616 -u MARKETING
+  - Enter text and then press Enter to publish the message.
+  - See messages appear under the various user names as you
+    enter messages in each console window.
+  - Stop a session by pressing CTRL+C in its console window.
+
+*/
+import org.apache.activemq.*;
+
+public class Chat
+    implements javax.jms.MessageListener
+{
+    private static final String APP_TOPIC = "jms.samples.chat";
+    private static final String DEFAULT_USER = "Chatter";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD = "password";
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session pubSession = null;
+    private javax.jms.Session subSession = null;
+    private javax.jms.MessageProducer publisher = null;
+
+    /** Create JMS client for publishing and subscribing to messages. */
+    private void chatter( String broker, String username, String password)
+    {
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            pubSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            subSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Publisher and Subscriber to 'chat' topics
+        try
+        {
+            javax.jms.Topic topic = pubSession.createTopic (APP_TOPIC);
+            javax.jms.MessageConsumer subscriber = subSession.createConsumer(topic);
+            subscriber.setMessageListener(this);
+            publisher = pubSession.createProducer(topic);
+            // Now that setup is complete, start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        try
+        {
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            System.out.println ("\nChat application:\n"
+            					+ "=================\n"
+            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+								+ "The application will publish messages to the " + APP_TOPIC + " topic.\n"
+                                + "The application also subscribes to that topic to consume any messages published there.\n\n"
+                                + "Type some text, and then press Enter to publish it as a TextMesssage from " + username + ".\n");
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 )
+                {
+                    javax.jms.TextMessage msg = pubSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    publisher.send( msg );
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = null;
+        String password  = DEFAULT_PASSWORD;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client for the "chat".
+        Chat chat = new Chat();
+        chat.chatter (broker, username, password);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java Chat (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name. (Required)\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+


Mime
View raw message