Enum Class TwitchLimitRegistry

java.lang.Object
java.lang.Enum<TwitchLimitRegistry>
com.github.twitch4j.common.util.TwitchLimitRegistry
All Implemented Interfaces:
Serializable, Comparable<TwitchLimitRegistry>, Constable

public enum TwitchLimitRegistry extends Enum<TwitchLimitRegistry>
This singleton facilitates sharing of key rate-limit buckets by user and limit type.

For example:

 TwitchLimitRegistry.getInstance().setLimit(
         "149223493",
         TwitchLimitType.CHAT_MESSAGE_LIMIT,
         Collections.singletonList(TwitchChatLimitHelper.MOD_MESSAGE_LIMIT)
     );
 
 
  • Enum Constant Details

    • INSTANCE

      public static final TwitchLimitRegistry INSTANCE
      The single thread-safe instance of the limit registry.
  • Method Details

    • values

      public static TwitchLimitRegistry[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TwitchLimitRegistry valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • setLimit

      public void setLimit(@NonNull @NonNull String userId, @NonNull @NonNull TwitchLimitType limitType, @NonNull @NonNull List<io.github.bucket4j.Bandwidth> limit)
      Attempts to set a user's bucket for a specific rate-limit.
      Parameters:
      userId - the id of the user whose rate limit is being specified.
      limitType - the type of rate-limit that is being configured.
      limit - the bandwidths that are applicable for this user and rate limit type.
    • invalidateLimitsByUserId

      public boolean invalidateLimitsByUserId(String userId)
      Invalidates the registered rate limits for this id.
      Parameters:
      userId - the id of the user or channel whose registered limits can be cleared from memory
      Returns:
      whether the user had registered limits that were cleared
    • invalidateLimit

      public boolean invalidateLimit(String userId, TwitchLimitType limitType)
      Invalidates a specific rate limit type that was registered for a specific user/channel id.
      Parameters:
      userId - the id of the user or channel whose registered limit should be cleared from memory
      limitType - the type of rate limit that should be cleared
      Returns:
      whether the user a registered limit of the specified type that could be cleared
    • getBucket

      @NonNull public @NonNull Optional<io.github.bucket4j.Bucket> getBucket(@NonNull @NonNull String userId, @NonNull @NonNull TwitchLimitType limitType)
      Obtains the Bucket for a user and rate limit type, if it has been registered.
      Parameters:
      userId - the id of the user whose rate limit bucket is being requested.
      limitType - the type of rate limit that is being queried.
      Returns:
      the shared rate limit bucket for this user and limit type, in an optional wrapper
    • getOrInitializeBucket

      @NonNull public @NonNull io.github.bucket4j.Bucket getOrInitializeBucket(@NonNull @NonNull String userId, @NonNull @NonNull TwitchLimitType limitType, @NonNull @NonNull List<io.github.bucket4j.Bandwidth> limit)
      Obtains or creates the Bucket for a certain user and rate limit type.
      Parameters:
      userId - the id of the user in question.
      limitType - the type of rate limit in question.
      limit - the default bandwidth settings for this user and rate limit type.
      Returns:
      the shared rate limit bucket for this user and limit type
    • getInstance

      @NonNull public static @NonNull TwitchLimitRegistry getInstance()
      Returns:
      the single thread-safe instance of the limit registry.