共用方式為


FixedDelay Class

  • java.lang.Object
    • com.azure.core.http.policy.FixedDelay

Implements

public class FixedDelay
implements RetryStrategy

The FixedDelay class is an implementation of the RetryStrategy interface. This strategy uses a fixed delay duration between each retry attempt.

This class is useful when you need to handle retries for operations that may transiently fail. It ensures that the retries are performed with a fixed delay to provide a consistent delay between retries.

Code sample:

In this example, a FixedDelay is created with a maximum of 3 retry attempts and a delay of 1 second between each attempt. The strategy is then used in a RetryPolicy which can then be added to the pipeline. For a request then sent by the pipeline, if the server responds with a transient error, the request will be retried with a fixed delay of 1 second between each attempt.

FixedDelay retryStrategy = new FixedDelay(3, Duration.ofSeconds(1));
 RetryPolicy policy = new RetryPolicy(retryStrategy);

Constructor Summary

Constructor Description
FixedDelay(FixedDelayOptions fixedDelayOptions)

Creates an instance of FixedDelay.

FixedDelay(int maxRetries, Duration delay)

Creates an instance of FixedDelay.

Method Summary

Modifier and Type Method and Description
Duration calculateRetryDelay(int retryAttempts)

Computes the delay between each retry.

int getMaxRetries()

Max number of retry attempts to be make.

boolean shouldRetryCondition(RequestRetryCondition requestRetryCondition)

This method is consulted to determine if a retry attempt should be made for the given RequestRetryCondition.

Methods inherited from java.lang.Object

Constructor Details

FixedDelay

public FixedDelay(FixedDelayOptions fixedDelayOptions)

Creates an instance of FixedDelay.

Parameters:

fixedDelayOptions - The FixedDelayOptions.

FixedDelay

public FixedDelay(int maxRetries, Duration delay)

Creates an instance of FixedDelay.

Parameters:

maxRetries - The max number of retry attempts that can be made.
delay - The fixed delay duration between retry attempts.

Method Details

calculateRetryDelay

public Duration calculateRetryDelay(int retryAttempts)

Computes the delay between each retry.

Parameters:

retryAttempts

getMaxRetries

public int getMaxRetries()

Max number of retry attempts to be make.

shouldRetryCondition

public boolean shouldRetryCondition(RequestRetryCondition requestRetryCondition)

This method is consulted to determine if a retry attempt should be made for the given RequestRetryCondition.

By default, if the RequestRetryCondition contains a non-null HttpResponse, then the #shouldRetry(HttpResponse) method is called, otherwise the #shouldRetryException(Throwable) method is called.

Parameters:

requestRetryCondition

Applies to