com.aliyuncs.policy.retry.conditions.StatusCodeCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aliyun-java-sdk-core Show documentation
Show all versions of aliyun-java-sdk-core Show documentation
Aliyun Open API SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
package com.aliyuncs.policy.retry.conditions;
import com.aliyuncs.policy.retry.RetryPolicyContext;
import com.aliyuncs.policy.retry.RetryUtil;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public final class StatusCodeCondition implements RetryCondition {
private final Set statusCodesToRetryOn;
private StatusCodeCondition(Set statusCodesToRetryOn) {
this.statusCodesToRetryOn = new HashSet(statusCodesToRetryOn);
}
@Override
public boolean meetState(RetryPolicyContext context) {
Integer code = context.httpStatusCode();
if (code == null) {
return false;
}
for (Integer s : statusCodesToRetryOn) {
if (code.equals(s)) {
return true;
}
}
return false;
}
@Override
public int escapeTime(RetryPolicyContext context) {
return RetryUtil.DEFAULT_ESCAPE_TIME;
}
public static StatusCodeCondition create(Set statusCodesToRetryOn) {
return new StatusCodeCondition(statusCodesToRetryOn);
}
public static StatusCodeCondition create(Integer... statusCodesToRetryOn) {
return new StatusCodeCondition(new HashSet(Arrays.asList(statusCodesToRetryOn)));
}
}