com.kingsoft.services.retry.MaxTimeoutRetryCondition Maven / Gradle / Ivy
package com.kingsoft.services.retry;
import com.kingsoft.services.RequestMessage;
import com.kingsoft.services.exception.KWSClientException;
import com.kingsoft.services.retry.PredefinedRetryStrategy.SDKDefaultRetryCondition;
public class MaxTimeoutRetryCondition extends SDKDefaultRetryCondition {
//private static final int PRE_DEFINED_EXECUTE_TIME = 500; //进行一次http请求预计话费的时间,目前暂定为200ms
private int timeoutMs;
public MaxTimeoutRetryCondition(int timeoutMs) {
super();
if (timeoutMs <= 0) {
throw new IllegalArgumentException("timeoutTimeMs must be a positive int");
}
this.timeoutMs = timeoutMs;
}
@Override
public boolean shouldRetry(RequestMessage> originalRequest,
KWSClientException exception, int retriesAttempted) {
boolean retry = super.shouldRetry(originalRequest, exception, retriesAttempted);
if (!retry) {
return false;
}
if (System.currentTimeMillis() > originalRequest.getStartTime() + timeoutMs) {
return false;
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy