#Enum and instances question

1 messages ยท Page 1 of 1 (latest)

rancid dune
#

I'm building an application that uses the Riot Games API. My single API key has rate-limits for each subdomain. I plan on using this enum class. Would it work if i attached a Bucket to that enum instance to hold tokens for each request, or does Enum instances get reset or something similar by garbage collector for example? Or would it be better to have another class with a HashMap with the enum as key, and bucket as value?
I wrote the question and read my code an extra time, and realized multiple enums would share the "regionUrl" endpoint, which further complicates how i would do this and it leaves me a but clueless.
Any help and wisdom is appreciated ๐Ÿ™‚
Heres my code:

public enum LeagueOfLegendsEndpoint {

    EUN1("europe"), EUW1("europe"), TR1("europe"), RU("europe"),
    
    BR1("americas"), LA1("americas"), LA2("americas"), NA1("americas"),

    JP1("asia"), KR("asia"),

    OC1("sea"), PH2("sea"), SG2("sea"), TH2("sea"), TW2("sea"), VN2("sea");

    @Getter private final String serverUrl;
    @Getter private final String regionUrl;

    LeagueOfLegendsEndpoint(String region) {
        this.serverUrl = name().toLowerCase() + ".api.riotgames.com";
        this.regionUrl = region + ".api.riotgames.com";
    }

}```
rich violetBOT
#

<@&987246399047479336> please have a look, thanks.

rich violetBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

the rate limits as properties to each enum instance?

Yes, it would work if you attach the rate limits as properties to each enum instance. You can define the enum class with the necessary properties and then set the rate limits for each enum instance accordingly.

Here's an example of how you can implement it:

public enum Subdomain {
    SUBDOMAIN1(100), // Rate limit for subdomain 1
    SUBDOMAIN2(200), // Rate limit for subdomain 2
    SUBDOMAIN3(300); // Rate limit for subdomain 3

    private int rateLimit;

    Subdomain(int rateLimit) {
        this.rateLimit = rateLimit;
    }

    public int getRateLimit() {
        return rateLimit;
    }
}

In your application, you can access the rate limit for a specific subdomain like this:

Subdomain subdomain = Subdomain.SUBDOMAIN1;
int rateLimit = subdomain.getRateLimit();
System.out.println("Rate limit for " + subdomain.name() + ": " + rateLimit);

This will output: "Rate limit for SUBDOMAIN1: 100".

By attaching the rate limits as properties to each enum instance, you can easily retrieve and use them in your application.

rancid dune
#

As per usual, it seems the bot misinterpreted my question ๐Ÿ™‚ I should perhaps mention i use Bucket4J as ratelimiter/bucket

wheat inlet
#

@rancid dune it would be safe to attach the buckets directly to the enum

#

I would still probably use an EnumMap of enum to bucket

rancid dune
smoky pewter
rancid dune
smoky pewter
rancid dune
#

Ah oki, thanks ๐Ÿ™‚