Guava RateLimiter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava RateLimiter class.

This code example shows how to use the following methods:acquire, tryAcquire
 
	/** 
	 * initializes the request rate limiter upon first block request in rotation.  
	 */ 
	private void init() { 
		boolean acquired = this.throttler.tryAcquire();
		if (acquired) {
			this.throttler.acquire();
		} 
	} 
	 
	/** 
	 *  
	 * @return true if blocking was preformed. 
	 */ 
	public boolean block() { 
		incrementRetryCounter(); 
		if (isInitRequired()) { 
			init(); 
		} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:tryAcquire
 
		long globalCount = golbalCounter.incrementAndGet();
		localCounter++;
 
		// print global progress, 所有線程裡只有一個会在10秒內打印一次。 
		if (golbalPrintRate.tryAcquire()) {
			System.out.printf("Total pop %,d jobs, tps is %,d%n", globalCount,
					(globalCount - golbalPreviousCount.get()) / PRINT_BETWEEN_SECONDS);
			golbalPreviousCount.set(globalCount);
		} 
 
		// print current thread progress,10秒內打印一次。 
		if (localPrintRate.tryAcquire()) {
			System.out.printf("Local thread pop %,d jobs, tps is %,d%n", localCounter,
					(localCounter - localPreviousCount) / PRINT_BETWEEN_SECONDS);
			localPreviousCount = localCounter;
		} 
	} 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:acquire
        this.limiter = limiter;
    } 
 
    protected void reBuffer() 
    { 
        limiter.acquire(buffer.capacity());
        super.reBuffer(); 
    } 
 
    public static ThrottledReader open(File file, RateLimiter limiter)
    { 
        try 
        { 
            return new ThrottledReader(file, limiter);
        } 
        catch (FileNotFoundException e)
        { 
            throw new RuntimeException(e);
        } 
    } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:acquire
        this.limiter = limiter;
    } 
 
    protected void reBuffer() 
    { 
        limiter.acquire(buffer.capacity());
        super.reBuffer(); 
    } 
 
    public static CompressedThrottledReader open(String file, CompressionMetadata metadata, RateLimiter limiter)
    { 
        try 
        { 
            return new CompressedThrottledReader(file, metadata, limiter);
        } 
        catch (FileNotFoundException e)
        { 
            throw new RuntimeException(e);
        } 
    } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:acquire
    public Throttle(long maxRatePerSecond) {
        this.rateLimiter = RateLimiter.create(maxRatePerSecond);
    } 
 
    public void consume(int usage) {
        rateLimiter.acquire(usage);
    } 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:acquire, tryAcquire
    } 
 
    @Override 
    public T execute(RestRequest request) throws NetworkException {
        if (enforceRatelimit) {
            if (!rateLimiter.tryAcquire()) {
                double time = rateLimiter.acquire();
                if (requestLogging) {
                    JrawUtils.logger().info("Slept for {} seconds", time);
                    JrawUtils.logger().info(""); 
                } 
            } 
        } 
 
        Request r = request.getRequest();
        try { 
            if (requestLogging)
                logger.log(request);
 
            Response response = http.newCall(r).execute();
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:acquire
        // creating it here makes things simple. 
        mRateLimiter = RateLimiter.create(config.getMessagesPerSecond());
    } 
 
    public static void acquire() { 
        mRateLimiter.acquire();
    } 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:tryAcquire
    private void checkLimit() { 
		if (limiter == null) {
			return; 
		} 
		 
		if (!limiter.tryAcquire()) {
			throw new Api.RateLimitExceeded("Cloud rate limit exceeded"); 
		} 
	} 
 
	/** 
	 * Saves the {@code message} to the cloud 
	 * @return true on success 
	 */ 
	public <T> boolean save(String id, Class<T> klass,T message) {
		String scopedId = scopeId(klass.getSimpleName(),id);
		StringResponse response = put(scopedId,DynamicMessageUtil.toJson(klass, message));
		if (response.getStatus() == 204) {
			return true; 
		} else { 
2
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Guava RateLimiter Methods: