Class ConcurrentSessionController
- All Implemented Interfaces:
SessionController
SessionController
which respects concurrent shard login.
This makes use of the
setConcurrency(int)
hook to delegate buckets for individual shard queues.
The concurrency model works through a modulo over the concurrency limit.
bucket = shard_id % concurrency
This limit is different depending on the scale of the bot and is determined by discord. Bots who participate in
a larger set of guilds are eligible to login more shards at once than smaller bots. A bot in 250 guilds will only
be able to login 1 shard but a bot in 250K guilds can login 16 or 64 shards at once. Each bucket has a 5 second delay
between logins.
This implementation is rather naive. It will use one thread per bucket and use sleeps to backoff. If desired, this could be done a lot more efficiently by using a scheduler. However, it is rather unlikely to be an issue in most cases. The only time where 64 threads would actually be used is during the initial startup. During runtime its not common for all shards to reconnect at once.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.utils.SessionController
SessionController.SessionConnectNode, SessionController.ShardedGateway
-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.utils.SessionController
IDENTIFY_DELAY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Called by a JDA session when a WebSocket should be started.void
Called by a JDA session when a shutdown has been requested.void
setConcurrency
(int level) Apply themax_concurrency
for this bot.Methods inherited from class net.dv8tion.jda.api.utils.SessionControllerAdapter
getRateLimitHandle, getShardedGateway
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.utils.SessionController
getGateway, getRateLimitHandle, getShardedGateway
-
Constructor Details
-
ConcurrentSessionController
public ConcurrentSessionController()
-
-
Method Details
-
setConcurrency
public void setConcurrency(int level) Description copied from interface:SessionController
Apply themax_concurrency
for this bot. This property is only useful for very large bots which get access to higher concurrency when starting their shards.Currently, there are 3 different levels of concurrency 1, 16, and 64. The concurrency means the bot can connect multiple shards at once without hitting the IDENTIFY rate-limit. This works by applying the concurrency level as a modulo operand to the shard id:
shard_id % concurrency
. We use one thread per bucket in this implementation.An implementation of this interface is not required to use this concurrency level.
SessionControllerAdapter
does not support this due to backwards compatibility.- Specified by:
setConcurrency
in interfaceSessionController
- Parameters:
level
- The concurrency level
-
appendSession
Description copied from interface:SessionController
Called by a JDA session when a WebSocket should be started. (Connecting and Reconnecting)
This should only add the node to a queue and execute the queue with respect to theSessionController.IDENTIFY_DELAY
.- Specified by:
appendSession
in interfaceSessionController
- Overrides:
appendSession
in classSessionControllerAdapter
- Parameters:
node
- TheSessionConnectNode
-
removeSession
Description copied from interface:SessionController
Called by a JDA session when a shutdown has been requested.
When this happened theSessionConnectNode.run(boolean)
will be a no-op and does not contribute to theSessionController.IDENTIFY_DELAY
.- Specified by:
removeSession
in interfaceSessionController
- Overrides:
removeSession
in classSessionControllerAdapter
- Parameters:
node
- TheSessionConnectNode
to remove from the queue.
-