mirror of https://github.com/apache/activemq.git
Added better proxy connector cleanup code.
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@376047 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7e672d4150
commit
a7ac415557
|
@ -19,16 +19,21 @@ package org.apache.activemq.proxy;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.activemq.Service;
|
import org.apache.activemq.Service;
|
||||||
import org.apache.activemq.transport.CompositeTransport;
|
import org.apache.activemq.transport.CompositeTransport;
|
||||||
import org.apache.activemq.transport.Transport;
|
import org.apache.activemq.transport.Transport;
|
||||||
import org.apache.activemq.transport.TransportAcceptListener;
|
import org.apache.activemq.transport.TransportAcceptListener;
|
||||||
import org.apache.activemq.transport.TransportFactory;
|
import org.apache.activemq.transport.TransportFactory;
|
||||||
|
import org.apache.activemq.transport.TransportFilter;
|
||||||
import org.apache.activemq.transport.TransportServer;
|
import org.apache.activemq.transport.TransportServer;
|
||||||
|
import org.apache.activemq.util.ServiceStopper;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @org.xbean.XBean
|
* @org.xbean.XBean
|
||||||
*
|
*
|
||||||
|
@ -41,6 +46,8 @@ public class ProxyConnector implements Service {
|
||||||
private URI bind;
|
private URI bind;
|
||||||
private URI remote;
|
private URI remote;
|
||||||
private URI localUri;
|
private URI localUri;
|
||||||
|
|
||||||
|
CopyOnWriteArrayList connections = new CopyOnWriteArrayList();
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
|
||||||
|
@ -49,7 +56,8 @@ public class ProxyConnector implements Service {
|
||||||
try {
|
try {
|
||||||
Transport remoteTransport = createRemoteTransport();
|
Transport remoteTransport = createRemoteTransport();
|
||||||
ProxyConnection connection = new ProxyConnection(localTransport, remoteTransport);
|
ProxyConnection connection = new ProxyConnection(localTransport, remoteTransport);
|
||||||
connection.start();
|
connections.add(connection);
|
||||||
|
connection.start();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
onAcceptError(e);
|
onAcceptError(e);
|
||||||
|
@ -65,9 +73,15 @@ public class ProxyConnector implements Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
|
ServiceStopper ss = new ServiceStopper();
|
||||||
if( this.server!=null ) {
|
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
|
// Properties
|
||||||
|
@ -121,6 +135,15 @@ public class ProxyConnector implements Service {
|
||||||
if( ct !=null && localUri!=null ) {
|
if( ct !=null && localUri!=null ) {
|
||||||
ct.add(new URI[]{localUri});
|
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;
|
return transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue