本文整理匯總了Java中com.google.common.util.concurrent.RateLimiter.getRate方法的典型用法代碼示例。如果您正苦於以下問題:Java RateLimiter.getRate方法的具體用法?Java RateLimiter.getRate怎麽用?Java RateLimiter.getRate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.util.concurrent.RateLimiter
的用法示例。
在下文中一共展示了RateLimiter.getRate方法的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;
}
示例2: create
import com.google.common.util.concurrent.RateLimiter; //導入方法依賴的package包/類
public static IFace create(double maxRequestsPerSecond) {
if (maxRequestsPerSecond <= 0.0) {
return ALLOW_NONE;
}
final RateLimiter rateLimiter = RateLimiter.create(maxRequestsPerSecond);
return new IFace() {
@Override
public boolean allowDequeue(int numJobs) {
return rateLimiter.tryAcquire(numJobs);
}
@Override
public double getRate() {
return rateLimiter.getRate();
}
};
}
示例3: 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;
}
示例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");
}
}
示例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);
}