public class WebhookClientBuilder
extends java.lang.Object
WebhookClient
instanceModifier and Type | Class | Description |
---|---|---|
class |
WebhookClientBuilder.DefaultWebhookThreadFactory |
Modifier and Type | Field | Description |
---|---|---|
static okhttp3.OkHttpClient.Builder |
DEFAULT_HTTP_BUILDER |
Constructor | Description |
---|---|
WebhookClientBuilder(long id,
java.lang.String token) |
Creates a new WebhookClientBuilder with the provided id and token
|
WebhookClientBuilder(java.lang.String url) |
Creates a new WebhookClientBuilder with the provided webhook URL
|
WebhookClientBuilder(Webhook webhook) |
Creates a new WebhookClientBuilder with the provided id and token
|
Modifier and Type | Method | Description |
---|---|---|
WebhookClient |
build() |
Builds a new
WebhookClient instance
with the current state of this builder. |
WebhookClientBuilder |
setDaemon(boolean isDaemon) |
Whether rate limit threads of the created
WebhookClient
should be treated as Thread.isDaemon() or not. |
WebhookClientBuilder |
setExecutorService(java.util.concurrent.ScheduledExecutorService executorService) |
The
ScheduledExecutorService
that should be used to handle rate limits!
By default this creates a new executor with 1 core thread! |
WebhookClientBuilder |
setHttpClient(okhttp3.OkHttpClient client) |
The
OkHttpClient
that should be used to make HTTP requests! |
WebhookClientBuilder |
setHttpClientBuilder(okhttp3.OkHttpClient.Builder builder) |
The
OkHttpClient.Builder
that should be used to create the OkHttpClient of the resulting WebhookClient !
If not set or null this builder will use the DEFAULT_HTTP_BUILDER instance. |
WebhookClientBuilder |
setThreadFactory(java.util.concurrent.ThreadFactory factory) |
Factory that should be used by the default
ScheduledExecutorService
to create Threads for rate limitation handling of the created WebhookClient !
This allows changing thread information such as name without having to create your own executor. |
public static final okhttp3.OkHttpClient.Builder DEFAULT_HTTP_BUILDER
public WebhookClientBuilder(long id, java.lang.String token)
id
- The snowflake id of the target webhooktoken
- The authorization token of the target webhook
java.lang.IllegalArgumentException
- If the provided token is null
or contains any whitespace!public WebhookClientBuilder(@Nonnull java.lang.String url)
url
- The URL of the webhook. May be directly copied from Discord's UI
https://discordapp.com/api/webhooks/123456789012345678/my-webhook-token
discordapp.com
java.lang.IllegalArgumentException
- If the provided URL is null
or is incorrectly formattedpublic WebhookClientBuilder setExecutorService(@Nullable java.util.concurrent.ScheduledExecutorService executorService)
ScheduledExecutorService
that should be used to handle rate limits!
Closing the WebhookClient
will close this
executor service!
executorService
- The executor service that should be usedpublic WebhookClientBuilder setHttpClient(@Nullable okhttp3.OkHttpClient client)
OkHttpClient
that should be used to make HTTP requests!
Setting this will skip the setHttpClientBuilder(OkHttpClient.Builder)
setting and directly use the provided client!
client
- The client that should be usedpublic WebhookClientBuilder setHttpClientBuilder(@Nullable okhttp3.OkHttpClient.Builder builder)
OkHttpClient.Builder
that should be used to create the OkHttpClient
of the resulting WebhookClient
!
null
this builder will use the DEFAULT_HTTP_BUILDER
instance.
This setting is ignored if setHttpClient(okhttp3.OkHttpClient)
is set!
builder
- The builder that should be usedpublic WebhookClientBuilder setThreadFactory(@Nullable java.util.concurrent.ThreadFactory factory)
ScheduledExecutorService
to create Threads for rate limitation handling of the created WebhookClient
!
factory
- The ThreadFactory
that will
be used when no ScheduledExecutorService
has been set via setExecutorService(ScheduledExecutorService)
public WebhookClientBuilder setDaemon(boolean isDaemon)
WebhookClient
should be treated as Thread.isDaemon()
or not.
This will not be used when the default thread pool has been set via setExecutorService(ScheduledExecutorService)
!
isDaemon
- True, if the threads should be daemonpublic WebhookClient build()
WebhookClient
instance
with the current state of this builder.
Remember to close the WebhookClient once you don't need it anymore to free resources!