Example usage for com.google.common.util.concurrent RateLimiter setRate

List of usage examples for com.google.common.util.concurrent RateLimiter setRate

Introduction

In this page you can find the example usage for com.google.common.util.concurrent RateLimiter setRate.

Prototype

public final void setRate(double permitsPerSecond) 

Source Link

Document

Updates the stable rate of this RateLimiter , that is, the permitsPerSecond argument provided in the factory method that constructed the RateLimiter .

Usage

From source file:com.liferay.sync.engine.session.rate.limiter.RateLimiterManager.java

protected static void updateRateLimits(List<RateLimiter> rateLimiters, int globalMaxRateLimit,
        int maxRateLimit) {

    int rate = 0;

    if ((globalMaxRateLimit == 0) && (maxRateLimit == 0)) {
        rate = Integer.MAX_VALUE;
    } else if (globalMaxRateLimit == 0) {
        rate = maxRateLimit;/*from  ww w.  ja v  a2  s. c  om*/
    } else if (maxRateLimit == 0) {
        rate = globalMaxRateLimit;
    } else {
        rate = Math.min(globalMaxRateLimit, maxRateLimit);
    }

    for (RateLimiter rateLimiter : rateLimiters) {
        rateLimiter.setRate(rate);
    }
}

From source file:com.spotify.styx.StyxScheduler.java

private static void updateRuntimeConfig(Storage storage, RateLimiter rateLimiter) {
    try {/*w w  w.  ja  v a 2 s.com*/
        double currentRate = rateLimiter.getRate();
        Double updatedRate = storage.submissionRateLimit()
                .orElse(StyxScheduler.DEFAULT_SUBMISSION_RATE_PER_SEC);
        if (Double.compare(updatedRate, currentRate) != 0) {
            LOG.info("Updating submission rate limit: {} -> {}", currentRate, updatedRate);
            rateLimiter.setRate(updatedRate);
        }
    } catch (IOException e) {
        LOG.warn("Failed to fetch the submission rate config from storage, " + "skipping RateLimiter update");
    }
}