Class DefaultShardManagerBuilder
- java.lang.Object
-
- net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder
-
public class DefaultShardManagerBuilder extends Object
Used to create new instances of JDA's defaultShardManagerimplementation.A single DefaultShardManagerBuilder can be reused multiple times. Each call to
build()creates a newShardManagerinstance using the same information.- Since:
- 3.4
- Author:
- Aljoscha Grebe
-
-
Constructor Summary
Constructors Constructor Description DefaultShardManagerBuilder()Creates a completely empty DefaultShardManagerBuilder.DefaultShardManagerBuilder(String token)Creates a DefaultShardManagerBuilder with the given token.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DefaultShardManagerBuilderaddEventListenerProvider(IntFunction<Object> listenerProvider)Adds the provided listener provider to the list of listener providers that will be used to create listeners.DefaultShardManagerBuilderaddEventListenerProviders(Collection<IntFunction<Object>> listenerProviders)Adds the provided listener providers to the list of listener providers that will be used to create listeners.DefaultShardManagerBuilderaddEventListeners(Object... listeners)Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManagerobject.DefaultShardManagerBuilderaddEventListeners(Collection<Object> listeners)Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManagerobject.ShardManagerbuild()Builds a newShardManagerinstance and uses the provided token to start the login process.DefaultShardManagerBuilderremoveEventListenerProvider(IntFunction<Object> listenerProvider)Removes the provided listener provider from the list of listener providers.DefaultShardManagerBuilderremoveEventListenerProviders(Collection<IntFunction<Object>> listenerProviders)Removes all provided listener providers from the list of listener providers.DefaultShardManagerBuilderremoveEventListeners(Object... listeners)Removes all provided listeners from the list of listeners.DefaultShardManagerBuilderremoveEventListeners(Collection<Object> listeners)Removes all provided listeners from the list of listeners.DefaultShardManagerBuildersetActivity(Activity game)Sets theActivityfor our session.DefaultShardManagerBuildersetActivityProvider(IntFunction<? extends Activity> gameProvider)Sets theActivityfor our session.DefaultShardManagerBuildersetAudioSendFactory(IAudioSendFactory factory)Changes the factory used to createIAudioSendSystemobjects which handle the sending loop for audio packets.DefaultShardManagerBuildersetAutoReconnect(boolean autoReconnect)Sets whether or not JDA should try to reconnect if a connection-error is encountered.DefaultShardManagerBuildersetBulkDeleteSplittingEnabled(boolean enabled)If enabled, JDA will separate the bulk delete event into individual delete events, but this isn't as efficient as handling a single event would be.DefaultShardManagerBuildersetCallbackPool(ExecutorService executor)Sets theExecutorServicethat should be used in the JDA callback handler which mostly consists ofRestActioncallbacks.DefaultShardManagerBuildersetCallbackPool(ExecutorService executor, boolean automaticShutdown)Sets theExecutorServicethat should be used in the JDA callback handler which mostly consists ofRestActioncallbacks.DefaultShardManagerBuildersetCallbackPoolProvider(ThreadPoolProvider<? extends ExecutorService> provider)Sets theExecutorServicethat should be used in the JDA callback handler which mostly consists ofRestActioncallbacks.DefaultShardManagerBuildersetCompression(Compression compression)Sets the compression algorithm used with the gateway connection, this will decrease the amount of used bandwidth for the running bot instance for the cost of a few extra cycles for decompression.DefaultShardManagerBuildersetContextEnabled(boolean enable)Whether JDA should use a synchronized MDC context for all of its controlled threads.DefaultShardManagerBuildersetContextMap(IntFunction<? extends ConcurrentMap<String,String>> provider)Sets theMDCmappings provider to use in JDA.DefaultShardManagerBuildersetDisabledCacheFlags(EnumSet<CacheFlag> flags)Flags used to disable parts of the JDA cache to reduce the runtime memory footprint.DefaultShardManagerBuildersetEnabledCacheFlags(EnumSet<CacheFlag> flags)Flags used to enable parts of the JDA cache to reduce the runtime memory footprint.DefaultShardManagerBuildersetEnableShutdownHook(boolean enable)Enables/Disables the use of a Shutdown hook to clean up the ShardManager and it's JDA instances.DefaultShardManagerBuildersetEventManager(IEventManager manager)Deprecated.UsesetEventManagerProvider(IntFunction)insteadDefaultShardManagerBuildersetEventManagerProvider(IntFunction<? extends IEventManager> eventManagerProvider)Sets a provider to change the internally used EventManager.DefaultShardManagerBuildersetGatewayPool(ScheduledExecutorService pool)Sets theScheduledExecutorServicethat should be used for the JDA main WebSocket workers.DefaultShardManagerBuildersetGatewayPool(ScheduledExecutorService pool, boolean automaticShutdown)Sets theScheduledExecutorServicethat should be used for the JDA main WebSocket workers.DefaultShardManagerBuildersetGatewayPoolProvider(ThreadPoolProvider<? extends ScheduledExecutorService> provider)Sets theScheduledExecutorServicethat should be used for the JDA main WebSocket workers.DefaultShardManagerBuildersetHttpClient(OkHttpClient client)Sets theOkHttpClientthat will be used by JDAs requester.DefaultShardManagerBuildersetHttpClientBuilder(OkHttpClient.Builder builder)Sets theBuilderthat will be used by JDA's requester.DefaultShardManagerBuildersetIdle(boolean idle)Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean).DefaultShardManagerBuildersetIdleProvider(IntFunction<Boolean> idleProvider)Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean).DefaultShardManagerBuildersetMaxReconnectDelay(int maxReconnectDelay)Sets the maximum amount of time that JDA will back off to wait when attempting to reconnect the MainWebsocket.DefaultShardManagerBuildersetRateLimitPool(ScheduledExecutorService pool)Sets theScheduledExecutorServicethat should be used in the JDA rate-limit handler.DefaultShardManagerBuildersetRateLimitPool(ScheduledExecutorService pool, boolean automaticShutdown)Sets theScheduledExecutorServicethat should be used in the JDA rate-limit handler.DefaultShardManagerBuildersetRateLimitPoolProvider(ThreadPoolProvider<? extends ScheduledExecutorService> provider)Sets theScheduledExecutorServiceprovider that should be used in the JDA rate-limit handler.DefaultShardManagerBuildersetRawEventsEnabled(boolean enable)Whether JDA should fireRawGatewayEventfor every discord event.DefaultShardManagerBuildersetRequestTimeoutRetry(boolean retryOnTimeout)Whether the Requester should retry when aSocketTimeoutExceptionoccurs.DefaultShardManagerBuildersetSessionController(SessionController controller)Sets theSessionControllerfor the resulting ShardManager instance.DefaultShardManagerBuildersetShards(int... shardIds)Sets the list of shards theDefaultShardManagershould contain.DefaultShardManagerBuildersetShards(int minShardId, int maxShardId)Sets the range of shards theDefaultShardManagershould contain.DefaultShardManagerBuildersetShards(Collection<Integer> shardIds)Sets the range of shards theDefaultShardManagershould contain.DefaultShardManagerBuildersetShardsTotal(int shardsTotal)This will set the total amount of shards theDefaultShardManagershould use.DefaultShardManagerBuildersetStatus(OnlineStatus status)Sets theOnlineStatusour connection will display.DefaultShardManagerBuildersetStatusProvider(IntFunction<OnlineStatus> statusProvider)Sets theOnlineStatusour connection will display.DefaultShardManagerBuildersetThreadFactory(ThreadFactory threadFactory)Sets theThreadFactorythat will be used by the internal executor of the ShardManager.DefaultShardManagerBuildersetToken(String token)Sets the token that will be used by theShardManagerinstance to log in whenbuild()is called.DefaultShardManagerBuildersetUseShutdownNow(boolean useShutdownNow)Whether theShardManagershould useJDA#shutdownNow()instead ofJDA#shutdown()to shutdown it's shards.DefaultShardManagerBuildersetVoiceDispatchInterceptor(VoiceDispatchInterceptor interceptor)Configures a custom voice dispatch handler which handles audio connections.DefaultShardManagerBuildersetWebsocketFactory(WebSocketFactory factory)Sets theWebSocketFactorythat will be used by JDA's websocket client.
-
-
-
Constructor Detail
-
DefaultShardManagerBuilder
public DefaultShardManagerBuilder()
Creates a completely empty DefaultShardManagerBuilder.
You need to set the token usingsetToken(String)before callingbuild().
-
DefaultShardManagerBuilder
public DefaultShardManagerBuilder(@Nonnull String token)
Creates a DefaultShardManagerBuilder with the given token.
This is equivalent to using the constuctorDefaultShardManagerBuilder()and callingsetToken(String)directly afterward. You can always change the token later withsetToken(String).- Parameters:
token- The login token
-
-
Method Detail
-
setRawEventsEnabled
@Nonnull public DefaultShardManagerBuilder setRawEventsEnabled(boolean enable)
- Parameters:
enable- True, if JDA should fireRawGatewayEvent.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
-
setEnabledCacheFlags
@Nonnull public DefaultShardManagerBuilder setEnabledCacheFlags(@Nullable EnumSet<CacheFlag> flags)
Flags used to enable parts of the JDA cache to reduce the runtime memory footprint.
It is highly recommended to usesetDisabledCacheFlags(EnumSet)instead for backwards compatibility. We might add more flags in the future which you then effectively disable when updating and not changing your setting here.- Parameters:
flags- EnumSet containing the flags for cache services that should be enabled- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setDisabledCacheFlags
@Nonnull public DefaultShardManagerBuilder setDisabledCacheFlags(@Nullable EnumSet<CacheFlag> flags)
Flags used to disable parts of the JDA cache to reduce the runtime memory footprint.
Shortcut forsetEnabledCacheFlags(EnumSet.complementOf(flags))- Parameters:
flags- EnumSet containing the flags for cache services that should be disabled- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setSessionController
@Nonnull public DefaultShardManagerBuilder setSessionController(@Nullable SessionController controller)
Sets theSessionControllerfor the resulting ShardManager instance. This can be used to sync behaviour and state between shards of a bot and should be one and the same instance on all builders for the shards.- Parameters:
controller- TheSessionControllerto use- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
SessionControllerAdapter
-
setVoiceDispatchInterceptor
@Nonnull public DefaultShardManagerBuilder setVoiceDispatchInterceptor(@Nullable VoiceDispatchInterceptor interceptor)
Configures a custom voice dispatch handler which handles audio connections.- Parameters:
interceptor- The new voice dispatch handler, or null to use the default- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
- See Also:
VoiceDispatchInterceptor
-
setContextMap
@Nonnull public DefaultShardManagerBuilder setContextMap(@Nullable IntFunction<? extends ConcurrentMap<String,String>> provider)
Sets theMDCmappings provider to use in JDA.
If sharding is enabled JDA will automatically add ajda.shardcontext with the format[SHARD_ID / TOTAL]whereSHARD_IDandTOTALare the shard configuration. Additionally it will provide context for the id viajda.shard.idand the total viajda.shard.total.The manager will call this with a shardId and it is recommended to provide a different context map for each shard!
This automatically switchessetContextEnabled(boolean)to true if the provided function is not null!- Parameters:
provider- The provider for modifiable context maps to use in JDA, ornullto reset- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
- MDC Javadoc
-
setContextEnabled
@Nonnull public DefaultShardManagerBuilder setContextEnabled(boolean enable)
Whether JDA should use a synchronized MDC context for all of its controlled threads.
Default:true- Parameters:
enable- True, if JDA should provide an MDC context map- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
- MDC Javadoc,
setContextMap(java.util.function.IntFunction)
-
setCompression
@Nonnull public DefaultShardManagerBuilder setCompression(@Nonnull Compression compression)
Sets the compression algorithm used with the gateway connection, this will decrease the amount of used bandwidth for the running bot instance for the cost of a few extra cycles for decompression. Compression can be entirely disabled by setting this toCompression.NONE.
Default:Compression.ZLIBWe recommend to keep this on the default unless you have issues with the decompression
This mode might become obligatory in a future version, do not rely on this switch to stay.- Parameters:
compression- The compression algorithm to use for the gateway connection- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- If provided with null- See Also:
- Official Discord Documentation - Transport Compression
-
addEventListeners
@Nonnull public DefaultShardManagerBuilder addEventListeners(@Nonnull Object... listeners)
Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManagerobject.
This uses theInterfacedEventListenerby default.
To switch to theAnnotatedEventManager, usesetEventManagerProvider(id -> new AnnotatedEventManager()).Note: When using the
InterfacedEventListener(default), given listener(s) must be instance ofEventListener!- Parameters:
listeners- The listener(s) to add to the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
JDA.addEventListeners(Object...)
-
addEventListeners
@Nonnull public DefaultShardManagerBuilder addEventListeners(@Nonnull Collection<Object> listeners)
Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManagerobject.
This uses theInterfacedEventListenerby default.
To switch to theAnnotatedEventManager, usesetEventManager(id -> new AnnotatedEventManager()).Note: When using the
InterfacedEventListener(default), given listener(s) must be instance ofEventListener!- Parameters:
listeners- The listener(s) to add to the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
JDA.addEventListeners(Object...)
-
removeEventListeners
@Nonnull public DefaultShardManagerBuilder removeEventListeners(@Nonnull Object... listeners)
Removes all provided listeners from the list of listeners.- Parameters:
listeners- The listener(s) to remove from the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
JDA.removeEventListeners(Object...)
-
removeEventListeners
@Nonnull public DefaultShardManagerBuilder removeEventListeners(@Nonnull Collection<Object> listeners)
Removes all provided listeners from the list of listeners.- Parameters:
listeners- The listener(s) to remove from the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
JDA.removeEventListeners(Object...)
-
addEventListenerProvider
@Nonnull public DefaultShardManagerBuilder addEventListenerProvider(@Nonnull IntFunction<Object> listenerProvider)
Adds the provided listener provider to the list of listener providers that will be used to create listeners. On shard creation (including shard restarts) the provider will have the shard id applied and must return a listener, which will be used, along all other listeners, to populate the listeners of the JDA object of that shard.
This uses theInterfacedEventListenerby default.
To switch to theAnnotatedEventManager, usesetEventManager(id -> new AnnotatedEventManager()).Note: When using the
InterfacedEventListener(default), given listener(s) must be instance ofEventListener!- Parameters:
listenerProvider- The listener provider to add to the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
addEventListenerProviders
@Nonnull public DefaultShardManagerBuilder addEventListenerProviders(@Nonnull Collection<IntFunction<Object>> listenerProviders)
Adds the provided listener providers to the list of listener providers that will be used to create listeners. On shard creation (including shard restarts) each provider will have the shard id applied and must return a listener, which will be used, along all other listeners, to populate the listeners of the JDA object of that shard.
This uses theInterfacedEventListenerby default.
To switch to theAnnotatedEventManager, usesetEventManager(id -> new AnnotatedEventManager()).Note: When using the
InterfacedEventListener(default), given listener(s) must be instance ofEventListener!- Parameters:
listenerProviders- The listener provider to add to the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
removeEventListenerProvider
@Nonnull public DefaultShardManagerBuilder removeEventListenerProvider(@Nonnull IntFunction<Object> listenerProvider)
Removes the provided listener provider from the list of listener providers.- Parameters:
listenerProvider- The listener provider to remove from the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
removeEventListenerProviders
@Nonnull public DefaultShardManagerBuilder removeEventListenerProviders(@Nonnull Collection<IntFunction<Object>> listenerProviders)
Removes all provided listener providers from the list of listener providers.- Parameters:
listenerProviders- The listener provider(s) to remove from the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setAudioSendFactory
@Nonnull public DefaultShardManagerBuilder setAudioSendFactory(@Nullable IAudioSendFactory factory)
Changes the factory used to createIAudioSendSystemobjects which handle the sending loop for audio packets.
By default, JDA usesDefaultSendFactory.- Parameters:
factory- The newIAudioSendFactoryto be used when creating newIAudioSendSystemobjects.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setAutoReconnect
@Nonnull public DefaultShardManagerBuilder setAutoReconnect(boolean autoReconnect)
Sets whether or not JDA should try to reconnect if a connection-error is encountered.
This will use an incremental reconnect (timeouts are increased each time an attempt fails). Default: true (enabled)- Parameters:
autoReconnect- If true - enables autoReconnect- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setBulkDeleteSplittingEnabled
@Nonnull public DefaultShardManagerBuilder setBulkDeleteSplittingEnabled(boolean enabled)
If enabled, JDA will separate the bulk delete event into individual delete events, but this isn't as efficient as handling a single event would be. It is recommended that BulkDelete Splitting be disabled and that the developer should instead handle theMessageBulkDeleteEvent.Default: true (enabled)
- Parameters:
enabled- True - The MESSAGE_DELETE_BULK will be split into multiple individual MessageDeleteEvents.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEnableShutdownHook
@Nonnull public DefaultShardManagerBuilder setEnableShutdownHook(boolean enable)
Enables/Disables the use of a Shutdown hook to clean up the ShardManager and it's JDA instances.
When the Java program closes shutdown hooks are run. This is used as a last-second cleanup attempt by JDA to properly close connections.Default: true (enabled)
- Parameters:
enable- True (default) - use shutdown hook to clean up the ShardManager and it's JDA instances if the Java program is closed.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEventManager
@Nonnull @Deprecated @DeprecatedSince("3.8.1") @ReplaceWith("setEventManagerProvider((id) -> manager)") public DefaultShardManagerBuilder setEventManager(@Nonnull IEventManager manager)
Deprecated.UsesetEventManagerProvider(IntFunction)insteadChanges the internally used EventManager.
There are 2 provided Implementations:InterfacedEventManagerwhich uses the InterfaceEventListener(tip: use theListenerAdapter).
This is the default EventManager.AnnotatedEventManagerwhich uses the Annotation@SubscribeEventto mark the methods that listen for events.
You can also create your own EventManager (SeeIEventManager).- Parameters:
manager- The newIEventManagerto use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEventManagerProvider
@Nonnull public DefaultShardManagerBuilder setEventManagerProvider(@Nonnull IntFunction<? extends IEventManager> eventManagerProvider)
Sets a provider to change the internally used EventManager.
There are 2 provided Implementations:InterfacedEventManagerwhich uses the InterfaceEventListener(tip: use theListenerAdapter).
This is the default EventManager.AnnotatedEventManagerwhich uses the Annotation@SubscribeEventto mark the methods that listen for events.
You can also create your own EventManager (SeeIEventManager).- Parameters:
eventManagerProvider- A supplier for the newIEventManagerto use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setActivity
@Nonnull public DefaultShardManagerBuilder setActivity(@Nullable Activity game)
Sets theActivityfor our session.
This value can be changed at any time in thePresencefrom a JDA instance.Hint: You can create a
Activityobject usingActivity.playing(String)orActivity.streaming(String, String)Activity.streaming(String, String)}.- Parameters:
game- An instance ofActivity(null allowed)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
Presence.setActivity(net.dv8tion.jda.api.entities.Activity)
-
setActivityProvider
@Nonnull public DefaultShardManagerBuilder setActivityProvider(@Nullable IntFunction<? extends Activity> gameProvider)
Sets theActivityfor our session.
This value can be changed at any time in thePresencefrom a JDA instance.Hint: You can create a
Activityobject usingActivity.playing(String)orActivity.streaming(String, String).- Parameters:
gameProvider- An instance ofActivity(null allowed)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
Presence.setActivity(net.dv8tion.jda.api.entities.Activity)
-
setIdle
@Nonnull public DefaultShardManagerBuilder setIdle(boolean idle)
Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean).- Parameters:
idle- boolean value that will be provided with our IDENTIFY packages to mark our sessions as afk or not. (default false)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
Presence.setIdle(boolean)
-
setIdleProvider
@Nonnull public DefaultShardManagerBuilder setIdleProvider(@Nullable IntFunction<Boolean> idleProvider)
Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean).- Parameters:
idleProvider- boolean value that will be provided with our IDENTIFY packages to mark our sessions as afk or not. (default false)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
Presence.setIdle(boolean)
-
setStatus
@Nonnull public DefaultShardManagerBuilder setStatus(@Nullable OnlineStatus status)
Sets theOnlineStatusour connection will display.
This value can be changed at any time in thePresencefrom a JDA instance.Note:This will not take affect for
AccountType.CLIENTif the statusProvider specified in the user_settings is not "online" as it is overriding our identify statusProvider.- Parameters:
status- Not-null OnlineStatus (default online)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- if the provided OnlineStatus is null orUNKNOWN- See Also:
Presence.setStatusProvider(OnlineStatus)
-
setStatusProvider
@Nonnull public DefaultShardManagerBuilder setStatusProvider(@Nullable IntFunction<OnlineStatus> statusProvider)
Sets theOnlineStatusour connection will display.
This value can be changed at any time in thePresencefrom a JDA instance.Note:This will not take affect for
AccountType.CLIENTif the statusProvider specified in the user_settings is not "online" as it is overriding our identify statusProvider.- Parameters:
statusProvider- Not-null OnlineStatus (default online)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- if the provided OnlineStatus is null orUNKNOWN- See Also:
Presence.setStatusProvider(OnlineStatus)
-
setThreadFactory
@Nonnull public DefaultShardManagerBuilder setThreadFactory(@Nullable ThreadFactory threadFactory)
Sets theThreadFactorythat will be used by the internal executor of the ShardManager.Note: This will not affect Threads created by any JDA instance.
- Parameters:
threadFactory- The ThreadFactory ornullto reset to the default value.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setHttpClientBuilder
@Nonnull public DefaultShardManagerBuilder setHttpClientBuilder(@Nullable OkHttpClient.Builder builder)
Sets theBuilderthat will be used by JDA's requester. This can be used to set things such as connection timeout and proxy.- Parameters:
builder- The newOkHttpClient.Builderto use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setHttpClient
@Nonnull public DefaultShardManagerBuilder setHttpClient(@Nullable OkHttpClient client)
Sets theOkHttpClientthat will be used by JDAs requester.
This can be used to set things such as connection timeout and proxy.- Parameters:
client- The newOkHttpClientto use- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitPool
@Nonnull public DefaultShardManagerBuilder setRateLimitPool(@Nullable ScheduledExecutorService pool)
Sets theScheduledExecutorServicethat should be used in the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.
This will override the rate-limit pool provider set fromsetRateLimitPoolProvider(ThreadPoolProvider).
This automatically disables the automatic shutdown of the rate-limit pool, you can enable it usingsetRateLimiPool(executor, true)This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. Besides that it is also used by planned execution for
RestAction.queueAfter(long, TimeUnit)and similar methods.Default:
ScheduledThreadPoolExecutorwith 5 threads (per shard).- Parameters:
pool- The thread-pool to use for rate-limit handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitPool
@Nonnull public DefaultShardManagerBuilder setRateLimitPool(@Nullable ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorServicethat should be used in the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.
This will override the rate-limit pool provider set fromsetRateLimitPoolProvider(ThreadPoolProvider).This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. Besides that it is also used by planned execution for
RestAction.queueAfter(long, TimeUnit)and similar methods.Default:
ScheduledThreadPoolExecutorwith 5 threads (per shard).- Parameters:
pool- The thread-pool to use for rate-limit handlingautomaticShutdown- WhetherJDA.shutdown()should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitPoolProvider
@Nonnull public DefaultShardManagerBuilder setRateLimitPoolProvider(@Nullable ThreadPoolProvider<? extends ScheduledExecutorService> provider)
Sets theScheduledExecutorServiceprovider that should be used in the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. Besides that it is also used by planned execution for
RestAction.queueAfter(long, TimeUnit)and similar methods.Default:
ScheduledThreadPoolExecutorwith 5 threads (per shard).- Parameters:
provider- The thread-pool provider to use for rate-limit handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public DefaultShardManagerBuilder setGatewayPool(@Nullable ScheduledExecutorService pool)
Sets theScheduledExecutorServicethat should be used for the JDA main WebSocket workers.
Only change this pool if you know what you're doing.
This will override the worker pool provider set fromsetGatewayPoolProvider(ThreadPoolProvider).
This automatically disables the automatic shutdown of the main-ws pools, you can enable it usingsetGatewayPoolProvider(pool, true)This is used to send various forms of session updates such as:
- Voice States - (Dis-)Connecting from channels
- Presence - Changing current activity or online status
- Guild Setup - Requesting Members of newly joined guilds
- Heartbeats - Regular updates to keep the connection alive (usually once a minute)
Default:
ScheduledThreadPoolExecutorwith 1 thread (per shard)- Parameters:
pool- The thread-pool to use for main WebSocket workers- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public DefaultShardManagerBuilder setGatewayPool(@Nullable ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorServicethat should be used for the JDA main WebSocket workers.
Only change this pool if you know what you're doing.
This will override the worker pool provider set fromsetGatewayPoolProvider(ThreadPoolProvider).This is used to send various forms of session updates such as:
- Voice States - (Dis-)Connecting from channels
- Presence - Changing current activity or online status
- Guild Setup - Requesting Members of newly joined guilds
- Heartbeats - Regular updates to keep the connection alive (usually once a minute)
Default:
ScheduledThreadPoolExecutorwith 1 thread (per shard)- Parameters:
pool- The thread-pool to use for main WebSocket workersautomaticShutdown- WhetherJDA.shutdown()should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPoolProvider
@Nonnull public DefaultShardManagerBuilder setGatewayPoolProvider(@Nullable ThreadPoolProvider<? extends ScheduledExecutorService> provider)
Sets theScheduledExecutorServicethat should be used for the JDA main WebSocket workers.
Only change this pool if you know what you're doing.This is used to send various forms of session updates such as:
- Voice States - (Dis-)Connecting from channels
- Presence - Changing current activity or online status
- Guild Setup - Requesting Members of newly joined guilds
- Heartbeats - Regular updates to keep the connection alive (usually once a minute)
Default:
ScheduledThreadPoolExecutorwith 1 thread (per shard)- Parameters:
provider- The thread-pool provider to use for main WebSocket workers- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPool
@Nonnull public DefaultShardManagerBuilder setCallbackPool(@Nullable ExecutorService executor)
Sets theExecutorServicethat should be used in the JDA callback handler which mostly consists ofRestActioncallbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.
This automatically disables the automatic shutdown of the callback pools, you can enable it usingsetCallbackPool(executor, true)This is used to handle callbacks of
RestAction.queue(), similarly it is used to finishRestAction.submit()andRestAction.complete()tasks which build on queue.Default:
ForkJoinPool.commonPool()- Parameters:
executor- The thread-pool to use for callback handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPool
@Nonnull public DefaultShardManagerBuilder setCallbackPool(@Nullable ExecutorService executor, boolean automaticShutdown)
Sets theExecutorServicethat should be used in the JDA callback handler which mostly consists ofRestActioncallbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.This is used to handle callbacks of
RestAction.queue(), similarly it is used to finishRestAction.submit()andRestAction.complete()tasks which build on queue.Default:
ForkJoinPool.commonPool()- Parameters:
executor- The thread-pool to use for callback handlingautomaticShutdown- WhetherJDA.shutdown()should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPoolProvider
@Nonnull public DefaultShardManagerBuilder setCallbackPoolProvider(@Nullable ThreadPoolProvider<? extends ExecutorService> provider)
Sets theExecutorServicethat should be used in the JDA callback handler which mostly consists ofRestActioncallbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.This is used to handle callbacks of
RestAction.queue(), similarly it is used to finishRestAction.submit()andRestAction.complete()tasks which build on queue.Default:
ForkJoinPool.commonPool()- Parameters:
provider- The thread-pool provider to use for callback handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setMaxReconnectDelay
@Nonnull public DefaultShardManagerBuilder setMaxReconnectDelay(int maxReconnectDelay)
Sets the maximum amount of time that JDA will back off to wait when attempting to reconnect the MainWebsocket.
Provided value must be 32 or greater.- Parameters:
maxReconnectDelay- The maximum amount of time that JDA will wait between reconnect attempts in seconds.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- Thrown if the providedmaxReconnectDelayis less than 32.
-
setRequestTimeoutRetry
@Nonnull public DefaultShardManagerBuilder setRequestTimeoutRetry(boolean retryOnTimeout)
Whether the Requester should retry when aSocketTimeoutExceptionoccurs.
Default:trueThis value can be changed at any time with
JDA.setRequestTimeoutRetry(boolean)!- Parameters:
retryOnTimeout- True, if the Request should retry once on a socket timeout- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setShards
@Nonnull public DefaultShardManagerBuilder setShards(int... shardIds)
Sets the list of shards theDefaultShardManagershould contain.This does not have any effect if the total shard count is set to
-1(get recommended shards from discord).- Parameters:
shardIds- The list of shard ids- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setShards
@Nonnull public DefaultShardManagerBuilder setShards(int minShardId, int maxShardId)
Sets the range of shards theDefaultShardManagershould contain. This is useful if you want to split your shards between multiple JVMs or servers.This does not have any effect if the total shard count is set to
-1(get recommended shards from discord).- Parameters:
minShardId- The lowest shard id the DefaultShardManager should containmaxShardId- The highest shard id the DefaultShardManager should contain- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- If either minShardId is negative, maxShardId is lower than shardsTotal or minShardId is lower than or equal to maxShardId
-
setShards
@Nonnull public DefaultShardManagerBuilder setShards(@Nonnull Collection<Integer> shardIds)
Sets the range of shards theDefaultShardManagershould contain. This is useful if you want to split your shards between multiple JVMs or servers.This does not have any effect if the total shard count is set to
-1(get recommended shards from discord).- Parameters:
shardIds- The list of shard ids- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- If either minShardId is negative, maxShardId is lower than shardsTotal or minShardId is lower than or equal to maxShardId
-
setShardsTotal
@Nonnull public DefaultShardManagerBuilder setShardsTotal(int shardsTotal)
This will set the total amount of shards theDefaultShardManagershould use.If this is set to
-1JDA will automatically retrieve the recommended amount of shards from discord (default behavior).- Parameters:
shardsTotal- The number of overall shards or-1if JDA should use the recommended amount from discord.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
setShards(int, int)
-
setToken
@Nonnull public DefaultShardManagerBuilder setToken(@Nonnull String token)
Sets the token that will be used by theShardManagerinstance to log in whenbuild()is called.To get a bot token:
- Go to your Discord Applications
- Create or select an already existing application
- Verify that it has already been turned into a Bot. If you see the "Create a Bot User" button, click it.
- Click the click to reveal link beside the Token label to show your Bot's
token
- Parameters:
token- The token of the account that you would like to login with.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException- If the token is either null or empty
-
setUseShutdownNow
@Nonnull public DefaultShardManagerBuilder setUseShutdownNow(boolean useShutdownNow)
Whether theShardManagershould useJDA#shutdownNow()instead ofJDA#shutdown()to shutdown it's shards.
Default:false- Parameters:
useShutdownNow- Whether the ShardManager should use JDA#shutdown() or not- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
JDA.shutdown(),JDA.shutdownNow()
-
setWebsocketFactory
@Nonnull public DefaultShardManagerBuilder setWebsocketFactory(@Nullable WebSocketFactory factory)
Sets theWebSocketFactorythat will be used by JDA's websocket client. This can be used to set things such as connection timeout and proxy.- Parameters:
factory- The newWebSocketFactoryto use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
build
@Nonnull public ShardManager build() throws LoginException, IllegalArgumentException
Builds a newShardManagerinstance and uses the provided token to start the login process.
The login process runs in a different thread, so while this will return immediately,ShardManagerhas not finished loading, thus manyShardManagermethods have the chance to return incorrect information.
The main use of this method is to start the JDA connect process and do other things in parallel while startup is being performed like database connection or local resource loading.Note that this method is async and as such will not block until all shards are started.
- Returns:
- A
ShardManagerinstance that has started the login process. It is unknown as to whether or not loading has finished when this returns. - Throws:
LoginException- If the provided token is invalid.IllegalArgumentException- If the provided token is empty or null.
-
-