KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Queue JavaDoc;
21 import java.util.concurrent.ConcurrentLinkedQueue JavaDoc;
22
23 import org.apache.activemq.ActiveMQConnectionFactory;
24 import org.apache.activemq.broker.BrokerService;
25
26
27 /**
28  * @version $Revision: 475999 $
29  */

30 public class JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest extends JmsQueueSendReceiveTwoConnectionsTest {
31
32     private Queue JavaDoc errors = new ConcurrentLinkedQueue JavaDoc();
33     private int delayBeforeStartingBroker = 1000;
34     private BrokerService broker;
35
36     public void startBroker() {
37         // Initialize the broker
38
log.info("Lets wait: " + delayBeforeStartingBroker + " millis before creating the broker");
39         try {
40             Thread.sleep(delayBeforeStartingBroker);
41         }
42         catch (InterruptedException JavaDoc e) {
43             e.printStackTrace();
44         }
45         
46         log.info("Now starting the broker");
47         try {
48             broker = new BrokerService();
49             broker.setPersistent(false);
50             broker.addConnector("tcp://localhost:61616");
51             broker.start();
52         }
53         catch (Exception JavaDoc e) {
54             log.info("Caught: " + e);
55             errors.add(e);
56         }
57     }
58     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception JavaDoc {
59         return new ActiveMQConnectionFactory("failover:(tcp://localhost:61616)?maxReconnectAttempts=10&useExponentialBackOff=false&initialReconnectDelay=200");
60     }
61
62     protected void setUp() throws Exception JavaDoc {
63         // now lets asynchronously start a broker
64
Thread JavaDoc thread = new Thread JavaDoc() {
65             public void run() {
66                 startBroker();
67             }
68         };
69         thread.start();
70
71         super.setUp();
72     }
73
74     protected void tearDown() throws Exception JavaDoc {
75         super.tearDown();
76
77         if (broker != null) {
78             broker.stop();
79         }
80         if (!errors.isEmpty()) {
81             Exception JavaDoc e = (Exception JavaDoc) errors.remove();
82             throw e;
83         }
84     }
85     
86     
87
88 }
89
Popular Tags