Package co.cryptoservice.sdk
Record Class RetryOptions
java.lang.Object
java.lang.Record
co.cryptoservice.sdk.RetryOptions
- Record Components:
maxRetries- the retries after the first attempt (0 or more)initialDelay- the cap on the first retry's wait (positive)maxDelay- the cap on any wait, and the longestRetry-Afterhonoured (no shorter thaninitialDelay)
Automatic retries of transient failures; off by default (
maxRetries = 0).
With retries on, the client sends a call again after HTTP 429, 503 or 504, or after a lost
connection or an attempt timeout, up to maxRetries() more times. Routes
that create or delete server state (key generation, /v2/keys/delete,
/v2/kms/create-key, /v2/opaque/register/*) are retried only after 429 or 503, when the
server certainly did not act; never after a 504 or a lost connection.
The wait before retry n (from 1) is full jitter: a random point in [0,
min(maxDelay, initialDelay * 2^(n-1))). A Retry-After header (seconds or an HTTP date)
replaces it; when it asks for longer than maxDelay() the client stops and
raises that answer rather than retry early.
CryptoServiceClient client = CryptoServiceClient.builder()
.baseUrl("http://127.0.0.1:3101")
.apiKey(System.getenv("CRYPTO_SERVICE_API_KEY"))
.retry(RetryOptions.of(3))
.build();
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe default initial delay, 200 ms.static final DurationThe default maximum delay, 2 s.static final RetryOptionsNo retries: every call is sent once. -
Constructor Summary
ConstructorsConstructorDescriptionRetryOptions(int maxRetries, Duration initialDelay, Duration maxDelay) Checks the values. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theinitialDelayrecord component.maxDelay()Returns the value of themaxDelayrecord component.intReturns the value of themaxRetriesrecord component.static RetryOptionsof(int maxRetries) maxRetriesretries with the default delays (200 ms initial, 2 s maximum).final StringtoString()Returns a string representation of this record class.
-
Field Details
-
DEFAULT_INITIAL_DELAY
The default initial delay, 200 ms. -
DEFAULT_MAX_DELAY
The default maximum delay, 2 s. -
NONE
No retries: every call is sent once.
-
-
Constructor Details
-
RetryOptions
Checks the values.- Throws:
IllegalArgumentException- whenmaxRetriesis negative, a delay is missing or not positive, ormaxDelayis shorter thaninitialDelay
-
-
Method Details
-
of
maxRetriesretries with the default delays (200 ms initial, 2 s maximum).- Parameters:
maxRetries- the retries after the first attempt- Returns:
- the options
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
maxRetries
public int maxRetries()Returns the value of themaxRetriesrecord component.- Returns:
- the value of the
maxRetriesrecord component
-
initialDelay
Returns the value of theinitialDelayrecord component.- Returns:
- the value of the
initialDelayrecord component
-
maxDelay
Returns the value of themaxDelayrecord component.- Returns:
- the value of the
maxDelayrecord component
-