You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/08/08 12:11:42 UTC
svn commit: r1154900 -
/cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
Author: sergeyb
Date: Mon Aug 8 10:11:42 2011
New Revision: 1154900
URL: http://svn.apache.org/viewvc?rev=1154900&view=rev
Log:
[CXF-3596] Updating RetryStrategy to optionally move to the next address after specific number of retries
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java?rev=1154900&r1=1154899&r2=1154900&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java Mon Aug 8 10:11:42 2011
@@ -32,13 +32,46 @@ import org.apache.cxf.message.Exchange;
*/
public class RetryStrategy extends SequentialStrategy {
+ private int maxNumberOfRetries;
+ private int counter;
+
/* (non-Javadoc)
* @see org.apache.cxf.clustering.AbstractStaticFailoverStrategy#getAlternateEndpoints(
* org.apache.cxf.message.Exchange)
*/
@Override
public List<Endpoint> getAlternateEndpoints(Exchange exchange) {
- return getEndpoints(exchange, true);
+ return getEndpoints(exchange, stillTheSameAddress());
+ }
+
+ protected boolean stillTheSameAddress() {
+ if (maxNumberOfRetries == 0) {
+ return true;
+ }
+ // let the target selector move to the next address
+ // and then stay on the same address for maxNumberOfRetries
+ synchronized (this) {
+ if (++counter <= maxNumberOfRetries) {
+ return true;
+ } else {
+ counter = 0;
+ return false;
+ }
+ }
+
+ }
+
+
+ public void setMaxNumberOfRetries(int maxNumberOfRetries) {
+ if (maxNumberOfRetries < 0) {
+ throw new IllegalArgumentException();
+ }
+ this.maxNumberOfRetries = maxNumberOfRetries;
+ }
+
+
+ public int getMaxNumberOfRetries() {
+ return maxNumberOfRetries;
}
}
\ No newline at end of file