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

com.azure.cosmos.implementation.throughputControl.controller.request.GlobalThroughputRequestController 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.throughputControl.controller.request;

import com.azure.cosmos.implementation.RxDocumentServiceRequest;
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
import com.azure.cosmos.implementation.throughputControl.ThroughputRequestThrottler;
import reactor.core.publisher.Mono;

import java.util.concurrent.atomic.AtomicReference;

public class GlobalThroughputRequestController implements IThroughputRequestController {
    private final AtomicReference scheduledThroughput;
    private final ThroughputRequestThrottler requestThrottler;

    public GlobalThroughputRequestController(double initialScheduledThroughput) {
        this.scheduledThroughput = new AtomicReference<>(initialScheduledThroughput);
        this.requestThrottler = new ThroughputRequestThrottler(this.scheduledThroughput.get(), StringUtils.EMPTY);
    }

    @Override
    @SuppressWarnings("unchecked")
    public  Mono init() {
        return Mono.just((T)requestThrottler);
    }

    @Override
    public boolean canHandleRequest(RxDocumentServiceRequest request) {
        return true;
    }

    @Override
    public  Mono processRequest(RxDocumentServiceRequest request, Mono originalRequestMono) {
        return this.requestThrottler.processRequest(request, originalRequestMono);
    }

    @Override
    public double renewThroughputUsageCycle(double throughput) {
        this.scheduledThroughput.set(throughput);
        return this.requestThrottler.renewThroughputUsageCycle(throughput);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy