From a7ac415557938069b8de56a70f276041596c26d6 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Wed, 8 Feb 2006 20:23:08 +0000 Subject: [PATCH] Added better proxy connector cleanup code. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@376047 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/proxy/ProxyConnector.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java b/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java index a2232c0da9..517a377268 100644 --- a/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java @@ -19,16 +19,21 @@ package org.apache.activemq.proxy; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.util.Iterator; import org.apache.activemq.Service; import org.apache.activemq.transport.CompositeTransport; import org.apache.activemq.transport.Transport; import org.apache.activemq.transport.TransportAcceptListener; import org.apache.activemq.transport.TransportFactory; +import org.apache.activemq.transport.TransportFilter; import org.apache.activemq.transport.TransportServer; +import org.apache.activemq.util.ServiceStopper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList; + /** * @org.xbean.XBean * @@ -41,6 +46,8 @@ public class ProxyConnector implements Service { private URI bind; private URI remote; private URI localUri; + + CopyOnWriteArrayList connections = new CopyOnWriteArrayList(); public void start() throws Exception { @@ -49,7 +56,8 @@ public class ProxyConnector implements Service { try { Transport remoteTransport = createRemoteTransport(); ProxyConnection connection = new ProxyConnection(localTransport, remoteTransport); - connection.start(); + connections.add(connection); + connection.start(); } catch (Exception e) { onAcceptError(e); @@ -65,9 +73,15 @@ public class ProxyConnector implements Service { } public void stop() throws Exception { + ServiceStopper ss = new ServiceStopper(); if( this.server!=null ) { - this.server.stop(); + ss.stop(this.server); } + for (Iterator iter = connections.iterator(); iter.hasNext();) { + System.out.println("Connector stopped: Stopping proxy."); + ss.stop((Service) iter.next()); + } + ss.throwFirstException(); } // Properties @@ -121,6 +135,15 @@ public class ProxyConnector implements Service { if( ct !=null && localUri!=null ) { ct.add(new URI[]{localUri}); } + + // Add a transport filter so that can track the transport life cycle + transport = new TransportFilter(transport) { + public void stop() throws Exception { + System.out.println("Stopping proxy."); + super.stop(); + connections.remove(this); + } + }; return transport; }