Package org.jeasy.batch.core.retry
Class RetryTemplate
- java.lang.Object
-
- org.jeasy.batch.core.retry.RetryTemplate
-
public abstract class RetryTemplate extends java.lang.Object
Support class providing a template method for a retryable code with a retry policy.- Author:
- Mahmoud Ben Hassine ([email protected])
-
-
Field Summary
Fields Modifier and Type Field Description protected RetryPolicy
retryPolicy
-
Constructor Summary
Constructors Constructor Description RetryTemplate(RetryPolicy retryPolicy)
Create a newRetryTemplate
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
afterCall(java.lang.Object result)
Called after calling the callable.protected abstract void
afterWait()
Called after waiting for next attempt.protected abstract void
beforeCall()
Called before calling the callable.protected abstract void
beforeWait()
Called before waiting for next attempt.<T> T
execute(java.util.concurrent.Callable<T> callable)
Execute the callable with retries.protected abstract void
onException(java.lang.Exception exception)
Called whenever the callable throw an exception.protected abstract void
onMaxAttempts(java.lang.Exception exception)
Called whenever all retries have been executed.
-
-
-
Field Detail
-
retryPolicy
protected RetryPolicy retryPolicy
-
-
Constructor Detail
-
RetryTemplate
public RetryTemplate(RetryPolicy retryPolicy)
Create a newRetryTemplate
.- Parameters:
retryPolicy
- the retry policy to apply
-
-
Method Detail
-
execute
public <T> T execute(java.util.concurrent.Callable<T> callable) throws java.lang.Exception
Execute the callable with retries.- Type Parameters:
T
- the return type of the callable- Parameters:
callable
- to execute- Returns:
- the result of the callable
- Throws:
java.lang.Exception
- if the callable still throw an exception after all retries
-
beforeCall
protected abstract void beforeCall()
Called before calling the callable.
-
afterCall
protected abstract void afterCall(java.lang.Object result)
Called after calling the callable.- Parameters:
result
- the result of the callable
-
onException
protected abstract void onException(java.lang.Exception exception)
Called whenever the callable throw an exception.- Parameters:
exception
- thrown by the callable
-
onMaxAttempts
protected abstract void onMaxAttempts(java.lang.Exception exception)
Called whenever all retries have been executed.- Parameters:
exception
- thrown by the callable on the last attempt
-
beforeWait
protected abstract void beforeWait()
Called before waiting for next attempt.
-
afterWait
protected abstract void afterWait()
Called after waiting for next attempt.
-
-