All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyuncs.policy.retry.conditions.StatusCodeCondition Maven / Gradle / Ivy

Go to download

Aliyun Open API SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 4.7.1
Show newest version
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)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy