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

com.azure.cosmos.implementation.RetryContext 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 com.fasterxml.jackson.annotation.JsonIgnore;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RetryContext {
    @JsonIgnore
    private volatile Instant retryStartTime;
    @JsonIgnore
    private volatile Instant retryEndTime;

    private List statusAndSubStatusCodes;

    public void addStatusAndSubStatusCode(int statusCode, int subStatusCode) {
        if (statusAndSubStatusCodes == null) {
            statusAndSubStatusCodes = Collections.synchronizedList(new ArrayList<>());
        }
        int[] statusAndSubStatusCode = {statusCode, subStatusCode};
        statusAndSubStatusCodes.add(statusAndSubStatusCode);
    }

    public List getStatusAndSubStatusCodes() {
        return statusAndSubStatusCodes;
    }

    public int getRetryCount() {
        if (this.statusAndSubStatusCodes != null) {
            return this.statusAndSubStatusCodes.size();
        }

        return 0;
    }

    public long getRetryLatency() {
        if (this.retryStartTime != null && this.retryEndTime != null && this.statusAndSubStatusCodes != null) {
            return Duration.between(this.retryStartTime, this.retryEndTime).toMillis();
        } else {
            return 0;
        }
    }

    public void updateEndTime() {
        this.retryEndTime = Instant.now();
    }

    public void captureStartTimeIfNotSet() {
        if (this.retryStartTime == null) {
            this.retryStartTime = Instant.now();
        }
    }

    public Instant getRetryStartTime() {
        return retryStartTime;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy