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

com.azure.cosmos.implementation.ShouldRetryResult Maven / Gradle / Ivy

Go to download

This Package contains Microsoft Azure Cosmos SDK (with Reactive Extension Reactor support) for Azure Cosmos DB SQL API

There is a newer version: 4.61.1
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.implementation;

import java.time.Duration;

public class ShouldRetryResult {
    public final static ShouldRetryResult NO_RETRY =
        ShouldRetryResult.noRetry();
    public final static ShouldRetryResult RETRY_NOW =
        ShouldRetryResult.retryAfter(Duration.ZERO);

    /// 
    /// How long to wait before next retry. 0 indicates retry immediately.
    /// 
    public final Duration backOffTime;
    public final Exception exception;
    public final Quadruple policyArg;
    public boolean shouldRetry;
    public boolean nonRelatedException;

    private ShouldRetryResult(Duration dur, Exception e, boolean shouldRetry,
                              Quadruple policyArg, boolean nonRelatedException) {
        this.backOffTime = dur;
        this.exception = e;
        this.shouldRetry = shouldRetry;
        this.policyArg = policyArg;
        this.nonRelatedException = nonRelatedException;
    }

    public static ShouldRetryResult error(Exception e) {
        Utils.checkNotNullOrThrow(e, "exception", "cannot be null");
        return new ShouldRetryResult(null, e, false, null, false);
    }

    public static ShouldRetryResult noRetry() {
        return new ShouldRetryResult(null, null, false, null, false);
    }

    public static ShouldRetryResult noRetryOnNonRelatedException() {
        return new ShouldRetryResult(null, null, false, null, true);
    }

    public static ShouldRetryResult noRetry(Quadruple policyArg) {
        return new ShouldRetryResult(
            null,
            null,
            false,
            policyArg,
            false);
    }

    public static ShouldRetryResult retryAfter(Duration dur,
                                               Quadruple policyArg) {
        Utils.checkNotNullOrThrow(dur, "duration", "cannot be null");
        return new ShouldRetryResult(dur, null, true, policyArg, false);
    }

    public static ShouldRetryResult retryAfter(Duration dur) {
        Utils.checkNotNullOrThrow(dur, "duration", "cannot be null");
        return new ShouldRetryResult(dur, null, true, null, false);
    }

    public void throwIfDoneTrying(Exception capturedException) throws Exception {
        if (this.shouldRetry) {
            return;
        }

        if (this.exception == null) {
            throw capturedException;
        } else {
            throw this.exception;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy