Show / Hide Table of Contents

Namespace MingweiSamuel.Camille.Util

Classes

CircularBufferTokenBucket

A circular buffer keeps track of tokens. The value of each buffer index represents the number of requests sent during that time period and as time passes, old indices are zeroed and the current index advances.The entire length of the buffer minus one represents a entire timespan (each index represents a fraction of the total timespan). The extra index prevents violations due to bucket misalignment.A rolling total is kept of the buffer's contents.

When trying to obtain a token, we first check the rolling total is less than the limit.If so, we obtain a token by incrementing the rolling total and incrementing the buffer's current index.

The length of the buffer is one more than the temporal factor supplied to the constructor. The temporal factor represents the multiplicative increase in temporal resolution provided with more buffer indices.

Additionally, a non-zero spreading factor can be provided to prevent a single index from supplying all of a timespan's tokens. A spreading factor of 0.0 means no spreading, a factor of 0.5 means each index can supply up to half of the tokens, and a factor of 1.0 means tokens will be evenly supplied by all indices (provided there is enough demand).

Checking the availability of tokens is done using the {@link #getDelay()} method. Tokens are obtained using the {@link #getToken()} method. Both these methods are synchronized on the bucket instance. Because the state of the bucket may change if there are multiple threads, it is best to call these methods in a synchronized block, as shown below.

ITokenBucket bucket = ...;
while (true)
{
    long delay;
    synchronized(bucket) {
        delay = bucket.getDelay();
        if (delay == -1)
        {
            bucket.GetTokens(1);
            break;
        }
    }
    // Waiting is done outside of the synchronized block.
    Thread.sleep(delay);
}
// Token is obtained.
...

RateLimit

RateLimitTypeInfo

RateLimitUtils

RegionalRequester

Manages rate limits for a particular region and sends requests. Retries retryable responses (429, 5xx). Processes non-retryable responses (200, 404, 4xx).

RequestManager

For sending rate-limited requests to the Riot API.

Manages splitting up regions and limiting concurrent connections.

RiotResponseException

TokenBucketUtils

Structs

SynchronizationContextRemover

Interfaces

IRateLimit

ITokenBucket

This interface defines a token bucket system. One instance represents one recurring bucket with a certain limit of tokens per timespan.

Enums

RateLimitType

Delegates

TokenBucketFactory

Back to top Generated by DocFX