KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > JmsTopicSendReceiveTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq;
19
20 import javax.jms.Connection JavaDoc;
21 import javax.jms.DeliveryMode JavaDoc;
22 import javax.jms.JMSException JavaDoc;
23 import javax.jms.MessageConsumer JavaDoc;
24 import javax.jms.Session JavaDoc;
25 import javax.jms.Topic JavaDoc;
26
27 /**
28  * @version $Revision: 1.3 $
29  */

30 public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport {
31     private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
32             .getLog(JmsTopicSendReceiveTest.class);
33     
34     protected Connection JavaDoc connection;
35
36     protected void setUp() throws Exception JavaDoc {
37         super.setUp();
38
39         connectionFactory = createConnectionFactory();
40         connection = createConnection();
41         if (durable) {
42             connection.setClientID(getClass().getName());
43         }
44
45         log.info("Created connection: " + connection);
46
47         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
48
49         log.info("Created session: " + session);
50         producer = session.createProducer(null);
51         producer.setDeliveryMode(deliveryMode);
52
53         log.info("Created producer: " + producer + " delivery mode = " +
54                 (deliveryMode == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON_PERSISTENT"));
55
56         if (topic) {
57             consumerDestination = session.createTopic(getConsumerSubject());
58             producerDestination = session.createTopic(getProducerSubject());
59         }
60         else {
61             consumerDestination = session.createQueue(getConsumerSubject());
62             producerDestination = session.createQueue(getProducerSubject());
63         }
64
65         log.info("Created consumer destination: " + consumerDestination + " of type: " + consumerDestination.getClass());
66         log.info("Created producer destination: " + producerDestination + " of type: " + producerDestination.getClass());
67         consumer = createConsumer();
68         consumer.setMessageListener(this);
69         connection.start();
70
71         //log.info("Created connection: " + connection);
72
}
73
74     protected MessageConsumer JavaDoc createConsumer() throws JMSException JavaDoc {
75         if (durable) {
76             log.info("Creating durable consumer");
77             return session.createDurableSubscriber((Topic JavaDoc) consumerDestination, getName());
78         }
79         return session.createConsumer(consumerDestination);
80     }
81
82     protected void tearDown() throws Exception JavaDoc {
83         log.info("Dumping stats...");
84         //connectionFactory.getStats().reset();
85

86         log.info("Closing down connection");
87
88         /** TODO we should be able to shut down properly */
89         session.close();
90         connection.close();
91     }
92
93 }
94
Popular Tags