User: hiram   
  Date: 01/01/03 15:26:16

  Modified:    examples AckEquivExample.java
  Log:
  BugFix: SpyderMQ durable topic subscriptions are only allowed with valid 
user/password
  
  Revision  Changes    Path
  1.2       +405 -405  spyderMQ/examples/AckEquivExample.java
  
  Index: AckEquivExample.java
  ===================================================================
  RCS file: /products/cvs/ejboss/spyderMQ/examples/AckEquivExample.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AckEquivExample.java      2000/12/12 21:30:45     1.1
  +++ AckEquivExample.java      2001/01/03 23:26:16     1.2
  @@ -58,413 +58,413 @@
    * @version 1.6, 08/18/00
    */
   public class AckEquivExample {
  -    final String  CONTROL_QUEUE = "controlQueue";
  -    String        queueName = null;
  -    String        topicName = null;
  -    int           exitResult = 0;
  -
  -    /**
  -     * The SynchSender class creates a session in CLIENT_ACKNOWLEDGE mode and
  -     * sends a message.
  -     *
  -     * @author Kim Haase
  -     * @version 1.6, 08/18/00
  -     */
  -    public class SynchSender extends Thread {
  -        
  -        /**
  -         * Runs the thread.
  -         */
  -        public void run() {
  -            QueueConnectionFactory  queueConnectionFactory = null;
  -            QueueConnection         queueConnection = null;
  -            QueueSession            queueSession = null;
  -            Queue                   queue = null;
  -            QueueSender             queueSender = null;
  -            final String            MSG_TEXT = 
  -                             new String("Here is a client-acknowledge message");
  -            TextMessage             message = null;
  -
  -            try {
  -                queueConnectionFactory = 
  -                    SampleUtilities.getQueueConnectionFactory();
  -                queueConnection = 
  -                    queueConnectionFactory.createQueueConnection();
  -                queueSession = queueConnection.createQueueSession(false, 
  -                    Session.CLIENT_ACKNOWLEDGE);
  -                queue = SampleUtilities.getQueue(queueName, queueSession);
  -            } catch (Exception e) {
  -                System.out.println("Connection problem: " + e.toString());
  -                if (queueConnection != null) {
  -                    try {
  -                        queueConnection.close();
  -                    } catch (JMSException ee) {}
  -                }
  -                System.exit(1);
  -            }
  -
  -            /*
  -             * Create client-acknowledge sender.
  -             * Create and send message.
  -             */
  -            try {
  -                System.out.println("  SENDER: Created client-acknowledge session");
  -                queueSender = queueSession.createSender(queue);
  -                message = queueSession.createTextMessage();
  -                message.setText(MSG_TEXT);
  -                System.out.println("  SENDER: Sending message: " 
  -                    + message.getText());
  -                queueSender.send(message);
  -            } catch (JMSException e) {
  -                System.out.println("Exception occurred: " + e.toString());
  -                exitResult = 1;
  -            } finally {
  -                if (queueConnection != null) {
  -                    try {
  -                        queueConnection.close();
  -                    } catch (JMSException e) {
  -                        exitResult = 1;
  -                    }
  -                }
  -            }
  -        }
  -    }
  +     final String  CONTROL_QUEUE = "controlQueue";
  +     String        queueName = null;
  +     String        topicName = null;
  +     int           exitResult = 0;
  +
  +     /**
  +      * The SynchSender class creates a session in CLIENT_ACKNOWLEDGE mode and
  +      * sends a message.
  +      *
  +      * @author Kim Haase
  +      * @version 1.6, 08/18/00
  +      */
  +     public class SynchSender extends Thread {
  +             
  +             /**
  +              * Runs the thread.
  +              */
  +             public void run() {
  +                     QueueConnectionFactory  queueConnectionFactory = null;
  +                     QueueConnection         queueConnection = null;
  +                     QueueSession            queueSession = null;
  +                     Queue                   queue = null;
  +                     QueueSender             queueSender = null;
  +                     final String            MSG_TEXT = 
  +                                                      new String("Here is a 
client-acknowledge message");
  +                     TextMessage             message = null;
  +
  +                     try {
  +                             queueConnectionFactory = 
  +                                     SampleUtilities.getQueueConnectionFactory();
  +                             queueConnection = 
  +                                     queueConnectionFactory.createQueueConnection();
  +                             queueSession = 
queueConnection.createQueueSession(false, 
  +                                     Session.CLIENT_ACKNOWLEDGE);
  +                             queue = SampleUtilities.getQueue(queueName, 
queueSession);
  +                     } catch (Exception e) {
  +                             System.out.println("Connection problem: " + 
e.toString());
  +                             if (queueConnection != null) {
  +                                     try {
  +                                             queueConnection.close();
  +                                     } catch (JMSException ee) {}
  +                             }
  +                             System.exit(1);
  +                     }
  +
  +                     /*
  +                      * Create client-acknowledge sender.
  +                      * Create and send message.
  +                      */
  +                     try {
  +                             System.out.println("  SENDER: Created 
client-acknowledge session");
  +                             queueSender = queueSession.createSender(queue);
  +                             message = queueSession.createTextMessage();
  +                             message.setText(MSG_TEXT);
  +                             System.out.println("  SENDER: Sending message: " 
  +                                     + message.getText());
  +                             queueSender.send(message);
  +                     } catch (JMSException e) {
  +                             System.out.println("Exception occurred: " + 
e.toString());
  +                             exitResult = 1;
  +                     } finally {
  +                             if (queueConnection != null) {
  +                                     try {
  +                                             queueConnection.close();
  +                                     } catch (JMSException e) {
  +                                             exitResult = 1;
  +                                     }
  +                             }
  +                     }
  +             }
  +     }
       
  -    /**
  -     * The SynchReceiver class creates a session in CLIENT_ACKNOWLEDGE mode and
  -     * receives the message sent by the SynchSender class.
  -     *
  -     * @author Kim Haase
  -     * @version 1.6, 08/18/00
  -     */
  -    public class SynchReceiver extends Thread {
  -
  -        /**
  -         * Runs the thread.
  -         */
  -     public void run() {
  -            QueueConnectionFactory  queueConnectionFactory = null;
  -            QueueConnection         queueConnection = null;
  -            QueueSession            queueSession = null;
  -            Queue                   queue = null;
  -            QueueReceiver           queueReceiver = null;
  -            TextMessage             message = null;
  -
  -            try {
  -                queueConnectionFactory = 
  -                    SampleUtilities.getQueueConnectionFactory();
  -                queueConnection = 
  -                    queueConnectionFactory.createQueueConnection();
  -                queueSession = queueConnection.createQueueSession(false, 
  -                    Session.CLIENT_ACKNOWLEDGE);
  -                queue = SampleUtilities.getQueue(queueName, queueSession);
  -            } catch (Exception e) {
  -                System.out.println("Connection problem: " + e.toString());
  -                if (queueConnection != null) {
  -                    try {
  -                        queueConnection.close();
  -                    } catch (JMSException ee) {}
  -                }
  -                System.exit(1);
  -            }
  +     /**
  +      * The SynchReceiver class creates a session in CLIENT_ACKNOWLEDGE mode and
  +      * receives the message sent by the SynchSender class.
  +      *
  +      * @author Kim Haase
  +      * @version 1.6, 08/18/00
  +      */
  +     public class SynchReceiver extends Thread {
  +
  +             /**
  +              * Runs the thread.
  +              */
  +             public void run() {
  +                     QueueConnectionFactory  queueConnectionFactory = null;
  +                     QueueConnection         queueConnection = null;
  +                     QueueSession            queueSession = null;
  +                     Queue                   queue = null;
  +                     QueueReceiver           queueReceiver = null;
  +                     TextMessage             message = null;
  +
  +                     try {
  +                             queueConnectionFactory = 
  +                                     SampleUtilities.getQueueConnectionFactory();
  +                             queueConnection = 
  +                                     queueConnectionFactory.createQueueConnection();
  +                             queueSession = 
queueConnection.createQueueSession(false, 
  +                                     Session.CLIENT_ACKNOWLEDGE);
  +                             queue = SampleUtilities.getQueue(queueName, 
queueSession);
  +                     } catch (Exception e) {
  +                             System.out.println("Connection problem: " + 
e.toString());
  +                             if (queueConnection != null) {
  +                                     try {
  +                                             queueConnection.close();
  +                                     } catch (JMSException ee) {}
  +                             }
  +                             System.exit(1);
  +                     }
        
  -            /*
  -             * Create client-acknowledge receiver.
  -             * Receive message and process it.
  -             * Acknowledge message.
  -             */
  -             try {
  -                System.out.println("  RECEIVER: Created client-acknowledge 
session");
  -                queueReceiver = queueSession.createReceiver(queue);
  -                queueConnection.start();
  -                message = (TextMessage) queueReceiver.receive();
  -                System.out.println("  RECEIVER: Processing message: " 
  -                    + message.getText());
  -                System.out.println("  RECEIVER: Now I'll acknowledge the message");
  -                message.acknowledge();
  -            } catch (JMSException e) {
  -                System.out.println("Exception occurred: " + e.toString());
  -                exitResult = 1;
  -            } finally {
  -                if (queueConnection != null) {
  -                    try {
  -                        queueConnection.close();
  -                    } catch (JMSException e) {
  -                        exitResult = 1;
  -                    }
  -                }
  -            }
  -        }        
  -    }
  +                     /*
  +                      * Create client-acknowledge receiver.
  +                      * Receive message and process it.
  +                      * Acknowledge message.
  +                      */
  +                      try {
  +                             System.out.println("  RECEIVER: Created 
client-acknowledge session");
  +                             queueReceiver = queueSession.createReceiver(queue);
  +                             queueConnection.start();
  +                             message = (TextMessage) queueReceiver.receive();
  +                             System.out.println("  RECEIVER: Processing message: " 
  +                                     + message.getText());
  +                             System.out.println("  RECEIVER: Now I'll acknowledge 
the message");
  +                             message.acknowledge();
  +                     } catch (JMSException e) {
  +                             System.out.println("Exception occurred: " + 
e.toString());
  +                             exitResult = 1;
  +                     } finally {
  +                             if (queueConnection != null) {
  +                                     try {
  +                                             queueConnection.close();
  +                                     } catch (JMSException e) {
  +                                             exitResult = 1;
  +                                     }
  +                             }
  +                     }
  +             }           
  +     }
       
  -    /**
  -     * The AsynchSubscriber class creates a session in AUTO_ACKNOWLEDGE mode
  -     * and fetches several messages from a topic asynchronously, using a 
  -     * message listener, TextListener.
  -     * <p>
  -     * Each message is acknowledged after the onMessage method completes.
  -     *
  -     * @author Kim Haase
  -     * @version 1.6, 08/18/00
  -     */
  -    public class AsynchSubscriber extends Thread {
  -
  -        /**
  -         * The TextListener class implements the MessageListener interface by 
  -         * defining an onMessage method for the AsynchSubscriber class.
  -         *
  -         * @author Kim Haase
  -         * @version 1.6, 08/18/00
  -         */
  -        private class TextListener implements MessageListener {
  -            final SampleUtilities.DoneLatch  monitor =
  -                new SampleUtilities.DoneLatch();
  -
  -            /**
  -             * Casts the message to a TextMessage and displays its text.
  -             * A non-text message is interpreted as the end of the message 
  -             * stream, and the message listener sets its monitor state to all 
  -             * done processing messages.
  -             *
  -             * @param message        the incoming message
  -             */
  -            public void onMessage(Message message) {
  -                if (message instanceof TextMessage) {
  -                    TextMessage  msg = (TextMessage) message;
  -                    
  -                    try {
  -                        System.out.println("SUBSCRIBER: Processing message: " 
  -                                           + msg.getText());
  -                    } catch (JMSException e) {
  -                        System.out.println("Exception in onMessage(): " 
  -                                           + e.toString());
  -                    } 
  -                } else {
  -                    monitor.allDone();
  -                }
  -            }
  -        }
  -
  -        /**
  -         * Runs the thread.
  -         */
  -        public void run() {
  -            TopicConnectionFactory  topicConnectionFactory = null;
  -            TopicConnection         topicConnection = null;
  -            TopicSession            topicSession = null;
  -            Topic                   topic = null;
  -            TopicSubscriber         topicSubscriber = null;
  -            TextListener            topicListener = null;
  -
  -            try {
  -                topicConnectionFactory = 
  -                    SampleUtilities.getTopicConnectionFactory();
  -                topicConnection = 
  -                    topicConnectionFactory.createTopicConnection();
  -                topicConnection.setClientID("AckEquivExample");
  -                topicSession = topicConnection.createTopicSession(false, 
  -                    Session.AUTO_ACKNOWLEDGE);
  -                System.out.println("SUBSCRIBER: Created auto-acknowledge session");
  -                topic = SampleUtilities.getTopic(topicName, topicSession);
  -            } catch (Exception e) {
  -                System.out.println("Connection problem: " + e.toString());
  -                if (topicConnection != null) {
  -                    try {
  -                        topicConnection.close();
  -                    } catch (JMSException ee) {}
  -                }
  -             System.exit(1);
  -            }
  -            
  -            /*
  -             * Create auto-acknowledge subscriber.
  -             * Register message listener (TextListener).
  -             * Start message delivery.
  -             * Send synchronize message to publisher, then wait till all
  -             *   messages have arrived.
  -             * Listener displays the messages obtained.
  -             */
  -            try {
  -                topicSubscriber = topicSession.createDurableSubscriber(topic,
  -                     "AckEquivExampleSubscription");
  -                topicListener = new TextListener();
  -                topicSubscriber.setMessageListener(topicListener);
  -                topicConnection.start();
  -
  -                // Let publisher know that subscriber is ready.
  -                try {
  -                    SampleUtilities.sendSynchronizeMessage("SUBSCRIBER: ", 
  -                                                            CONTROL_QUEUE);
  -                } catch (Exception e) {
  -                    System.out.println("Queue probably missing: " + e.toString());
  -                    if (topicConnection != null) {
  -                        try {
  -                            topicConnection.close();
  -                        } catch (JMSException ee) {}
  -                    }
  -                 System.exit(1);
  -             }
  -
  -                /*
  -                 * Asynchronously process messages.
  -                 * Block until publisher issues a control message indicating
  -                 * end of publish stream.
  -                 */
  -                topicListener.monitor.waitTillDone();
  -                topicSubscriber.close();
  -                topicSession.unsubscribe("AckEquivExampleSubscription");
  -            } catch (JMSException e) {
  -                System.out.println("Exception occurred: " + e.toString());
  -                exitResult = 1;
  -            } finally {
  -                if (topicConnection != null) {
  -                    try {
  -                        topicConnection.close();
  -                    } catch (JMSException e) {
  -                        exitResult = 1;
  -                    }
  -                }
  -            }
  -        }        
  -    }
  -
  -    /**
  -     * The MultiplePublisher class creates a session in AUTO_ACKNOWLEDGE mode
  -     * and publishes three messages to a topic. 
  -     *
  -     * @author Kim Haase
  -     * @version 1.6, 08/18/00
  -     */
  -    public class MultiplePublisher extends Thread {
  -        
  -        /**
  -         * Runs the thread.
  -         */
  -        public void run() {
  -            TopicConnectionFactory  topicConnectionFactory = null;
  -            TopicConnection         topicConnection = null;
  -            TopicSession            topicSession = null;
  -            Topic                   topic = null;
  -            TopicPublisher          topicPublisher = null;
  -            TextMessage             message = null;
  -            final int               NUMMSGS = 3;
  -            final String            MSG_TEXT = 
  -                              new String("Here is an auto-acknowledge message");
  -
  -            try {
  -                topicConnectionFactory = 
  -                    SampleUtilities.getTopicConnectionFactory();
  -                topicConnection = 
  -                    topicConnectionFactory.createTopicConnection();
  -                topicSession = topicConnection.createTopicSession(false, 
  -                    Session.AUTO_ACKNOWLEDGE);
  -                System.out.println("PUBLISHER: Created auto-acknowledge session");
  -                topic = SampleUtilities.getTopic(topicName, topicSession);
  -            } catch (Exception e) {
  -                System.out.println("Connection problem: " + e.toString());
  -                if (topicConnection != null) {
  -                    try {
  -                        topicConnection.close();
  -                    } catch (JMSException ee) {}
  -                }
  -             System.exit(1);
  -            }
  -
  -            /*
  -             * After synchronizing with subscriber, create publisher.
  -             * Send 3 messages, varying text slightly.
  -             * Send end-of-messages message.
  -             */
  -            try {
  -                /*
  -                 * Synchronize with subscriber.  Wait for message indicating 
  -                 * that subscriber is ready to receive messages.
  -                 */
  -                try {
  -                    SampleUtilities.receiveSynchronizeMessages("PUBLISHER: ", 
  -                                                              CONTROL_QUEUE, 1);
  -                } catch (Exception e) {
  -                    System.out.println("Queue probably missing: " + e.toString());
  -                    if (topicConnection != null) {
  -                        try {
  -                            topicConnection.close();
  -                        } catch (JMSException ee) {}
  -                    }
  -                 System.exit(1);
  -             }
  -
  -                topicPublisher = topicSession.createPublisher(topic);
  -                message = topicSession.createTextMessage();
  -                for (int i = 0; i < NUMMSGS; i++) {
  -                    message.setText(MSG_TEXT + " " + (i + 1));
  -                    System.out.println("PUBLISHER: Publishing message: " 
  -                        + message.getText());
  -                    topicPublisher.publish(message);
  -                }
  -                
  -                // Send a non-text control message indicating end of messages. 
  -                topicPublisher.publish(topicSession.createMessage());
  -            } catch (JMSException e) {
  -                System.out.println("Exception occurred: " + e.toString());
  -                exitResult = 1;
  -            } finally {
  -                if (topicConnection != null) {
  -                    try {
  -                        topicConnection.close();
  -                    } catch (JMSException e) {
  -                        exitResult = 1;
  -                    }
  -                }
  -            }
  -        }
  -    }
  +     /**
  +      * The AsynchSubscriber class creates a session in AUTO_ACKNOWLEDGE mode
  +      * and fetches several messages from a topic asynchronously, using a 
  +      * message listener, TextListener.
  +      * <p>
  +      * Each message is acknowledged after the onMessage method completes.
  +      *
  +      * @author Kim Haase
  +      * @version 1.6, 08/18/00
  +      */
  +     public class AsynchSubscriber extends Thread {
  +
  +             /**
  +              * The TextListener class implements the MessageListener interface by 
  +              * defining an onMessage method for the AsynchSubscriber class.
  +              *
  +              * @author Kim Haase
  +              * @version 1.6, 08/18/00
  +              */
  +             private class TextListener implements MessageListener {
  +                     final SampleUtilities.DoneLatch  monitor =
  +                             new SampleUtilities.DoneLatch();
  +
  +                     /**
  +                      * Casts the message to a TextMessage and displays its text.
  +                      * A non-text message is interpreted as the end of the message 
  +                      * stream, and the message listener sets its monitor state to 
all 
  +                      * done processing messages.
  +                      *
  +                      * @param message       the incoming message
  +                      */
  +                     public void onMessage(Message message) {
  +                             if (message instanceof TextMessage) {
  +                                     TextMessage  msg = (TextMessage) message;
  +                                     
  +                                     try {
  +                                             System.out.println("SUBSCRIBER: 
Processing message: " 
  +                                                                                + 
msg.getText());
  +                                     } catch (JMSException e) {
  +                                             System.out.println("Exception in 
onMessage(): " 
  +                                                                                + 
e.toString());
  +                                     } 
  +                             } else {
  +                                     monitor.allDone();
  +                             }
  +                     }
  +             }
  +
  +             /**
  +              * Runs the thread.
  +              */
  +             public void run() {
  +                     TopicConnectionFactory  topicConnectionFactory = null;
  +                     TopicConnection         topicConnection = null;
  +                     TopicSession            topicSession = null;
  +                     Topic                   topic = null;
  +                     TopicSubscriber         topicSubscriber = null;
  +                     TextListener            topicListener = null;
  +
  +                     try {
  +                             topicConnectionFactory = 
  +                                     SampleUtilities.getTopicConnectionFactory();
  +                             topicConnection = 
  +                             //      topicConnectionFactory.createTopicConnection();
  +                                     
topicConnectionFactory.createTopicConnection("john", "needle");
  +                             //topicConnection.setClientID("AckEquivExample");
  +                             topicSession = 
topicConnection.createTopicSession(false, 
  +                                     Session.AUTO_ACKNOWLEDGE);
  +                             System.out.println("SUBSCRIBER: Created 
auto-acknowledge session");
  +                             topic = SampleUtilities.getTopic(topicName, 
topicSession);
  +                     } catch (Exception e) {
  +                             System.out.println("Connection problem: " + 
e.toString());
  +                             if (topicConnection != null) {
  +                                     try {
  +                                             topicConnection.close();
  +                                     } catch (JMSException ee) {}
  +                             }
  +                     System.exit(1);
  +                     }
  +                     
  +                     /*
  +                      * Create auto-acknowledge subscriber.
  +                      * Register message listener (TextListener).
  +                      * Start message delivery.
  +                      * Send synchronize message to publisher, then wait till all
  +                      *   messages have arrived.
  +                      * Listener displays the messages obtained.
  +                      */
  +                     try {
  +                             topicSubscriber = 
topicSession.createDurableSubscriber(topic,
  +                                      "AckEquivExampleSubscription");
  +                             topicListener = new TextListener();
  +                             topicSubscriber.setMessageListener(topicListener);
  +                             topicConnection.start();
  +
  +                             // Let publisher know that subscriber is ready.
  +                             try {
  +                                     
SampleUtilities.sendSynchronizeMessage("SUBSCRIBER: ", 
  +                                                                                    
                                 CONTROL_QUEUE);
  +                             } catch (Exception e) {
  +                                     System.out.println("Queue probably missing: " 
+ e.toString());
  +                                     if (topicConnection != null) {
  +                                             try {
  +                                                     topicConnection.close();
  +                                             } catch (JMSException ee) {}
  +                                     }
  +                         System.exit(1);
  +                     }
  +
  +                             /*
  +                              * Asynchronously process messages.
  +                              * Block until publisher issues a control message 
indicating
  +                              * end of publish stream.
  +                              */
  +                             topicListener.monitor.waitTillDone();
  +                             topicSubscriber.close();
  +                             
topicSession.unsubscribe("AckEquivExampleSubscription");
  +                     } catch (JMSException e) {
  +                             System.out.println("Exception occurred: " + 
e.toString());
  +                             exitResult = 1;
  +                     } finally {
  +                             if (topicConnection != null) {
  +                                     try {
  +                                             topicConnection.close();
  +                                     } catch (JMSException e) {
  +                                             exitResult = 1;
  +                                     }
  +                             }
  +                     }
  +             }           
  +     }
  +
  +     /**
  +      * The MultiplePublisher class creates a session in AUTO_ACKNOWLEDGE mode
  +      * and publishes three messages to a topic. 
  +      *
  +      * @author Kim Haase
  +      * @version 1.6, 08/18/00
  +      */
  +     public class MultiplePublisher extends Thread {
  +             
  +             /**
  +              * Runs the thread.
  +              */
  +             public void run() {
  +                     TopicConnectionFactory  topicConnectionFactory = null;
  +                     TopicConnection         topicConnection = null;
  +                     TopicSession            topicSession = null;
  +                     Topic                   topic = null;
  +                     TopicPublisher          topicPublisher = null;
  +                     TextMessage             message = null;
  +                     final int               NUMMSGS = 3;
  +                     final String            MSG_TEXT = 
  +                                                       new String("Here is an 
auto-acknowledge message");
  +
  +                     try {
  +                             topicConnectionFactory = 
  +                                     SampleUtilities.getTopicConnectionFactory();
  +                             topicConnection = 
  +                                     topicConnectionFactory.createTopicConnection();
  +                             topicSession = 
topicConnection.createTopicSession(false, 
  +                                     Session.AUTO_ACKNOWLEDGE);
  +                             System.out.println("PUBLISHER: Created 
auto-acknowledge session");
  +                             topic = SampleUtilities.getTopic(topicName, 
topicSession);
  +                     } catch (Exception e) {
  +                             System.out.println("Connection problem: " + 
e.toString());
  +                             if (topicConnection != null) {
  +                                     try {
  +                                             topicConnection.close();
  +                                     } catch (JMSException ee) {}
  +                             }
  +                     System.exit(1);
  +                     }
  +
  +                     /*
  +                      * After synchronizing with subscriber, create publisher.
  +                      * Send 3 messages, varying text slightly.
  +                      * Send end-of-messages message.
  +                      */
  +                     try {
  +                             /*
  +                              * Synchronize with subscriber.  Wait for message 
indicating 
  +                              * that subscriber is ready to receive messages.
  +                              */
  +                             try {
  +                                     
SampleUtilities.receiveSynchronizeMessages("PUBLISHER: ", 
  +                                                                                    
                                   CONTROL_QUEUE, 1);
  +                             } catch (Exception e) {
  +                                     System.out.println("Queue probably missing: " 
+ e.toString());
  +                                     if (topicConnection != null) {
  +                                             try {
  +                                                     topicConnection.close();
  +                                             } catch (JMSException ee) {}
  +                                     }
  +                         System.exit(1);
  +                     }
  +
  +                             topicPublisher = topicSession.createPublisher(topic);
  +                             message = topicSession.createTextMessage();
  +                             for (int i = 0; i < NUMMSGS; i++) {
  +                                     message.setText(MSG_TEXT + " " + (i + 1));
  +                                     System.out.println("PUBLISHER: Publishing 
message: " 
  +                                             + message.getText());
  +                                     topicPublisher.publish(message);
  +                             }
  +                             
  +                             // Send a non-text control message indicating end of 
messages. 
  +                             topicPublisher.publish(topicSession.createMessage());
  +                     } catch (JMSException e) {
  +                             System.out.println("Exception occurred: " + 
e.toString());
  +                             exitResult = 1;
  +                     } finally {
  +                             if (topicConnection != null) {
  +                                     try {
  +                                             topicConnection.close();
  +                                     } catch (JMSException e) {
  +                                             exitResult = 1;
  +                                     }
  +                             }
  +                     }
  +             }
  +     }
       
  -    /**
  -     * Instantiates the sender, receiver, subscriber, and publisher classes and 
  -     * starts their threads.
  -     * Calls the join method to wait for the threads to die.
  -     */
  -    public void run_threads() {
  -        SynchSender        synchSender = new SynchSender();
  -        SynchReceiver      synchReceiver = new SynchReceiver();
  -        AsynchSubscriber   asynchSubscriber = new AsynchSubscriber();
  -        MultiplePublisher  multiplePublisher = new MultiplePublisher();
  -        
  -        synchSender.start();
  -        synchReceiver.start();
  -        try {
  -            synchSender.join();
  -            synchReceiver.join();
  -        } catch (InterruptedException e) {}
  -
  -        asynchSubscriber.start();
  -        multiplePublisher.start();
  -        try {
  -            asynchSubscriber.join();
  -            multiplePublisher.join();
  -        } catch (InterruptedException e) {}
  -    }
  -
  -    /**
  -     * Reads the queue and topic names from the command line, then calls the
  -     * run_threads method to execute the program threads.
  -     *
  -     * @param args   the topic used by the example
  -     */
  -    public static void main(String[] args) {
  -        AckEquivExample  aee = new AckEquivExample();
  -        
  -        if (args.length != 2) {
  -         System.out.println("Usage: java AckEquivExample <queue_name> 
<topic_name>");
  -         System.exit(1);
  -     }
  -        aee.queueName = new String(args[0]);
  -        aee.topicName = new String(args[1]);
  -        System.out.println("Queue name is " + aee.queueName);
  -        System.out.println("Topic name is " + aee.topicName);
  -
  -     aee.run_threads();
  -     SampleUtilities.exit(aee.exitResult);
  -    }
  +     /**
  +      * Instantiates the sender, receiver, subscriber, and publisher classes and 
  +      * starts their threads.
  +      * Calls the join method to wait for the threads to die.
  +      */
  +     public void run_threads() {
  +             SynchSender        synchSender = new SynchSender();
  +             SynchReceiver      synchReceiver = new SynchReceiver();
  +             AsynchSubscriber   asynchSubscriber = new AsynchSubscriber();
  +             MultiplePublisher  multiplePublisher = new MultiplePublisher();
  +             
  +             synchSender.start();
  +             synchReceiver.start();
  +             try {
  +                     synchSender.join();
  +                     synchReceiver.join();
  +             } catch (InterruptedException e) {}
  +
  +             asynchSubscriber.start();
  +             multiplePublisher.start();
  +             try {
  +                     asynchSubscriber.join();
  +                     multiplePublisher.join();
  +             } catch (InterruptedException e) {}
  +     }
  +
  +     /**
  +      * Reads the queue and topic names from the command line, then calls the
  +      * run_threads method to execute the program threads.
  +      *
  +      * @param args  the topic used by the example
  +      */
  +     public static void main(String[] args) {
  +             AckEquivExample  aee = new AckEquivExample();
  +             
  +             if (args.length != 2) {
  +                 System.out.println("Usage: java AckEquivExample <queue_name> 
<topic_name>");
  +                 System.exit(1);
  +             }
  +             aee.queueName = new String(args[0]);
  +             aee.topicName = new String(args[1]);
  +             System.out.println("Queue name is " + aee.queueName);
  +             System.out.println("Topic name is " + aee.topicName);
  +
  +             aee.run_threads();
  +             SampleUtilities.exit(aee.exitResult);
  +     }
   }
  -
  
  
  

Reply via email to