Interface RetryPolicy
-
- All Superinterfaces:
Supplier<RetryPolicy>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface RetryPolicy extends Supplier<RetryPolicy>
Mechanism for controlling retry of attempts to load data by anAbstractSource
.When an
AbstractSource
attempts to load the underlying data it uses aRetryPolicy
to govern if and how it retries the load operation in case of errors.The
execute(java.util.function.Supplier)
method of each policy implementation must perform at least one attempt to load the data, even if it chooses not to retry in case of errors.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default boolean
cancel(boolean mayInterruptIfRunning)
Cancels the current use of the retry policy.static RetryPolicy
create(Config metaConfig)
Constructs aRetryPolicy
from meta-configuration.<T> T
execute(Supplier<T> call)
Invokes the providedSupplier
to read the source data and returns that data.default RetryPolicy
get()
-
-
-
Method Detail
-
create
static RetryPolicy create(Config metaConfig) throws ConfigMappingException, MissingValueException
Constructs aRetryPolicy
from meta-configuration.As described with
ConfigSource.create(Config)
, the config system can loadConfigSource
s using meta-configuration, which supports specifying retry policies. Thebuilt-in retry policies
and custom ones are supported. (The support is tightly connected withAbstractSource extensions
and will not be automatically provided by any another config source implementations.)The meta-configuration for a config source can set the property
retry-policy
using the following nestedproperties
:type
- name of the retry policy implementation.Built-in Retry Policies Name Policy Properties repeat
Tries to load at regular intervals until the retry count reaches retries
. SeeRetryPolicies.repeat(int)
, andRetryPolicies.Builder
for details on theproperties
.class
- fully qualified class name of custom retry policy implementation or a builder class that implements abuild()
method that returns aRetryPolicy
.
type
orclass
to indicate a retry policy but not both. If both appear the config system ignores theclass
setting.See
ConfigSource.create(Config)
for example of using built-in retry policies.Meta-configuration Support for Custom Retry Policies
To support settings in meta-configuration, a custom retry policy must follow this pattern.The implementation class should define a Java bean property for each meta-configuration property it needs to support. The config system uses mapping functions to convert the text in the meta-configuration into the correct Java type and then assigns the value to the correspondingly-named Java bean property defined on the custom policy instance. See the built-in mappers defined in
ConfigMappers
to see what Java types are automatically supported.- Parameters:
metaConfig
- meta-configuration used to initialize returned retry policy instance from.- Returns:
- new instance of retry policy described by
metaConfig
- Throws:
MissingValueException
- in case the configuration tree does not contain all expected sub-nodes required by the mapper implementation to provide instance of Java type.ConfigMappingException
- in case the mapper fails to map the (existing) configuration tree represented by the supplied configuration node to an instance of a given Java type.- See Also:
ConfigSources.load(Supplier[])
,ConfigSources.load(Config)
-
execute
<T> T execute(Supplier<T> call)
Invokes the providedSupplier
to read the source data and returns that data.The implementation of this method incorporates the retry logic.
- Type Parameters:
T
- result type- Parameters:
call
- supplier ofT
- Returns:
- loaded data returned by the provided
Supplier
-
cancel
default boolean cancel(boolean mayInterruptIfRunning)
Cancels the current use of the retry policy.Implementations should correctly handle three cases:
cancel
invoked when no invocation ofexecute
is in progress,cancel
invoked when an invocation ofexecute
is active but no attempted load is actually in progress (e.g., a prior attempt failed and the retry policy is waiting for some time to pass before trying again), andcancel
invoked while a load attempt is in progress.
- Parameters:
mayInterruptIfRunning
- whether an in-progress load attempt should be interrupted- Returns:
false
if the task could not be canceled, typically because it has already completed;true
otherwise
-
get
default RetryPolicy get()
- Specified by:
get
in interfaceSupplier<RetryPolicy>
-
-