Search in sources :

Example 1 with Retry

use of com.dtflys.forest.annotation.Retry in project forest by dromara.

the class RetryLifeCycle method onInvokeMethod.

@Override
public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
    Retry annotation = (Retry) request.getMethod().getExtensionParameterValue(PARAM_KEY_RETRY);
    Object retryWhen = request.getMethod().getExtensionParameterValue(PARAM_KEY_RETRY_WHEN);
    String maxRetryCountStr = annotation.maxRetryCount();
    String maxRetryIntervalStr = annotation.maxRetryInterval();
    if (StringUtils.isNotBlank(maxRetryCountStr)) {
        MappingTemplate maxRetryCountTemplate = method.makeTemplate(Retry.class, "maxRetryCount", maxRetryCountStr);
        try {
            Integer maxRetryCount = Integer.parseInt(maxRetryCountTemplate.render(args));
            request.maxRetryCount(maxRetryCount);
        } catch (Throwable ignored) {
        }
    }
    if (StringUtils.isNotBlank(maxRetryIntervalStr)) {
        try {
            MappingTemplate maxRetryIntervalTemplate = method.makeTemplate(Retry.class, "maxRetryInterval", maxRetryIntervalStr);
            Long maxRetryInterval = Long.parseLong(maxRetryIntervalTemplate.render(args));
            request.setMaxRetryInterval(maxRetryInterval);
        } catch (Throwable ignored) {
        }
    }
    if (retryWhen != null) {
        request.retryWhen((RetryWhen) retryWhen);
    }
}
Also used : MappingTemplate(com.dtflys.forest.mapping.MappingTemplate) Retry(com.dtflys.forest.annotation.Retry)

Aggregations

Retry (com.dtflys.forest.annotation.Retry)1 MappingTemplate (com.dtflys.forest.mapping.MappingTemplate)1