當前位置: 首頁>>代碼示例>>Java>>正文


Java RateLimiter.setRate方法代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.RateLimiter.setRate方法的典型用法代碼示例。如果您正苦於以下問題:Java RateLimiter.setRate方法的具體用法?Java RateLimiter.setRate怎麽用?Java RateLimiter.setRate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.util.concurrent.RateLimiter的用法示例。


在下文中一共展示了RateLimiter.setRate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initRateLimiter

import com.google.common.util.concurrent.RateLimiter; //導入方法依賴的package包/類
public RateLimiter initRateLimiter(String target, double rate) {
    RateLimiter limiter = requestRateLimiterMap.get(target);
    if (limiter == null) {
        limiter = RateLimiter.create(rate);
        requestRateLimiterMap.put(target, limiter);
        return limiter;
    }

    if (limiter.getRate() == rate) {
        return limiter;
    }

    limiter.setRate(rate);
    requestRateLimiterMap.put(target, limiter);

    return limiter;
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:18,代碼來源:LimitationManager.java

示例2: getRateLimiter

import com.google.common.util.concurrent.RateLimiter; //導入方法依賴的package包/類
/**
 * 獲取限速器
 *
 * @param restyCommand
 * @return limiter
 */
private RateLimiter getRateLimiter(RestyCommand restyCommand) {
    String key = restyCommand.getServiceMethod() + "@" + restyCommand.getPath();
    RateLimiter rateLimiter = limiterMap.get(key);
    if (rateLimiter == null) {
        limiterMap.putIfAbsent(key, RateLimiter.create(restyCommand.getRestyCommandConfig().getLimit()));
        rateLimiter = limiterMap.get(key);
    } else if (rateLimiter.getRate() != restyCommand.getRestyCommandConfig().getLimit()) {
        // 更新rate
        rateLimiter.setRate(restyCommand.getRestyCommandConfig().getLimit());
    }
    return rateLimiter;
}
 
開發者ID:darren-fu,項目名稱:RestyPass,代碼行數:19,代碼來源:TrafficLimitFilter.java

示例3: freshNetRate

import com.google.common.util.concurrent.RateLimiter; //導入方法依賴的package包/類
public void freshNetRate(int rate) {
    int downRate = rate - Constants.SYSTEM_NEED_RATE;
    if (downRate <= 0) {
        downRate = rate / 2;
    }
    if (downRate == 0) {
        logger.error("net rate:{} is illegal", rate);
        return;
    }
    long rateOnByte = downRate * 1024L * 1024L;
    boolean updated = false;
    try {
        for (RateLimiter rateLimiter : rateLimiters) {
            if (Math.abs(rateLimiter.getRate() - rateOnByte) >= 1024) {
                rateLimiter.setRate(rateOnByte);
                updated = true;
            }
        }
        if (updated) {
            logger.info("update net rate to {} MB", rate);
        }
    } catch (Exception e) {
        logger.error("E_freshNetRate", e);
    }
}
 
開發者ID:alibaba,項目名稱:Dragonfly,代碼行數:26,代碼來源:NetConfigNotification.java

示例4: updateRuntimeConfig

import com.google.common.util.concurrent.RateLimiter; //導入方法依賴的package包/類
private static void updateRuntimeConfig(Supplier<StyxConfig> config, RateLimiter rateLimiter) {
  try {
    double currentRate = rateLimiter.getRate();
    Double updatedRate = config.get().submissionRateLimit().orElse(
        StyxScheduler.DEFAULT_SUBMISSION_RATE_PER_SEC);
    if (Math.abs(updatedRate - currentRate) >= 0.1) {
      LOG.info("Updating submission rate limit: {} -> {}", currentRate, updatedRate);
      rateLimiter.setRate(updatedRate);
    }
  } catch (Exception e) {
    LOG.warn("Failed to fetch the submission rate config from storage, "
        + "skipping RateLimiter update");
  }
}
 
開發者ID:spotify,項目名稱:styx,代碼行數:15,代碼來源:StyxScheduler.java

示例5: mayUpdateThroughput

import com.google.common.util.concurrent.RateLimiter; //導入方法依賴的package包/類
private void mayUpdateThroughput(double limit, RateLimiter rateLimiter)
{
    // if throughput is set to 0, throttling is disabled
    if (limit == 0)
        limit = Double.MAX_VALUE;
    if (rateLimiter.getRate() != limit)
        rateLimiter.setRate(limit);
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:9,代碼來源:StreamManager.java


注:本文中的com.google.common.util.concurrent.RateLimiter.setRate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。