1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16- package com .optimizely .ab .cmab ;
16+ package com .optimizely .ab .cmab . client ;
1717/**
1818 * Configuration for retry behavior in CMAB client operations.
1919 */
2020public class RetryConfig {
2121 private final int maxRetries ;
2222 private final long backoffBaseMs ;
2323 private final double backoffMultiplier ;
24-
24+ private final int maxTimeoutMs ;
25+
2526 /**
2627 * Creates a RetryConfig with custom retry and backoff settings.
2728 *
2829 * @param maxRetries Maximum number of retry attempts
2930 * @param backoffBaseMs Base delay in milliseconds for the first retry
3031 * @param backoffMultiplier Multiplier for exponential backoff (e.g., 2.0 for doubling)
32+ * @param maxTimeoutMs Maximum total timeout in milliseconds for all retry attempts
3133 */
32- public RetryConfig (int maxRetries , long backoffBaseMs , double backoffMultiplier ) {
34+ public RetryConfig (int maxRetries , long backoffBaseMs , double backoffMultiplier , int maxTimeoutMs ) {
3335 if (maxRetries < 0 ) {
3436 throw new IllegalArgumentException ("maxRetries cannot be negative" );
3537 }
@@ -39,19 +41,23 @@ public RetryConfig(int maxRetries, long backoffBaseMs, double backoffMultiplier)
3941 if (backoffMultiplier < 1.0 ) {
4042 throw new IllegalArgumentException ("backoffMultiplier must be >= 1.0" );
4143 }
44+ if (maxTimeoutMs < 0 ) {
45+ throw new IllegalArgumentException ("maxTimeoutMs cannot be negative" );
46+ }
4247
4348 this .maxRetries = maxRetries ;
4449 this .backoffBaseMs = backoffBaseMs ;
4550 this .backoffMultiplier = backoffMultiplier ;
51+ this .maxTimeoutMs = maxTimeoutMs ;
4652 }
4753
4854 /**
49- * Creates a RetryConfig with default backoff settings (1 second base, 2x multiplier).
55+ * Creates a RetryConfig with default backoff settings and timeout (1 second base, 2x multiplier, 10 second timeout ).
5056 *
5157 * @param maxRetries Maximum number of retry attempts
5258 */
5359 public RetryConfig (int maxRetries ) {
54- this (maxRetries , 1000 , 2.0 ); // Default: 1 second base, exponential backoff
60+ this (maxRetries , 1000 , 2.0 , 10000 ); // Default: 1 second base, exponential backoff, 10 second timeout
5561 }
5662
5763 /**
@@ -65,7 +71,7 @@ public static RetryConfig defaultConfig() {
6571 * Creates a RetryConfig with no retries (single attempt only).
6672 */
6773 public static RetryConfig noRetry () {
68- return new RetryConfig (0 );
74+ return new RetryConfig (0 , 0 , 1.0 , 0 );
6975 }
7076
7177 public int getMaxRetries () {
@@ -80,6 +86,10 @@ public double getBackoffMultiplier() {
8086 return backoffMultiplier ;
8187 }
8288
89+ public int getMaxTimeoutMs () {
90+ return maxTimeoutMs ;
91+ }
92+
8393 /**
8494 * Calculates the delay for a specific retry attempt.
8595 *
@@ -95,8 +105,8 @@ public long calculateDelay(int attemptNumber) {
95105
96106 @ Override
97107 public String toString () {
98- return String .format ("RetryConfig{maxRetries=%d, backoffBaseMs=%d, backoffMultiplier=%.1f}" ,
99- maxRetries , backoffBaseMs , backoffMultiplier );
108+ return String .format ("RetryConfig{maxRetries=%d, backoffBaseMs=%d, backoffMultiplier=%.1f, maxTimeoutMs=%d }" ,
109+ maxRetries , backoffBaseMs , backoffMultiplier , maxTimeoutMs );
100110 }
101111
102112 @ Override
@@ -107,6 +117,7 @@ public boolean equals(Object obj) {
107117 RetryConfig that = (RetryConfig ) obj ;
108118 return maxRetries == that .maxRetries &&
109119 backoffBaseMs == that .backoffBaseMs &&
120+ maxTimeoutMs == that .maxTimeoutMs &&
110121 Double .compare (that .backoffMultiplier , backoffMultiplier ) == 0 ;
111122 }
112123
@@ -115,6 +126,7 @@ public int hashCode() {
115126 int result = maxRetries ;
116127 result = 31 * result + Long .hashCode (backoffBaseMs );
117128 result = 31 * result + Double .hashCode (backoffMultiplier );
129+ result = 31 * result + Integer .hashCode (maxTimeoutMs );
118130 return result ;
119131 }
120132}
0 commit comments