KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > usecases > TwoBrokerTopicSendReceiveUsingTcpTest


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.usecases;
19
20 import javax.jms.JMSException JavaDoc;
21
22 import org.apache.activemq.ActiveMQConnectionFactory;
23 import org.apache.activemq.xbean.BrokerFactoryBean;
24 import org.apache.activemq.broker.BrokerService;
25 import org.apache.activemq.broker.TransportConnector;
26 import org.springframework.core.io.ClassPathResource;
27
28 import java.io.IOException JavaDoc;
29 import java.net.URISyntaxException JavaDoc;
30
31 /**
32  * @version $Revision: 1.1.1.1 $
33  */

34 public class TwoBrokerTopicSendReceiveUsingTcpTest extends TwoBrokerTopicSendReceiveTest {
35     private BrokerService receiverBroker;
36     private BrokerService senderBroker;
37
38     protected void setUp() throws Exception JavaDoc {
39         BrokerFactoryBean brokerFactory;
40
41         brokerFactory = new BrokerFactoryBean(new ClassPathResource("org/apache/activemq/usecases/receiver.xml"));
42         brokerFactory.afterPropertiesSet();
43         receiverBroker = brokerFactory.getBroker();
44
45         brokerFactory = new BrokerFactoryBean(new ClassPathResource("org/apache/activemq/usecases/sender.xml"));
46         brokerFactory.afterPropertiesSet();
47         senderBroker = brokerFactory.getBroker();
48
49         super.setUp();
50     }
51
52     protected void tearDown() throws Exception JavaDoc {
53         super.tearDown();
54
55         if (receiverBroker != null) {
56             receiverBroker.stop();
57         }
58         if (senderBroker != null) {
59             senderBroker.stop();
60         }
61     }
62
63     
64     protected ActiveMQConnectionFactory createReceiverConnectionFactory() throws JMSException JavaDoc {
65         try {
66             ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(((TransportConnector)receiverBroker.getTransportConnectors().get(0)).getConnectUri());
67             return fac;
68         } catch (Exception JavaDoc e) {
69             e.printStackTrace();
70             return null;
71         }
72     }
73
74     protected ActiveMQConnectionFactory createSenderConnectionFactory() throws JMSException JavaDoc {
75         try {
76             ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(((TransportConnector)senderBroker.getTransportConnectors().get(0)).getConnectUri());
77             return fac;
78         } catch (Exception JavaDoc e) {
79             e.printStackTrace();
80             return null;
81         }
82
83     }
84 }
85
Popular Tags