activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1486869 - in /activemq/trunk: activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverPriorityTest.java
Date Tue, 28 May 2013 11:17:17 GMT
Author: dejanb
Date: Tue May 28 11:17:17 2013
New Revision: 1486869

URL: http://svn.apache.org/r1486869
Log:
https://issues.apache.org/jira/browse/AMQ-4461 - priority backup should not be restricted
by the pool size

Modified:
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverPriorityTest.java

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java?rev=1486869&r1=1486868&r2=1486869&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
(original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
Tue May 28 11:17:17 2013
@@ -1156,9 +1156,13 @@ public class FailoverTransport implement
         return maxReconnectValue;
     }
 
+    private boolean shouldBuildBackups() {
+       return (backup && backups.size() < backupPoolSize) || (priorityBackup &&
!(priorityBackupAvailable || connectedToPriority));
+    }
+
     final boolean buildBackups() {
         synchronized (backupMutex) {
-            if (!disposed && (backup || priorityBackup) && backups.size()
< backupPoolSize) {
+            if (!disposed && shouldBuildBackups()) {
                 ArrayList<URI> backupList = new ArrayList<URI>(priorityList);
                 List<URI> connectList = getConnectList();
                 for (URI uri: connectList) {
@@ -1175,7 +1179,7 @@ public class FailoverTransport implement
                 }
                 backups.removeAll(disposedList);
                 disposedList.clear();
-                for (Iterator<URI> iter = backupList.iterator(); !disposed &&
iter.hasNext() && backups.size() < backupPoolSize; ) {
+                for (Iterator<URI> iter = backupList.iterator(); !disposed &&
iter.hasNext() && shouldBuildBackups(); ) {
                     URI uri = iter.next();
                     if (connectedTransportURI != null && !connectedTransportURI.equals(uri))
{
                         try {
@@ -1190,6 +1194,17 @@ public class FailoverTransport implement
                                 if (priorityBackup && isPriority(uri)) {
                                    priorityBackupAvailable = true;
                                    backups.add(0, bt);
+                                   // if this priority backup overflows the pool
+                                   // remove the backup with the lowest priority
+                                   if (backups.size() > backupPoolSize) {
+                                       BackupTransport disposeTransport = backups.remove(backups.size()
- 1);
+                                       disposeTransport.setDisposed(true);
+                                       Transport transport = disposeTransport.getTransport();
+                                       if (transport != null) {
+                                           transport.setTransportListener(disposedListener);
+                                           disposeTransport(transport);
+                                       }
+                                   }
                                 } else {
                                     backups.add(bt);
                                 }

Modified: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverPriorityTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverPriorityTest.java?rev=1486869&r1=1486868&r2=1486869&view=diff
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverPriorityTest.java
(original)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverPriorityTest.java
Tue May 28 11:17:17 2013
@@ -115,7 +115,7 @@ public class FailoverPriorityTest extend
         getBroker(BROKER_C_NAME).waitUntilStarted();
         Thread.sleep(1000);
 
-        setClientUrl("failover:(" + BROKER_A_CLIENT_TC_ADDRESS + "," + BROKER_B_CLIENT_TC_ADDRESS
+ "," + BROKER_C_CLIENT_TC_ADDRESS + ")?randomize=false&priorityBackup=true&initialReconnectDelay=1000&useExponentialBackOff=false&backupPoolSize=2");
+        setClientUrl("failover:(" + BROKER_A_CLIENT_TC_ADDRESS + "," + BROKER_B_CLIENT_TC_ADDRESS
+ "," + BROKER_C_CLIENT_TC_ADDRESS + ")?randomize=false&priorityBackup=true&initialReconnectDelay=1000&useExponentialBackOff=false");
 
         createClients(5);
 



Mime
View raw message