TokenBucket class

Пакет: com.hypixel.hytale.lib.quiche

Файл: com/hypixel/hytale/lib/quiche/TokenBucket.java

Поля (3)

МодификаторыТипИмя
final int maxTokens
long var3
long var5

Методы (4)

МодификаторыВозвратСигнатура
if if(var3 > 0L)
if if(var5 > 0L)
if if(this.tokens <= 0)
boolean tryConsumeboolean tryConsume(long var1)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.lib.quiche;

class="kw">final class TokenBucket {
   class="kw">private class="kw">final int maxTokens;
   class="kw">private class="kw">final int tokensPerSecond;
   class="kw">private int tokens;
   class="kw">private long lastRefillNs;

   TokenBucket(int var1, int var2, long var3) {
      this.maxTokens = var1;
      this.tokensPerSecond = var2;
      this.tokens = var1;
      this.lastRefillNs = var3;
   }

   boolean tryConsume(long var1) {
      long var3 = var1 - this.lastRefillNs;
      if (var3 > 0L) {
         long var5 = var3 * this.tokensPerSecond / 1000000000L;
         if (var5 > 0L) {
            this.tokens = (int)Math.min(this.maxTokens, this.tokens + var5);
            this.lastRefillNs = this.lastRefillNs + var5 * 1000000000L / this.tokensPerSecond;
         }
      }

      if (this.tokens <= 0) {
         class="kw">return false;
      }

      this.tokens--;
      class="kw">return true;
   }
}