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

com.azure.cosmos.implementation.RequestChargeTracker 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.60.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.implementation;

import java.util.concurrent.atomic.AtomicLong;

/**
 * Tracks requests charge in the Azure Cosmos DB database service.
 */
public final class RequestChargeTracker {
    private final static int NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR = 1000;
    private final AtomicLong totalRUs = new AtomicLong();

    public double getTotalRequestCharge() {
        return ((double) this.totalRUs.get()) / NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR;
    }

    public void addCharge(double ruUsage) {
        this.totalRUs.addAndGet((long) (ruUsage * NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR));
    }

    public double getAndResetCharge() {
        return (double) this.totalRUs.getAndSet(0) / NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy