Package net.dv8tion.jda.bot.sharding
Class DefaultShardManager
- java.lang.Object
-
- net.dv8tion.jda.bot.sharding.DefaultShardManager
-
- All Implemented Interfaces:
ShardManager
public class DefaultShardManager extends java.lang.Object implements ShardManager
JDA's defaultShardManager
implementation. To create new instances use theDefaultShardManagerBuilder
.- Since:
- 3.4
- Author:
- Aljoscha Grebe
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.concurrent.ThreadFactory
DEFAULT_THREAD_FACTORY
static org.slf4j.Logger
LOG
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventListener(java.lang.Object... listeners)
Adds all provided listeners to the event-listeners that will be used to handle events.void
addEventListeners(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events.Guild
getGuildById(long id)
This returns theGuild
which has the same id as the one provided.ShardCacheView
getShardCache()
UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.int
getShardsQueued()
Returns the amount of shards queued for (re)connecting.int
getShardsTotal()
Returns the amount of shards managed by thisShardManager
.void
login()
void
removeEventListener(java.lang.Object... listeners)
Removes all provided listeners from the event-listeners and no longer uses them to handle events.void
removeEventListenerProvider(java.util.function.IntFunction<java.lang.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
setGameProvider(java.util.function.IntFunction<? extends Game> gameProvider)
Sets provider that provider theGame
for all shards.void
setIdleProvider(java.util.function.IntFunction<java.lang.Boolean> idleProvider)
Sets the provider that decides for all shards whether they should be marked as afk or not.void
setStatusProvider(java.util.function.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.bot.sharding.ShardManager
getApplicationInfo, getAveragePing, getCategories, getCategoriesByName, getCategoryById, getCategoryById, getCategoryCache, getEmoteById, getEmoteById, getEmoteCache, getEmotes, getEmotesByName, getGuildById, getGuildCache, getGuilds, getGuildsByName, getMutualGuilds, getMutualGuilds, getPrivateChannelById, getPrivateChannelById, getPrivateChannelCache, getPrivateChannels, getRoleById, getRoleById, getRoleCache, getRoles, getRolesByName, getShardById, getShardById, getShards, getShardsRunning, getStatus, getStatuses, getTextChannelById, getTextChannelById, getTextChannelCache, getTextChannels, getUserById, getUserById, getUserCache, getUsers, getVoiceChannelById, getVoiceChannelById, getVoiceChannelCache, getVoiceChannels, removeEventListeners, retrieveUserById, retrieveUserById, setGame, setIdle, setStatus
-
-
-
-
Method Detail
-
addEventListener
public void addEventListener(java.lang.Object... listeners)
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), given listener must be instance ofEventListener
!- Specified by:
addEventListener
in interfaceShardManager
- Parameters:
listeners
- The listener(s) which will react to events.
-
removeEventListener
public void removeEventListener(java.lang.Object... listeners)
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
public void addEventListeners(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
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), given listener must be instance ofEventListener
!- Specified by:
addEventListeners
in interfaceShardManager
- Parameters:
eventListenerProvider
- The provider of listener(s) which will react to events.
-
removeEventListenerProvider
public void removeEventListenerProvider(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
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 likeremoveEventListenerProvider(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
public Guild getGuildById(long id)
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, then this returnsnull
.- Specified by:
getGuildById
in interfaceShardManager
- Parameters:
id
- The id of theGuild
.- Returns:
- Possibly-null
Guild
with matching id.
-
getShardCache
public ShardCacheView 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() throws javax.security.auth.login.LoginException
- Throws:
javax.security.auth.login.LoginException
-
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.- 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.
This does nothing if there is no shard with the given id.- 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
-
setGameProvider
public void setGameProvider(java.util.function.IntFunction<? extends Game> gameProvider)
Description copied from interface:ShardManager
Sets provider that provider theGame
for all shards.
A Game can be retrieved viaGame.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:
setGameProvider
in interfaceShardManager
- Parameters:
gameProvider
- AGame
instance or null to reset- See Also:
Game.playing(String)
,Game.streaming(String, String)
-
setIdleProvider
public void setIdleProvider(java.util.function.IntFunction<java.lang.Boolean> idleProvider)
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
- boolean
-
setStatusProvider
public void setStatusProvider(java.util.function.IntFunction<OnlineStatus> statusProvider)
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)
-
-