Class DefaultShardManager
- All Implemented Interfaces:
IGuildChannelContainer<Channel>
,ShardManager
ShardManager
implementation.
To create new instances use the DefaultShardManagerBuilder
.- Since:
- 3.4
- Author:
- Aljoscha Grebe
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultShardManager
(String token) DefaultShardManager
(String token, Collection<Integer> shardIds) DefaultShardManager
(String token, Collection<Integer> shardIds, net.dv8tion.jda.internal.utils.config.sharding.ShardingConfig shardingConfig, net.dv8tion.jda.internal.utils.config.sharding.EventConfig eventConfig, net.dv8tion.jda.internal.utils.config.sharding.PresenceProviderConfig presenceConfig, net.dv8tion.jda.internal.utils.config.sharding.ThreadingProviderConfig threadingConfig, net.dv8tion.jda.internal.utils.config.sharding.ShardingSessionConfig sessionConfig, net.dv8tion.jda.internal.utils.config.sharding.ShardingMetaConfig metaConfig, IntFunction<? extends RestConfig> restConfigProvider, ChunkingFilter chunkingFilter) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEventListener
(Object... listeners) Adds all provided listeners to the event-listeners that will be used to handle events.void
addEventListeners
(IntFunction<Object> eventListenerProvider) Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events.TheGatewayIntents
for the JDA sessions of this shard manager.getGuildById
(long id) This returns theGuild
which has the same id as the one provided.UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.int
Returns the amount of shards queued for (re)connecting.int
Returns the amount of shards managed by thisShardManager
.void
login()
Initializes and starts all shards.void
removeEventListener
(Object... listeners) Removes all provided listeners from the event-listeners and no longer uses them to handle events.void
removeEventListenerProvider
(IntFunction<Object> eventListenerProvider) Remove a listener provider.void
restart()
Restarts all shards, shutting old ones down first.void
restart
(int shardId) Restarts the shards with the given id only.void
setActivityProvider
(IntFunction<? extends Activity> activityProvider) Sets provider that provider theActivity
for all shards.void
setIdleProvider
(IntFunction<Boolean> idleProvider) Sets the provider that decides for all shards whether they should be marked as afk or not.void
setPresenceProvider
(IntFunction<OnlineStatus> statusProvider, IntFunction<? extends Activity> activityProvider) Sets the provider that provides theOnlineStatus
andActivity
for all shards.void
setStatusProvider
(IntFunction<OnlineStatus> statusProvider) Sets the provider that provides theOnlineStatus
for all shards.void
shutdown()
Shuts down all JDA shards, closing all their connections.void
shutdown
(int shardId) Shuts down the shard with the given id only.void
start
(int shardId) Adds a new shard with the given id to this ShardManager and starts it.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.entities.channel.attribute.IGuildChannelContainer
getCategories, getCategoriesByName, getCategoryById, getCategoryById, getChannelById, getChannelById, getForumChannelById, getForumChannelById, getForumChannels, getForumChannelsByName, getGuildChannelById, getGuildChannelById, getMediaChannelById, getMediaChannelById, getMediaChannels, getMediaChannelsByName, getNewsChannelById, getNewsChannelById, getNewsChannels, getNewsChannelsByName, getStageChannelById, getStageChannelById, getStageChannels, getStageChannelsByName, getTextChannelById, getTextChannelById, getTextChannels, getTextChannelsByName, getThreadChannelById, getThreadChannelById, getThreadChannels, getThreadChannelsByName, getVoiceChannelById, getVoiceChannelById, getVoiceChannels, getVoiceChannelsByName
Methods inherited from interface net.dv8tion.jda.api.sharding.ShardManager
getAverageGatewayPing, getCategoryCache, getChannelCache, getEmojiById, getEmojiById, getEmojiCache, getEmojis, getEmojisByName, getForumChannelCache, getGuildById, getGuildCache, getGuildChannelById, getGuildChannelById, getGuilds, getGuildsByName, getMediaChannelCache, getMutualGuilds, getMutualGuilds, getNewsChannelCache, getPrivateChannelById, getPrivateChannelById, getPrivateChannelCache, getPrivateChannels, getRoleById, getRoleById, getRoleCache, getRoles, getRolesByName, getShardById, getShardById, getShards, getShardsRunning, getStageChannelCache, getStatus, getStatuses, getTextChannelCache, getThreadChannelCache, getUserById, getUserById, getUserByTag, getUserByTag, getUserCache, getUsers, getVoiceChannelCache, removeEventListeners, retrieveApplicationInfo, retrieveUserById, retrieveUserById, setActivity, setIdle, setPresence, setStatus
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
DEFAULT_THREAD_FACTORY
-
-
Constructor Details
-
DefaultShardManager
-
DefaultShardManager
-
DefaultShardManager
public DefaultShardManager(@Nonnull String token, @Nullable Collection<Integer> shardIds, @Nullable net.dv8tion.jda.internal.utils.config.sharding.ShardingConfig shardingConfig, @Nullable net.dv8tion.jda.internal.utils.config.sharding.EventConfig eventConfig, @Nullable net.dv8tion.jda.internal.utils.config.sharding.PresenceProviderConfig presenceConfig, @Nullable net.dv8tion.jda.internal.utils.config.sharding.ThreadingProviderConfig threadingConfig, @Nullable net.dv8tion.jda.internal.utils.config.sharding.ShardingSessionConfig sessionConfig, @Nullable net.dv8tion.jda.internal.utils.config.sharding.ShardingMetaConfig metaConfig, @Nullable IntFunction<? extends RestConfig> restConfigProvider, @Nullable ChunkingFilter chunkingFilter)
-
-
Method Details
-
getGatewayIntents
Description copied from interface:ShardManager
TheGatewayIntents
for the JDA sessions of this shard manager.- Specified by:
getGatewayIntents
in interfaceShardManager
- Returns:
EnumSet
of active gateway intents
-
addEventListener
Description copied from interface:ShardManager
Adds all provided listeners to the event-listeners that will be used to handle events.Note: when using the
InterfacedEventListener
(default), the given listener must be an instance ofEventListener
!- Specified by:
addEventListener
in interfaceShardManager
- Parameters:
listeners
- The listener(s) which will react to events.
-
removeEventListener
Description copied from interface:ShardManager
Removes all provided listeners from the event-listeners and no longer uses them to handle events.- Specified by:
removeEventListener
in interfaceShardManager
- Parameters:
listeners
- The listener(s) to be removed.
-
addEventListeners
Description copied from interface:ShardManager
Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events. The listener provider gets a shard id applied and is expected to return a listener.Note: when using the
InterfacedEventListener
(default), the given listener must be an instance ofEventListener
!- Specified by:
addEventListeners
in interfaceShardManager
- Parameters:
eventListenerProvider
- The provider of listener(s) which will react to events.
-
removeEventListenerProvider
Description copied from interface:ShardManager
Remove a listener provider. This will stop further created / restarted shards from getting a listener added by that provider.Default is a no-op for backwards compatibility, see implementations like
removeEventListenerProvider(IntFunction)
for actual code- Specified by:
removeEventListenerProvider
in interfaceShardManager
- Parameters:
eventListenerProvider
- The provider of listeners that shall be removed.
-
getShardsQueued
public int getShardsQueued()Description copied from interface:ShardManager
Returns the amount of shards queued for (re)connecting.- Specified by:
getShardsQueued
in interfaceShardManager
- Returns:
- The amount of shards queued for (re)connecting.
-
getShardsTotal
public int getShardsTotal()Description copied from interface:ShardManager
Returns the amount of shards managed by thisShardManager
. This includes shards currently queued for a restart.- Specified by:
getShardsTotal
in interfaceShardManager
- Returns:
- The managed amount of shards.
-
getGuildById
Description copied from interface:ShardManager
This returns theGuild
which has the same id as the one provided.
If there is no connected guild with an id that matches the provided one, this will returnnull
.- Specified by:
getGuildById
in interfaceShardManager
- Parameters:
id
- The id of theGuild
.- Returns:
- Possibly-null
Guild
with matching id.
-
getShardCache
Description copied from interface:ShardManager
UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.- Specified by:
getShardCache
in interfaceShardManager
- Returns:
- Unified
ShardCacheView
-
login
public void login()Description copied from interface:ShardManager
Initializes and starts all shards. This should only be called once.- Specified by:
login
in interfaceShardManager
-
restart
public void restart(int shardId) Description copied from interface:ShardManager
Restarts the shards with the given id only.
If there is no shard with the given Id, this method acts likeShardManager.start(int)
.- Specified by:
restart
in interfaceShardManager
- Parameters:
shardId
- The id of the target shard
-
restart
public void restart()Description copied from interface:ShardManager
Restarts all shards, shutting old ones down first.As all shards need to connect to discord again this will take equally long as the startup of a new ShardManager (using the 5000ms + backoff as delay between starting new JDA instances).
- Specified by:
restart
in interfaceShardManager
-
shutdown
public void shutdown()Description copied from interface:ShardManager
Shuts down all JDA shards, closing all their connections. After this method has been called the ShardManager instance can not be used anymore.
This will shutdown the internal queue worker for (re-)starts of shards. This meansShardManager.restart(int)
,ShardManager.restart()
, andShardManager.start(int)
will throwRejectedExecutionException
.This will interrupt the default JDA event thread, due to the gateway connection being interrupted.
- Specified by:
shutdown
in interfaceShardManager
-
shutdown
public void shutdown(int shardId) Description copied from interface:ShardManager
Shuts down the shard with the given id only.
If there is no shard with the given id, this will do nothing.- Specified by:
shutdown
in interfaceShardManager
- Parameters:
shardId
- The id of the shard that should be stopped
-
start
public void start(int shardId) Description copied from interface:ShardManager
Adds a new shard with the given id to this ShardManager and starts it.- Specified by:
start
in interfaceShardManager
- Parameters:
shardId
- The id of the shard that should be started
-
setActivityProvider
Description copied from interface:ShardManager
Sets provider that provider theActivity
for all shards.
A Activity can be retrieved viaActivity.playing(String)
. For streams you provide a valid streaming url as second parameter.This will also change the provider for shards that are created in the future.
- Specified by:
setActivityProvider
in interfaceShardManager
- Parameters:
activityProvider
- Provider for anActivity
instance or null to reset- See Also:
-
setIdleProvider
Description copied from interface:ShardManager
Sets the provider that decides for all shards whether they should be marked as afk or not.This will also change the provider for shards that are created in the future.
- Specified by:
setIdleProvider
in interfaceShardManager
- Parameters:
idleProvider
- Provider for a boolean
-
setPresenceProvider
public void setPresenceProvider(IntFunction<OnlineStatus> statusProvider, IntFunction<? extends Activity> activityProvider) Description copied from interface:ShardManager
Sets the provider that provides theOnlineStatus
andActivity
for all shards.This will also change the status for shards that are created in the future.
- Specified by:
setPresenceProvider
in interfaceShardManager
- Parameters:
statusProvider
- TheOnlineStatus
to be used (OFFLINE/null -> INVISIBLE)activityProvider
- AActivity
instance or null to reset- See Also:
-
setStatusProvider
Description copied from interface:ShardManager
Sets the provider that provides theOnlineStatus
for all shards.This will also change the provider for shards that are created in the future.
- Specified by:
setStatusProvider
in interfaceShardManager
- Parameters:
statusProvider
- TheOnlineStatus
to be used (OFFLINE/null -> INVISIBLE)
-