- java.lang.Object
-
- io.helidon.config.SimpleRetryPolicy
-
- All Implemented Interfaces:
RetryPolicy
,Supplier<RetryPolicy>
public final class SimpleRetryPolicy extends Object implements RetryPolicy
A default retry policy implementation withScheduledExecutorService
. Following attributes can be configured:- number of retries (excluding the first invocation)
- delay between the invocations
- a delay multiplication factor
- a timeout for the individual invocation
- an overall timeout
- an executor service
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleRetryPolicy.Builder
Fluent API builder forSimpleRetryPolicy
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimpleRetryPolicy.Builder
builder()
Fluent API builder forSimpleRetryPolicy
.Duration
callTimeout()
Timeout of the call.boolean
cancel(boolean mayInterruptIfRunning)
Cancels the current use of the retry policy.static SimpleRetryPolicy
create(Config metaConfig)
Initializes retry policy instance from configuration properties.Duration
delay()
Delay between retries.double
delayFactor()
Delay multiplication factor.<T> T
execute(Supplier<T> call)
Invokes the providedSupplier
to read the source data and returns that data.Duration
overallTimeout()
Overall timeout.int
retries()
Number of retries.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.helidon.config.spi.RetryPolicy
get
-
-
-
-
Method Detail
-
builder
public static SimpleRetryPolicy.Builder builder()
Fluent API builder forSimpleRetryPolicy
.- Returns:
- a new builder
-
create
public static SimpleRetryPolicy create(Config metaConfig)
Initializes retry policy instance from configuration properties.Mandatory
properties
, seeRetryPolicies.repeat(int)
:retries
- typeint
properties
:delay
- typeDuration
, seeSimpleRetryPolicy.Builder.delay(Duration)
delay-factor
- typedouble
, seeSimpleRetryPolicy.Builder.delayFactor(double)
call-timeout
- typeDuration
, seeSimpleRetryPolicy.Builder.callTimeout(Duration)
overall-timeout
- typeDuration
, seeSimpleRetryPolicy.Builder.overallTimeout(Duration)
- Parameters:
metaConfig
- meta-configuration used to initialize returned polling strategy builder instance from.- Returns:
- new instance of polling strategy builder 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:
PollingStrategies.regular(Duration)
-
execute
public <T> T execute(Supplier<T> call) throws ConfigException
Description copied from interface:RetryPolicy
Invokes the providedSupplier
to read the source data and returns that data.The implementation of this method incorporates the retry logic.
- Specified by:
execute
in interfaceRetryPolicy
- Type Parameters:
T
- result type- Parameters:
call
- supplier ofT
- Returns:
- loaded data returned by the provided
Supplier
- Throws:
ConfigException
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
Description copied from interface:RetryPolicy
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.
- Specified by:
cancel
in interfaceRetryPolicy
- 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
-
retries
public int retries()
Number of retries.- Returns:
- retries
-
delay
public Duration delay()
Delay between retries.- Returns:
- delay
-
delayFactor
public double delayFactor()
Delay multiplication factor.- Returns:
- delay factor
-
callTimeout
public Duration callTimeout()
Timeout of the call.- Returns:
- call timeout
-
overallTimeout
public Duration overallTimeout()
Overall timeout.- Returns:
- overall timeout
-
-