KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.activemq.broker.BrokerService;
21 import org.apache.activemq.broker.TransportConnector;
22 import org.apache.activemq.network.DemandForwardingBridge;
23 import org.apache.activemq.network.NetworkBridgeConfiguration;
24 import org.apache.activemq.transport.TransportFactory;
25
26 import java.util.List JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.net.URI JavaDoc;
29
30 /**
31  * @version $Revision: 1.1.1.1 $
32  */

33 public class ThreeBrokerTopicNetworkUsingTcpTest extends ThreeBrokerTopicNetworkTest {
34     protected List JavaDoc bridges;
35
36     protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception JavaDoc {
37         List JavaDoc remoteTransports = remoteBroker.getTransportConnectors();
38         List JavaDoc localTransports = localBroker.getTransportConnectors();
39
40         URI JavaDoc remoteURI, localURI;
41         if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
42             remoteURI = ((TransportConnector)remoteTransports.get(0)).getConnectUri();
43             localURI = ((TransportConnector)localTransports.get(0)).getConnectUri();
44
45             // Ensure that we are connecting using tcp
46
if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
47                 NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
48                 config.setBrokerName(localBroker.getBrokerName());
49                 DemandForwardingBridge bridge = new DemandForwardingBridge(config,TransportFactory.connect(localURI),
50                                                                            TransportFactory.connect(remoteURI));
51                 bridges.add(bridge);
52
53                 bridge.start();
54             } else {
55                 throw new Exception JavaDoc("Remote broker or local broker is not using tcp connectors");
56             }
57         } else {
58             throw new Exception JavaDoc("Remote broker or local broker has no registered connectors.");
59         }
60
61         MAX_SETUP_TIME = 2000;
62     }
63
64     public void setUp() throws Exception JavaDoc {
65         super.setUp();
66
67         bridges = new ArrayList JavaDoc();
68     }
69 }
70
Popular Tags