mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@418413 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
311cd54b78
commit
a537902613
|
@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.BindException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -51,6 +52,9 @@ import java.nio.channels.DatagramChannel;
|
|||
public class UdpTransport extends TransportThreadSupport implements Transport, Service, Runnable {
|
||||
private static final Log log = LogFactory.getLog(UdpTransport.class);
|
||||
|
||||
private static final int MAX_BIND_ATTEMPTS = 50;
|
||||
private static final long BIND_ATTEMPT_DELAY = 100;
|
||||
|
||||
private CommandChannel commandChannel;
|
||||
private OpenWireFormat wireFormat;
|
||||
private ByteBufferPool bufferPool;
|
||||
|
@ -387,7 +391,26 @@ public class UdpTransport extends TransportThreadSupport implements Transport, S
|
|||
if (log.isDebugEnabled()) {
|
||||
log.debug("Binding to address: " + localAddress);
|
||||
}
|
||||
socket.bind(localAddress);
|
||||
|
||||
//
|
||||
// We have noticed that on some platfoms like linux, after you close down
|
||||
// a previously bound socket, it can take a little while before we can bind it again.
|
||||
//
|
||||
for(int i=0; i < MAX_BIND_ATTEMPTS; i++){
|
||||
try {
|
||||
socket.bind(localAddress);
|
||||
return;
|
||||
} catch (BindException e) {
|
||||
if ( i+1 == MAX_BIND_ATTEMPTS )
|
||||
throw e;
|
||||
try {
|
||||
Thread.sleep(BIND_ATTEMPT_DELAY);
|
||||
} catch (InterruptedException e1) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected DatagramChannel connect(DatagramChannel channel, SocketAddress targetAddress2) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue