Search in sources :

Example 1 with ForestRetryer

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;
}
Also used : Constructor(java.lang.reflect.Constructor) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) ForestRetryer(com.dtflys.forest.retryer.ForestRetryer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ForestRetryer

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);
}
Also used : ForestRetryer(com.dtflys.forest.retryer.ForestRetryer) Retryer(com.dtflys.forest.annotation.Retryer)

Aggregations

ForestRetryer (com.dtflys.forest.retryer.ForestRetryer)2 Retryer (com.dtflys.forest.annotation.Retryer)1 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1