Class ConcurrentSessionController

All Implemented Interfaces:

public class ConcurrentSessionController extends SessionControllerAdapter implements SessionController
Implementation of 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.