public class Retrier extends Object
IRetriable
instances. Upon reaching the maximum number of retries allowed, it
will throw a RetriableException
, wrapping the last exceptions
encountered, if any, to a configurable maximum.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_CAUSES_KEPT
Default maximum number of exception causes kept.
|
static int |
DEFAULT_MAX_RETRIES
Default maximum number of retries.
|
static long |
DEFAULT_RETRY_DELAY
Default wait time (milliseconds) before making a new attempt.
|
Constructor and Description |
---|
Retrier()
Creates a new instance with the default maximum retries and default
retry delay (no delay).
|
Retrier(IExceptionFilter exceptionFilter)
Creates a new instance which will retry execution
only if the exception thrown by an attempt is accepted by
the
IExceptionFilter (up to maxRetries ). |
Retrier(IExceptionFilter exceptionFilter,
int maxRetries)
Creates a new instance which will retry execution
only if the exception thrown by an attempt is accepted by
the
IExceptionFilter (up to maxRetries ). |
Retrier(int maxRetries)
Creates a new instance with the default retry delay (no delay).
|
Modifier and Type | Method and Description |
---|---|
<T> T |
execute(IRetriable<T> retriable)
Runs the
IRetriable instance. |
IExceptionFilter |
getExceptionFilter()
Sets an exception filter that limits the exceptions eligible for retry.
|
int |
getMaxCauses()
Gets the maximum number of exception causes to keep when all attempts
were made and a
RetriableException is thrown. |
int |
getMaxRetries()
Gets the maximum number of retries (the initial run does not count as
a retry).
|
long |
getRetryDelay()
Gets the delay in milliseconds before attempting to execute again.
|
Retrier |
setExceptionFilter(IExceptionFilter exceptionFilter)
Sets an exception filter that limits the exceptions eligible for retry.
|
Retrier |
setMaxCauses(int maxCauses)
Sets the maximum number of exception causes to keep when all attempts
were made and a
RetriableException is thrown. |
Retrier |
setMaxRetries(int maxRetries)
Sets the maximum number of retries (the initial run does not count as
a retry).
|
Retrier |
setRetryDelay(long retryDelay)
Sets the delay in milliseconds before attempting to execute again.
|
public static final int DEFAULT_MAX_RETRIES
public static final long DEFAULT_RETRY_DELAY
public static final int DEFAULT_MAX_CAUSES_KEPT
public Retrier()
public Retrier(int maxRetries)
maxRetries
- maximum number of execution retriespublic Retrier(IExceptionFilter exceptionFilter)
IExceptionFilter
(up to maxRetries
).
Uses the default maximum retries and default retry delay.exceptionFilter
- exception filterpublic Retrier(IExceptionFilter exceptionFilter, int maxRetries)
IExceptionFilter
(up to maxRetries
).exceptionFilter
- exception filtermaxRetries
- maximum number of retriespublic int getMaxRetries()
public Retrier setMaxRetries(int maxRetries)
maxRetries
- maximum number of retriespublic long getRetryDelay()
public Retrier setRetryDelay(long retryDelay)
retryDelay
- delay in millisecondspublic IExceptionFilter getExceptionFilter()
public Retrier setExceptionFilter(IExceptionFilter exceptionFilter)
exceptionFilter
- exception filterpublic int getMaxCauses()
RetriableException
is thrown.public Retrier setMaxCauses(int maxCauses)
RetriableException
is thrown.maxCauses
- max number of causespublic <T> T execute(IRetriable<T> retriable) throws RetriableException
IRetriable
instance. This method is not thread safe.T
- type of optional return valueretriable
- the code to runRetriableException
- wrapper around last exception encountered
or exception thrown when max rerun attempts is reached.Copyright © 2008–2021 Norconex Inc.. All rights reserved.