1 18 package org.apache.activemq.proxy; 19 20 import java.net.URI ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 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 connections = new ArrayList (); 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 { 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 (getLocalProxyURI())); 56 proxyConnector.setRemote(new URI ("fanout:static://"+getRemoteURI())); 57 service.addProxyConnector(proxyConnector); 58 59 return service; 60 } 61 62 protected BrokerService createRemoteBroker() throws Exception { 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 (getRemoteProxyURI())); 71 remoteProxyConnector.setRemote(new URI ("fanout:static://"+getLocalURI())); 72 service.addProxyConnector(remoteProxyConnector); 73 74 return service; 75 } 76 77 78 protected void setUp() throws Exception { 79 super.setUp(); 80 remoteBroker = createRemoteBroker(); 81 remoteBroker.start(); 82 } 83 84 protected void tearDown() throws Exception { 85 for (Iterator 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 getRemoteURI() { 95 return "tcp://localhost:7001"; 96 } 97 98 protected String getLocalURI() { 99 return "tcp://localhost:6001"; 100 } 101 102 protected String getRemoteProxyURI() { 103 return "tcp://localhost:7002"; 104 } 105 106 protected String getLocalProxyURI() { 107 return "tcp://localhost:6002"; 108 } 109 110 protected StubConnection createConnection() throws Exception { 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 { 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 { 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 { 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 |