Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9987D8202 for ; Mon, 8 Aug 2011 10:12:19 +0000 (UTC) Received: (qmail 65228 invoked by uid 500); 8 Aug 2011 10:12:16 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 65097 invoked by uid 500); 8 Aug 2011 10:12:07 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 65088 invoked by uid 99); 8 Aug 2011 10:12:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2011 10:12:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2011 10:12:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C9A5E23889D5 for ; Mon, 8 Aug 2011 10:11:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1154900 - /cxf/trunk/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java Date: Mon, 08 Aug 2011 10:11:42 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110808101142.C9A5E23889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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