fixed exponentialBackoff

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@379397 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-02-21 09:14:07 +00:00
parent 4c3f739198
commit 2bc09bb764
1 changed files with 18 additions and 6 deletions

View File

@ -59,6 +59,7 @@ public class FailoverTransport implements CompositeTransport {
private final CopyOnWriteArrayList uris = new CopyOnWriteArrayList(); private final CopyOnWriteArrayList uris = new CopyOnWriteArrayList();
private final Object reconnectMutex = new Object(); private final Object reconnectMutex = new Object();
private final Object sleepMutex = new Object();
private final ConnectionStateTracker stateTracker = new ConnectionStateTracker(); private final ConnectionStateTracker stateTracker = new ConnectionStateTracker();
private final ConcurrentHashMap requestMap = new ConcurrentHashMap(); private final ConcurrentHashMap requestMap = new ConcurrentHashMap();
@ -136,7 +137,9 @@ public class FailoverTransport implements CompositeTransport {
if( connectList.isEmpty() ) { if( connectList.isEmpty() ) {
failure = new IOException("No uris available to connect to."); failure = new IOException("No uris available to connect to.");
} else { } else {
reconnectDelay = initialReconnectDelay; if (!useExponentialBackOff){
reconnectDelay = initialReconnectDelay;
}
Iterator iter = connectList.iterator(); Iterator iter = connectList.iterator();
for (int i = 0; iter.hasNext() && connectedTransport == null && !disposed; i++) { for (int i = 0; iter.hasNext() && connectedTransport == null && !disposed; i++) {
URI uri = (URI) iter.next(); URI uri = (URI) iter.next();
@ -175,12 +178,17 @@ public class FailoverTransport implements CompositeTransport {
} }
if(!disposed){ if(!disposed){
try{
log.debug("Waiting "+reconnectDelay+" ms before attempting connection. "); log.debug("Waiting "+reconnectDelay+" ms before attempting connection. ");
Thread.sleep(reconnectDelay); synchronized(sleepMutex){
}catch(InterruptedException e1){ try{
Thread.currentThread().interrupt(); sleepMutex.wait(reconnectDelay);
} }catch(InterruptedException e){
Thread.currentThread().interrupt();
}
}
if(useExponentialBackOff){ if(useExponentialBackOff){
// Exponential increment of reconnect delay. // Exponential increment of reconnect delay.
reconnectDelay*=backOffMultiplier; reconnectDelay*=backOffMultiplier;
@ -234,6 +242,10 @@ public class FailoverTransport implements CompositeTransport {
if (connectedTransport != null) { if (connectedTransport != null) {
connectedTransport.stop(); connectedTransport.stop();
} }
reconnectMutex.notifyAll();
}
synchronized(sleepMutex){
sleepMutex.notifyAll();
} }
} }