User: kimptoc 
  Date: 01/04/01 13:36:17

  Modified:    src/examples RequestReplyQueue.java
  Log:
  patch to the request reply example to make it work - was complaining about 
persistent msgs on temp queues
  
  Revision  Changes    Path
  1.2       +40 -35    jbossmq/src/examples/RequestReplyQueue.java
  
  Index: RequestReplyQueue.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/examples/RequestReplyQueue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestReplyQueue.java    2001/01/26 00:42:42     1.1
  +++ RequestReplyQueue.java    2001/04/01 20:36:17     1.2
  @@ -1,8 +1,8 @@
   /*
  - * @(#)RequestReplyQueue.java        1.5 00/08/14
  - * 
  + * @(#)RequestReplyQueue.java   1.5 00/08/14
  + *
    * Copyright (c) 2000 Sun Microsystems, Inc. All Rights Reserved.
  - * 
  + *
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
    * modify and redistribute this software in source and binary code form,
    * provided that i) this copyright notice and license appear on all copies of
  @@ -35,7 +35,7 @@
    * by JMS.  Providers and clients can create more sophisticated versions of
    * this facility.
    * <p>
  - * The program contains a Request class, a Reply class, a main method, and 
  + * The program contains a Request class, a Reply class, a main method, and
    * a method that runs the sender and receiver threads.
    *
    * @author Kim Haase
  @@ -46,13 +46,13 @@
       int     exitResult = 0;
   
       /**
  -     * The Request class represents the request half of the message exchange.  
  +     * The Request class represents the request half of the message exchange.
        *
        * @author Kim Haase
        * @version 1.5, 08/14/00
        */
       public class Request extends Thread {
  -        
  +
           /**
            * Runs the thread.
            */
  @@ -68,11 +68,11 @@
               String                  replyID = null;
   
               try {
  -                queueConnectionFactory = 
  +                queueConnectionFactory =
                       SampleUtilities.getQueueConnectionFactory();
  -                queueConnection = 
  +                queueConnection =
                       queueConnectionFactory.createQueueConnection();
  -                queueSession = queueConnection.createQueueSession(false, 
  +                queueSession = queueConnection.createQueueSession(false,
                       Session.AUTO_ACKNOWLEDGE);
                   queue = SampleUtilities.getQueue(queueName, queueSession);
               } catch (Exception e) {
  @@ -83,18 +83,18 @@
                       } catch (JMSException ee) {}
                   }
                   System.exit(1);
  -            } 
  +            }
   
  -            /*  
  +            /*
                * Create a QueueRequestor.
                * Create a text message and set its text.
                * Start delivery of incoming messages.
  -             * Send the text message as the argument to the request method, 
  +             * Send the text message as the argument to the request method,
                * which returns the reply message.  The request method also
                * creates a temporary queue and places it in the JMSReplyTo
                * message header field.
                * Extract and display the reply message.
  -             * Read the JMSCorrelationID of the reply message and confirm that 
  +             * Read the JMSCorrelationID of the reply message and confirm that
                * it matches the JMSMessageID of the message that was sent.
                * Finally, close the connection.
                */
  @@ -102,11 +102,11 @@
                   queueRequestor = new QueueRequestor(queueSession, queue);
                   message = queueSession.createTextMessage();
                   message.setText(MSG_TEXT);
  -                System.out.println("REQUEST: Sending message: " 
  +                System.out.println("REQUEST: Sending message: "
                       + message.getText());
                   queueConnection.start();
                   reply = (TextMessage) queueRequestor.request(message);
  -                System.out.println("REQUEST: Reply received: " 
  +                System.out.println("REQUEST: Reply received: "
                       + reply.getText());
                   replyID = new String(reply.getJMSCorrelationID());
                   if (replyID.equals(message.getJMSMessageID())) {
  @@ -150,18 +150,18 @@
               QueueSession            queueSession = null;
               Queue                   queue = null;
               QueueReceiver           queueReceiver = null;
  -            TextMessage             message = null; 
  +            TextMessage             message = null;
               Queue                   tempQueue = null;
               QueueSender             replySender = null;
  -            TextMessage             reply = null; 
  +            TextMessage             reply = null;
               final String            REPLY_TEXT = new String("Here is a reply");
   
               try {
  -                queueConnectionFactory = 
  +                queueConnectionFactory =
                       SampleUtilities.getQueueConnectionFactory();
  -                queueConnection = 
  +                queueConnection =
                       queueConnectionFactory.createQueueConnection();
  -                queueSession = queueConnection.createQueueSession(false, 
  +                queueSession = queueConnection.createQueueSession(false,
                       Session.AUTO_ACKNOWLEDGE);
                   queue = SampleUtilities.getQueue(queueName, queueSession);
               } catch (Exception e) {
  @@ -174,24 +174,24 @@
                   System.exit(1);
               }
   
  -            /* 
  +            /*
                * Create a QueueReceiver.
                * Start delivery of incoming messages.
                * Call receive, which blocks until it obtains a message.
                * Display the message obtained.
  -             * Extract the temporary reply queue from the JMSReplyTo field of 
  +             * Extract the temporary reply queue from the JMSReplyTo field of
                * the message header.
                * Use the temporary queue to create a sender for the reply message.
  -             * Create the reply message, setting the JMSCorrelationID to the 
  +             * Create the reply message, setting the JMSCorrelationID to the
                * value of the incoming message's JMSMessageID.
                * Send the reply message.
  -             * Finally, close the connection. 
  -             */    
  +             * Finally, close the connection.
  +             */
               try {
                   queueReceiver = queueSession.createReceiver(queue);
                   queueConnection.start();
                   message = (TextMessage) queueReceiver.receive();
  -                System.out.println("REPLY: Message received: " 
  +                System.out.println("REPLY: Message received: "
                       + message.getText());
                   tempQueue = (Queue) message.getJMSReplyTo();
                   replySender = queueSession.createSender(tempQueue);
  @@ -199,6 +199,11 @@
                   reply.setText(REPLY_TEXT);
                   reply.setJMSCorrelationID(message.getJMSMessageID());
                   System.out.println("REPLY: Sending reply: " + reply.getText());
  +
  +                //HACK - senders are persistent by default - but the request/reply 
via queue requestor
  +                // uses a temporary queue - which dont go!
  +                replySender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
  +
                   replySender.send(reply);
               } catch (JMSException e) {
                   System.out.println("Exception occurred: " + e.toString());
  @@ -218,7 +223,7 @@
               }
           }
       }
  -        
  +
       /**
        * Instantiates the Request and Reply classes and starts their
        * threads.
  @@ -240,21 +245,21 @@
        * Reads the queue name from the command line, then calls the
        * run_threads method to execute the program threads.
        *
  -     * @param args   the queue used by the example
  +     * @param args  the queue used by the example
        */
       public static void main(String[] args) {
           RequestReplyQueue  rrq = new RequestReplyQueue();
  -        
  +
           if (args.length != 1) {
  -         System.out.println("Usage: java RequestReplyQueue <queue_name>");
  -         System.exit(1);
  -     }
  -     
  +            System.out.println("Usage: java RequestReplyQueue <queue_name>");
  +            System.exit(1);
  +        }
  +        
           rrq.queueName = new String(args[0]);
           System.out.println("Queue name is " + rrq.queueName);
   
  -     rrq.run_threads();
  -     SampleUtilities.exit(rrq.exitResult);
  +        rrq.run_threads();
  +        SampleUtilities.exit(rrq.exitResult);
       }
   }
   
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to