Class RatelimitBucket



  • public class RatelimitBucket
    extends Object
    • Constructor Detail

      • RatelimitBucket

        public RatelimitBucket​(DiscordApi api,
                               RestEndpoint endpoint)
        Creates a RatelimitBucket for the given endpoint / parameter combination.
        Parameters:
        api - The api/shard to use.
        endpoint - The REST endpoint the ratelimit is tracked for.
      • RatelimitBucket

        public RatelimitBucket​(DiscordApi api,
                               RestEndpoint endpoint,
                               String majorUrlParameter)
        Creates a RatelimitBucket for the given endpoint / parameter combination.
        Parameters:
        api - The api/shard to use.
        endpoint - The REST endpoint the ratelimit is tracked for.
        majorUrlParameter - The url parameter this bucket is specific for. May be null.
    • Method Detail

      • setGlobalRatelimitResetTimestamp

        public static void setGlobalRatelimitResetTimestamp​(DiscordApi api,
                                                            long resetTimestamp)
        Sets a global ratelimit.
        Parameters:
        api - A discord api instance.
        resetTimestamp - The reset timestamp of the global ratelimit.
      • addRequestToQueue

        public void addRequestToQueue​(RestRequest<?> request)
        Adds the given request to the bucket's queue.
        Parameters:
        request - The request to add.
      • pollRequestFromQueue

        public RestRequest<?> pollRequestFromQueue​()
        Polls a request from the bucket's queue.
        Returns:
        The polled request.
      • peekRequestFromQueue

        public RestRequest<?> peekRequestFromQueue​()
        Peeks a request from the bucket's queue.
        Returns:
        The peeked request.
      • setRatelimitRemaining

        public void setRatelimitRemaining​(int ratelimitRemaining)
        Sets the remaining requests till ratelimit.
        Parameters:
        ratelimitRemaining - The remaining requests till ratelimit.
      • setRatelimitResetTimestamp

        public void setRatelimitResetTimestamp​(long ratelimitResetTimestamp)
        Sets the ratelimit reset timestamp.
        Parameters:
        ratelimitResetTimestamp - The ratelimit reset timestamp.
      • getTimeTillSpaceGetsAvailable

        public int getTimeTillSpaceGetsAvailable​()
        Gets the time in seconds how long you have to wait till there's space in the bucket again.
        Returns:
        The time in seconds how long you have to wait till there's space in the bucket again.
      • equals

        public boolean equals​(RestEndpoint endpoint,
                              String majorUrlParameter)
        Checks if a bucket created with the given parameters would equal this bucket.
        Parameters:
        endpoint - The endpoint.
        majorUrlParameter - The major url parameter.
        Returns:
        Whether a bucket created with the given parameters would equal this bucket or not.
      • hashCode

        public int hashCode​()
        Overrides:
        hashCode in class Object