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

com.microsoft.azure.storage.RetryInfo Maven / Gradle / Ivy

There is a newer version: 8.6.6
Show newest version
/**
 * Copyright Microsoft Corporation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.microsoft.azure.storage;

import com.microsoft.azure.storage.core.Utility;

/**
 * Represents the context for a retry of a request made against the storage services.
 */
public class RetryInfo {

    /**
     * The location that the next retry should target.
     */
    private StorageLocation targetLocation;

    /**
     * The location mode for subsequent retries.
     */
    private LocationMode updatedLocationMode;

    /**
     * The interval in milliseconds until the next retry. The minimum back-off interval is 3 seconds.
     */
    private int retryInterval = 3000;

    /**
     * Initializes a new instance of the {@link RetryInfo} class.
     */
    public RetryInfo() {
        this.targetLocation = StorageLocation.PRIMARY;
        this.updatedLocationMode = LocationMode.PRIMARY_ONLY;
    }

    /**
     * Initializes a new instance of the {@link "RetryInfo"} class.
     * 
     * @param retryContext
     *            The {@link RetryContext} object that was passed in to the retry policy.
     */
    public RetryInfo(RetryContext retryContext) {
        Utility.assertNotNull("retryContext", retryContext);
        this.targetLocation = retryContext.getNextLocation();
        this.updatedLocationMode = retryContext.getLocationMode();
    }

    /**
     * Gets the interval in milliseconds until the next retry. The minimum back-off interval is 3 seconds.
     * 
     * @return An int which represents the retry interval (in milliseconds).
     */
    public int getRetryInterval() {
        return this.retryInterval;
    }

    /**
     * Gets the location that the next retry should target.
     * 
     * @return A {@link StorageLocation} object which represents the location for the next retry.
     */
    public final StorageLocation getTargetLocation() {
        return this.targetLocation;
    }

    /**
     * Gets the location mode for subsequent retries.
     * 
     * @return A {@link LocationMode} object which represents the location mode for subsequent retries.
     */
    public LocationMode getUpdatedLocationMode() {
        return this.updatedLocationMode;
    }

    /**
     * Sets the interval in milliseconds until the next retry. The minimum back-off interval is 3 seconds.
     * 
     * @param retryInterval
     *        An int which represents the retry interval to set.
     */
    public void setRetryInterval(int retryInterval) {
        this.retryInterval = (retryInterval > 0 ? retryInterval : 0);
    }

    /**
     * Sets the location that the next retry should target.
     * 
     * @param targetLocation
     *        A {@link StorageLocation} object which represents the location to set.
     */
    public void setTargetLocation(StorageLocation targetLocation) {
        this.targetLocation = targetLocation;
    }

    /**
     * Sets the location mode for subsequent retries.
     * 
     * @param updatedLocationMode
     *        A {@link LocationMode} object which represents the the location mode to set.
     */
    public void setUpdatedLocationMode(LocationMode updatedLocationMode) {
        this.updatedLocationMode = updatedLocationMode;
    }

    /**
     * Returns a string that represents the current {@link "RetryInfo"} instance.
     * 
     * @return A String which represents the current RetryInfo instance.
     */
    @Override
    public String toString() {
        return String.format(Utility.LOCALE_US, "(%s,%s)", this.targetLocation, this.retryInterval);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy