use of com.dtflys.forest.retryer.ForestRetryer in project forest by dromara.
the class ForestRequest method setRetryer.
/**
* 设置Forest请求重试器
* <p>输入参数为 {@link ForestRetryer} 的子类 {@link Class} 对象
* <p>方法会自动将其实例化并设置为请求的重试器
*
* @param retryerClass {@link ForestRetryer} 的子类 {@link Class} 对象
* @return {@link ForestRequest}类实例
*/
public ForestRequest<T> setRetryer(Class<? extends ForestRetryer> retryerClass) {
try {
Constructor constructor = retryerClass.getConstructor(ForestRequest.class);
ForestRetryer retryer = (ForestRetryer) constructor.newInstance(this);
this.setRetryer(retryer);
} catch (NoSuchMethodException e) {
throw new ForestRuntimeException(e);
} catch (IllegalAccessException e) {
throw new ForestRuntimeException(e);
} catch (InstantiationException e) {
throw new ForestRuntimeException(e);
} catch (InvocationTargetException e) {
throw new ForestRuntimeException(e);
}
return this;
}
use of com.dtflys.forest.retryer.ForestRetryer in project forest by dromara.
the class RetryerLifeCycle method onInvokeMethod.
@Override
public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
Retryer annotation = (Retryer) request.getMethod().getExtensionParameterValue(PARAM_KEY_RETRYER);
Class<? extends ForestRetryer> clazz = annotation.value();
request.setRetryer(clazz);
}
Aggregations