KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > proxy > ProxyTestSupport


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.proxy;
19
20 import java.net.URI JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import org.apache.activemq.broker.BrokerService;
25 import org.apache.activemq.broker.BrokerTestSupport;
26 import org.apache.activemq.broker.StubConnection;
27 import org.apache.activemq.broker.TransportConnector;
28 import org.apache.activemq.memory.UsageManager;
29 import org.apache.activemq.proxy.ProxyConnector;
30 import org.apache.activemq.store.PersistenceAdapter;
31 import org.apache.activemq.transport.Transport;
32 import org.apache.activemq.transport.TransportFactory;
33
34 public class ProxyTestSupport extends BrokerTestSupport {
35     
36     protected ArrayList JavaDoc connections = new ArrayList JavaDoc();
37     
38     protected TransportConnector connector;
39
40     protected PersistenceAdapter remotePersistenceAdapter;
41     protected BrokerService remoteBroker;
42     protected UsageManager remoteMemoryManager;
43     protected TransportConnector remoteConnector;
44     private ProxyConnector proxyConnector;
45     private ProxyConnector remoteProxyConnector;
46
47     protected BrokerService createBroker() throws Exception JavaDoc {
48         BrokerService service = new BrokerService();
49         service.setBrokerName("broker1");
50         service.setPersistent(false);
51
52         connector = service.addConnector(getLocalURI());
53         proxyConnector=new ProxyConnector();
54         proxyConnector.setName("proxy");
55         proxyConnector.setBind(new URI JavaDoc(getLocalProxyURI()));
56         proxyConnector.setRemote(new URI JavaDoc("fanout:static://"+getRemoteURI()));
57         service.addProxyConnector(proxyConnector);
58         
59         return service;
60     }
61
62     protected BrokerService createRemoteBroker() throws Exception JavaDoc {
63         BrokerService service = new BrokerService();
64         service.setBrokerName("broker2");
65         service.setPersistent(false);
66
67         remoteConnector = service.addConnector(getRemoteURI());
68         remoteProxyConnector = new ProxyConnector();
69         remoteProxyConnector.setName("remoteProxy");
70         remoteProxyConnector.setBind(new URI JavaDoc(getRemoteProxyURI()));
71         remoteProxyConnector.setRemote(new URI JavaDoc("fanout:static://"+getLocalURI()));
72         service.addProxyConnector(remoteProxyConnector);
73         
74         return service;
75     }
76     
77
78     protected void setUp() throws Exception JavaDoc {
79         super.setUp();
80         remoteBroker = createRemoteBroker();
81         remoteBroker.start();
82     }
83     
84     protected void tearDown() throws Exception JavaDoc {
85         for (Iterator JavaDoc iter = connections.iterator(); iter.hasNext();) {
86             StubConnection connection = (StubConnection) iter.next();
87             connection.stop();
88             iter.remove();
89         }
90         remoteBroker.stop();
91         super.tearDown();
92     }
93
94     protected String JavaDoc getRemoteURI() {
95         return "tcp://localhost:7001";
96     }
97
98     protected String JavaDoc getLocalURI() {
99         return "tcp://localhost:6001";
100     }
101
102     protected String JavaDoc getRemoteProxyURI() {
103         return "tcp://localhost:7002";
104     }
105
106     protected String JavaDoc getLocalProxyURI() {
107         return "tcp://localhost:6002";
108     }
109
110     protected StubConnection createConnection() throws Exception JavaDoc {
111         Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
112         StubConnection connection = new StubConnection(transport);
113         connections.add(connection);
114         return connection;
115     }
116
117     protected StubConnection createRemoteConnection() throws Exception JavaDoc {
118         Transport transport = TransportFactory.connect(remoteConnector.getServer().getConnectURI());
119         StubConnection connection = new StubConnection(transport);
120         connections.add(connection);
121         return connection;
122     }
123
124     protected StubConnection createProxyConnection() throws Exception JavaDoc {
125         Transport transport = TransportFactory.connect(proxyConnector.getServer().getConnectURI());
126         StubConnection connection = new StubConnection(transport);
127         connections.add(connection);
128         return connection;
129     }
130
131     protected StubConnection createRemoteProxyConnection() throws Exception JavaDoc {
132         Transport transport = TransportFactory.connect(remoteProxyConnector.getServer().getConnectURI());
133         StubConnection connection = new StubConnection(transport);
134         connections.add(connection);
135         return connection;
136     }
137     
138 }
139
Popular Tags