support defining local address and port for a socket - e.g:

ssl://localhost:5666/localhost:60606
where the path (localhost:60606) - defines the local address and local port

For jira issue: AMQ-529

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@375923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-02-08 11:03:02 +00:00
parent c195dd3052
commit d52e6ac042
1 changed files with 29 additions and 13 deletions

View File

@ -16,6 +16,14 @@
*/ */
package org.apache.activemq.transport.tcp; package org.apache.activemq.transport.tcp;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
import org.activeio.command.WireFormat; import org.activeio.command.WireFormat;
import org.apache.activemq.openwire.OpenWireFormat; import org.apache.activemq.openwire.OpenWireFormat;
import org.apache.activemq.transport.MutexTransport; import org.apache.activemq.transport.MutexTransport;
@ -28,19 +36,11 @@ import org.apache.activemq.transport.WireFormatNegotiator;
import org.apache.activemq.util.IOExceptionSupport; import org.apache.activemq.util.IOExceptionSupport;
import org.apache.activemq.util.IntrospectionSupport; import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.URISupport; import org.apache.activemq.util.URISupport;
import org.apache.commons.logging.Log;
import javax.net.ServerSocketFactory; import org.apache.commons.logging.LogFactory;
import javax.net.SocketFactory;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
public class TcpTransportFactory extends TransportFactory { public class TcpTransportFactory extends TransportFactory {
private static final Log log = LogFactory.getLog(TcpTransportFactory.class);
public TransportServer doBind(String brokerId, final URI location) throws IOException { public TransportServer doBind(String brokerId, final URI location) throws IOException {
try { try {
Map options = new HashMap(URISupport.parseParamters(location)); Map options = new HashMap(URISupport.parseParamters(location));
@ -90,8 +90,24 @@ public class TcpTransportFactory extends TransportFactory {
return transport; return transport;
} }
protected Transport createTransport(URI location, WireFormat wf) throws UnknownHostException, IOException { protected Transport createTransport(URI location,WireFormat wf) throws UnknownHostException,IOException{
return new TcpTransport(wf, location); URI localLocation=null;
String path=location.getPath();
// see if the path is a local URI location
if(path!=null&&path.length()>0){
int localPortIndex=path.indexOf(':');
try{
Integer.parseInt(path.substring((localPortIndex+1),path.length()));
String localString=location.getScheme()+ ":/" + path;
localLocation=new URI(localString);
}catch(Exception e){
log.warn("path isn't a valid local location for TcpTransport to use",e);
}
}
if(localLocation!=null){
return new TcpTransport(wf,location,localLocation);
}
return new TcpTransport(wf,location);
} }
protected ServerSocketFactory createServerSocketFactory() { protected ServerSocketFactory createServerSocketFactory() {