Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more configurations for JDABuilder #705

Merged
merged 21 commits into from
Aug 3, 2018

Conversation

MinnDevelopment
Copy link
Member

@MinnDevelopment MinnDevelopment commented Jul 5, 2018

Pull Request Etiquette

There are several guidelines you should follow in order for your
Pull Request to be merged.

It is sometimes better to include more changes in a single commit.
If you find yourself having an overwhelming amount of commits, you
can rebase your branch.

Description

This will add a few more options to configure JDA.

Also added an option to set the okhttp client used by JDA to allow using
a single okhttp client for all JDA sessions

Additionally I also fixed the documentation in a few locations
@MinnDevelopment MinnDevelopment changed the title Add option for setting the core pool size for rate-limit handling Add more configurations for JDABuilder Jul 5, 2018
Also ensure the token in DefaultShardManager is only validated once
}

userResponse = checkToken(login);
requester.shutdownNow();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should call JDA#shutdownNow here

@@ -535,7 +560,7 @@ public DefaultShardManagerBuilder setIdleProvider(final IntFunction<Boolean> idl
* @throws IllegalArgumentException
* if the provided OnlineStatus is null or {@link net.dv8tion.jda.core.OnlineStatus#UNKNOWN UNKNOWN}
*
* @return The {@link net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder DefaultShardManagerBuilder} instance. Useful for chaining.
* @return @return The DefaultShardManagerBuilder instance. Useful for chaining.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@MinnDevelopment MinnDevelopment added the status: completed has been completed but is not yet released label Jul 8, 2018
@MinnDevelopment MinnDevelopment mentioned this pull request Jul 21, 2018
2 tasks
@MinnDevelopment

This comment has been minimized.

buildAsync -> build()
buildBlocking -> build().awaitReady()
Now the methods accepting threadpools additionally accept
an optional boolean to enable/disable automatic shutdown

Additionally I added generic bounds to the providers (where needed)
@MinnDevelopment
Copy link
Member Author

Example usage:

JDABuilder builder = new JDABuilder(AccountType.BOT).setToken(BOT_TOKEN);
builder.setCorePoolSize(1);
builder.setCallbackPool(new ForkJoinPool(), true);
builder.addEventListener(new CommandHandler());
JDA api = builder.build();
api.awaitStatus(JDA.Status.AWAITING_LOGIN_CONFIRMATION);
log.info("Shard has started setting up");

Copy link
Collaborator

@kantenkugel kantenkugel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some renaming / improvements i would make. Nothing major

README.md Outdated
## Creating the JDA Object
Creating the JDA Object is done via the JDABuilder class by providing an AccountType (Bot/Client).
After setting the token via setter,
the JDA Object is then created by calling the `.buildBlocking()` or the `.buildAsync()` (non-blocking login) method.
the JDA Object is then created by calling the `.build()` (non-blocking login) method.
When `build()` returns JDA might not have finished starting up, however you can use `awaitReady()`
Copy link
Collaborator

@kantenkugel kantenkugel Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might change punctuation to "When build() returns**,** JDA might not have finished starting up**.** However**,** ..."


**Example**:

```java
JDA jda = new JDABuilder(AccountType.BOT).setToken("token").buildBlocking();
JDA jda = new JDABuilder(AccountType.BOT).setToken("token").build();

This comment was marked as resolved.

README.md Outdated
@@ -67,7 +79,7 @@ public class MessageListener extends ListenerAdapter
public static void main(String[] args)
throws LoginException, RateLimitedException, InterruptedException
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i understand correctly, build() on its own will not throw an InterruptedException anymore, right?

{
T provide(int shardId);

default boolean isAutomaticShutdown(int shardId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add javadocs here, and possibly rename to shouldShutdownAutomatically cuz isAutomaticShutdown sounds like JDA asks the ThreadPoolProvider if the pool already shuts down automatically rather than asking if JDA should shut it down

*/
@Deprecated
public JDA buildBlocking(JDA.Status status) throws LoginException, InterruptedException
{
Checks.notNull(status, "Status");
Checks.check(status.isInit(), "Cannot await the status %s as it is not part of the login cycle!", status);
JDA jda = buildAsync();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would use build() here instead of buildAsync(). The checks are also not needed anymore, as they are present in jda#awaitStatus()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are needed because we don't want to build if they fail

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right... makes sense

*/
@Deprecated
public JDA buildBlocking() throws LoginException, InterruptedException
{
return buildBlocking(Status.CONNECTED);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe switch to build().awaitReady()? Its not important here tho

@MinnDevelopment MinnDevelopment merged commit 4cc724e into development Aug 3, 2018
@MinnDevelopment MinnDevelopment deleted the feature/configurations branch August 29, 2018 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: completed has been completed but is not yet released type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants