Package com.github.twitch4j.common.util
Enum Class TwitchLimitRegistry
- All Implemented Interfaces:
Serializable
,Comparable<TwitchLimitRegistry>
,Constable
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)
);
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescription@NonNull Optional<io.github.bucket4j.Bucket>
getBucket
(@NonNull String userId, @NonNull TwitchLimitType limitType) Obtains theBucket
for a user and rate limit type, if it has been registered.static @NonNull TwitchLimitRegistry
@NonNull io.github.bucket4j.Bucket
getOrInitializeBucket
(@NonNull String userId, @NonNull TwitchLimitType limitType, @NonNull List<io.github.bucket4j.Bandwidth> limit) Obtains or creates theBucket
for a certain user and rate limit type.boolean
invalidateLimit
(String userId, TwitchLimitType limitType) Invalidates a specific rate limit type that was registered for a specific user/channel id.boolean
invalidateLimitsByUserId
(String userId) Invalidates the registered rate limits for this id.void
setLimit
(@NonNull String userId, @NonNull TwitchLimitType limitType, @NonNull List<io.github.bucket4j.Bandwidth> limit) Attempts to set a user's bucket for a specific rate-limit.static TwitchLimitRegistry
Returns the enum constant of this class with the specified name.static TwitchLimitRegistry[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
INSTANCE
The single thread-safe instance of the limit registry.
-
-
Method Details
-
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
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 nameNullPointerException
- 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
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
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 memorylimitType
- 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 theBucket
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 theBucket
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
- Returns:
- the single thread-safe instance of the limit registry.
-