public final class Retriers extends Object
Group of utility methods to configure the SDK retry behavior
Modifier and Type | Method and Description |
---|---|
static BmcGenericRetrier |
createPreferredRetrier(RetryConfiguration requestRetryConfiguration,
RetryConfiguration clientRetryConfiguration)
Choose the desired retry configuration and use it to create the retrier.
|
static BmcGenericRetrier |
createPreferredRetrier(RetryConfiguration requestRetryConfiguration,
RetryConfiguration clientRetryConfiguration,
boolean specBasedDefaultRetryEnabled)
Choose the desired retry configuration and use it to create the retrier.
|
static void |
setDefaultRetryConfiguration(@NonNull RetryConfiguration retryConfiguration)
Setter for the default retry configuration used in the SDK.
|
static boolean |
shouldSendOpcRetryToken()
Gets whether the SDK is automatically sending the opc-retry-token header
|
static void |
shouldSendOpcRetryToken(boolean shouldSendOpcRetryToken)
Sets whether the SDK should automatically send the opc-retry-token header
|
static void |
tryResetStreamForRetry(InputStream body)
Try to reset the
InputStream for the next retry, if supported. |
static void |
tryResetStreamForRetry(InputStream body,
boolean failIfUnsupported)
Try to reset the
InputStream for the next retry, if supported. |
static <T extends BmcRequest<InputStream>> |
wrapBodyInputStreamIfNecessary(T request,
BmcRequest.Builder<T,InputStream> builder)
Wrap the input stream in the request so retries can work.
|
static InputStream |
wrapInputStreamForRetry(InputStream body)
Wrap the input stream so retries can work.
|
public static void setDefaultRetryConfiguration(@NonNull @NonNull RetryConfiguration retryConfiguration)
Setter for the default retry configuration used in the SDK. This can be overriden by setting
a retry configuration on the client (via ClientConfiguration
) or the request (via
BmcRequest.setRetryConfiguration(RetryConfiguration)
)
retryConfiguration
- the RetryConfiguration
to usepublic static void shouldSendOpcRetryToken(boolean shouldSendOpcRetryToken)
Sets whether the SDK should automatically send the opc-retry-token header
shouldSendOpcRetryToken
- if true
, then the SDK will automatically send the opc-retry-token headerpublic static boolean shouldSendOpcRetryToken()
Gets whether the SDK is automatically sending the opc-retry-token header
true
if the SDK automatically sends the opc-retry-token header, else false
public static BmcGenericRetrier createPreferredRetrier(@Nullable RetryConfiguration requestRetryConfiguration, @Nullable RetryConfiguration clientRetryConfiguration)
Choose the desired retry configuration and use it to create the retrier.
requestRetryConfiguration
- the retry configuration set on the request objectclientRetryConfiguration
- the retry configuration set on the client objectpublic static BmcGenericRetrier createPreferredRetrier(@Nullable RetryConfiguration requestRetryConfiguration, @Nullable RetryConfiguration clientRetryConfiguration, boolean specBasedDefaultRetryEnabled)
Choose the desired retry configuration and use it to create the retrier.
requestRetryConfiguration
- the retry configuration set on the request objectclientRetryConfiguration
- the retry configuration set on the client objectspecBasedDefaultRetryEnabled
- boolean value indicating if default retry is enabled via specpublic static void tryResetStreamForRetry(InputStream body)
Try to reset the InputStream
for the next retry, if supported.
If the stream supports InputStream.mark(int)
and InputStream.reset()
, we reset the stream so it
starts at the beginning (or wherever the stream has been marked using InputStream.mark(int)
.
Note that this means that if the caller has used InputStream.mark(int)
and the mark does not represent
the place in the stream where retries should commence (if retries are requested and necessary), then incorrect
data may be processed.
If the stream does not support InputStream.mark(int)
and InputStream.reset()
, then retries
will not work. Therefore, those streams should be wrapped in a BufferedInputStream
before
they are sent here.
If the stream does not support being reset, this method throws an IllegalArgumentException. This is never
the case using the auto-generated code, since streams are always wrapped and/or buffered appropriately.
It could happen if someone sent in a KeepOpenInputStream
directly,
but users are not supposed to do that, since it’s an internal class.
body
- IllegalArgumentException
- if stream does not support being resetRuntimeException
- if stream does support being reset, but the reset failedpublic static void tryResetStreamForRetry(InputStream body, boolean failIfUnsupported)
Try to reset the InputStream
for the next retry, if supported. If not supported, fail if requested.
If the stream supports InputStream.mark(int)
and InputStream.reset()
, we reset the stream so it
starts at the beginning (or wherever the stream has been marked using InputStream.mark(int)
.
Note that this means that if the caller has used InputStream.mark(int)
and the mark does not represent
the place in the stream where retries should commence (if retries are requested and necessary), then incorrect
data may be processed.
If the stream does not support InputStream.mark(int)
and InputStream.reset()
, then retries
will not work. Therefore, those streams should be wrapped in a BufferedInputStream
before
they are sent here.
body
- failIfUnsupported
- if true, fail if unsupportedIllegalArgumentException
- if stream does not support being reset and failIfUnsupported is trueRuntimeException
- if stream does support being reset, but the reset failedpublic static <T extends BmcRequest<InputStream>> T wrapBodyInputStreamIfNecessary(T request, BmcRequest.Builder<T,InputStream> builder)
Wrap the input stream in the request so retries can work.
Note: The stream in the request may be wrapped in a KeepOpenInputStream
,
which prevents a call to close()
from actually closing the stream (this is necessary, since a closed
stream would not be able to serve in a potentially required retry). If this method
(wrapBodyInputStreamIfNecessary
) is called on request with a stream, you have to enclose it in a
try-finally
block that calls KeepOpenInputStream.closeStream(InputStream)
.
Example:
try {
request = Retriers.wrapBodyInputStreamIfNecessary(
request, MyRequest.builder());
...
} finally {
com.oracle.bmc.io.internal.KeepOpenInputStream.closeStream(
request.getBody$());
}
T
- type of the requestrequest
- request being handledbuilder
- builder for the requestpublic static InputStream wrapInputStreamForRetry(InputStream body)
Wrap the input stream so retries can work.
Note: The stream in the request may be wrapped in a KeepOpenInputStream
,
which prevents a call to close()
from actually closing the stream (this is necessary, since a closed
stream would not be able to serve in a potentially required retry).
After using this method, you now have to close the stream in a try-finally
block that calls
KeepOpenInputStream.closeStream(InputStream)
.
Example:
try {
stream = Retriers.wrapInputStreamForRetry(stream);
...
} finally {
com.oracle.bmc.io.internal.KeepOpenInputStream.closeStream(stream);
}
body
- input stream bodyCopyright © 2016–2022. All rights reserved.