Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 34934 invoked from network); 15 Jun 2009 19:06:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Jun 2009 19:06:38 -0000 Received: (qmail 66903 invoked by uid 500); 15 Jun 2009 19:06:47 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 66860 invoked by uid 500); 15 Jun 2009 19:06:47 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 66752 invoked by uid 99); 15 Jun 2009 19:06:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jun 2009 19:06:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jun 2009 19:06:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 42C78238886C; Mon, 15 Jun 2009 19:06:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r784920 - in /activemq/sandbox/activemq-flow: activemq-client/src/test/java/org/apache/activemq/legacy/ActiveMQConnectionFactoryTest.java activemq-transport/src/main/java/org/apache/activemq/transport/pipe/PipeTransportFactory.java Date: Mon, 15 Jun 2009 19:06:22 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090615190622.42C78238886C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chirino Date: Mon Jun 15 19:06:21 2009 New Revision: 784920 URL: http://svn.apache.org/viewvc?rev=784920&view=rev Log: adapting the ActiveMQConnectionFactoryTest to use the new apis. Modified: activemq/sandbox/activemq-flow/activemq-client/src/test/java/org/apache/activemq/legacy/ActiveMQConnectionFactoryTest.java activemq/sandbox/activemq-flow/activemq-transport/src/main/java/org/apache/activemq/transport/pipe/PipeTransportFactory.java Modified: activemq/sandbox/activemq-flow/activemq-client/src/test/java/org/apache/activemq/legacy/ActiveMQConnectionFactoryTest.java URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-client/src/test/java/org/apache/activemq/legacy/ActiveMQConnectionFactoryTest.java?rev=784920&r1=784919&r2=784920&view=diff ============================================================================== --- activemq/sandbox/activemq-flow/activemq-client/src/test/java/org/apache/activemq/legacy/ActiveMQConnectionFactoryTest.java (original) +++ activemq/sandbox/activemq-flow/activemq-client/src/test/java/org/apache/activemq/legacy/ActiveMQConnectionFactoryTest.java Mon Jun 15 19:06:21 2009 @@ -31,9 +31,12 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQMessageConsumer; import org.apache.activemq.apollo.CombinationTestSupport; -import org.apache.activemq.legacy.broker.BrokerRegistry; -import org.apache.activemq.legacy.broker.BrokerService; -import org.apache.activemq.legacy.broker.TransportConnector; +import org.apache.activemq.apollo.broker.Broker; +import org.apache.activemq.apollo.transport.vm.VMTransportFactory; +import org.apache.activemq.broker.store.memory.MemoryStore; +import org.apache.activemq.transport.TransportFactory; +import org.apache.activemq.transport.TransportServer; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,7 +44,7 @@ private static final Log LOG = LogFactory.getLog(ActiveMQConnectionFactoryTest.class); private ActiveMQConnection connection; - private BrokerService broker; + private Broker broker; public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException, JMSException { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory( @@ -109,17 +112,17 @@ ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); // Make sure the broker is not created until the connection is // instantiated. - assertNull(BrokerRegistry.getInstance().lookup("localhost")); + assertNull(VMTransportFactory.lookup("localhost")); connection = (ActiveMQConnection)cf.createConnection(); // This should create the connection. assertNotNull(connection); // Verify the broker was created. - assertNotNull(BrokerRegistry.getInstance().lookup("localhost")); + assertNotNull(VMTransportFactory.lookup("localhost")); connection.close(); // Verify the broker was destroyed. - assertNull(BrokerRegistry.getInstance().lookup("localhost")); + assertNull(VMTransportFactory.lookup("localhost")); } public void testGetBrokerName() throws URISyntaxException, JMSException { @@ -189,15 +192,16 @@ protected void assertCreateConnection(String uri) throws Exception { // Start up a broker with a tcp connector. - broker = new BrokerService(); - broker.setPersistent(false); - TransportConnector connector = broker.addConnector(uri); + broker = new Broker(); + broker.getDefaultVirtualHost().setStore(new MemoryStore()); + TransportServer server = TransportFactory.bind(new URI(uri)); + broker.addTransportServer(server); broker.start(); URI temp = new URI(uri); // URI connectURI = connector.getServer().getConnectURI(); // TODO this sometimes fails when using the actual local host name - URI currentURI = connector.getServer().getConnectURI(); + URI currentURI = server.getConnectURI(); // sometimes the actual host name doesn't work in this test case // e.g. on OS X so lets use the original details but just use the actual Modified: activemq/sandbox/activemq-flow/activemq-transport/src/main/java/org/apache/activemq/transport/pipe/PipeTransportFactory.java URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-transport/src/main/java/org/apache/activemq/transport/pipe/PipeTransportFactory.java?rev=784920&r1=784919&r2=784920&view=diff ============================================================================== --- activemq/sandbox/activemq-flow/activemq-transport/src/main/java/org/apache/activemq/transport/pipe/PipeTransportFactory.java (original) +++ activemq/sandbox/activemq-flow/activemq-transport/src/main/java/org/apache/activemq/transport/pipe/PipeTransportFactory.java Mon Jun 15 19:06:21 2009 @@ -33,7 +33,7 @@ public class PipeTransportFactory extends TransportFactory { static private final Object EOF_TOKEN = new Object(); - protected final HashMap servers = new HashMap(); + static protected final HashMap servers = new HashMap(); protected static class PipeTransport implements DispatchableTransport, Dispatchable, Runnable, ReadReadyListener { @@ -290,23 +290,24 @@ } @Override - public synchronized TransportServer doBind(URI uri) throws IOException { + public TransportServer doBind(URI uri) throws IOException { try { Map options = new HashMap(URISupport.parseParamters(uri)); - String node = uri.getHost(); - if (servers.containsKey(node)) { - throw new IOException("Server already bound: " + node); - } - PipeTransportServer server = createTransportServer(); - server.setConnectURI(uri); - server.setName(node); - if (options.containsKey("wireFormat")) { - server.setWireFormatFactory(createWireFormatFactory(options)); - } - - servers.put(node, server); - return server; + synchronized(servers) { + if (servers.containsKey(node)) { + throw new IOException("Server already bound: " + node); + } + PipeTransportServer server = createTransportServer(); + server.setConnectURI(uri); + server.setName(node); + if (options.containsKey("wireFormat")) { + server.setWireFormatFactory(createWireFormatFactory(options)); + } + + servers.put(node, server); + return server; + } } catch (URISyntaxException e) { throw IOExceptionSupport.create(e); } @@ -316,18 +317,34 @@ return new PipeTransportServer(); } - protected synchronized void unbind(PipeTransportServer server) { - servers.remove(server.getName()); - } - @Override - public synchronized Transport doCompositeConnect(URI location) throws Exception { + public Transport doCompositeConnect(URI location) throws Exception { String name = location.getHost(); - PipeTransportServer server = servers.get(name); - if (server == null) { - throw new IOException("Server is not bound: " + name); - } - return server.connect(); + synchronized(servers) { + PipeTransportServer server = lookup(name); + if (server == null) { + throw new IOException("Server is not bound: " + name); + } + return server.connect(); + } + } + + static public PipeTransportServer lookup(String name) { + synchronized(servers) { + return servers.get(name); + } + } + + static public Map getServers() { + synchronized(servers) { + return new HashMap(servers); + } + } + + static public void unbind(PipeTransportServer server) { + synchronized(servers) { + servers.remove(server.getName()); + } } }