Class DefaultShardManager

    • Field Detail

      • LOG

        public static final org.slf4j.Logger LOG
      • DEFAULT_THREAD_FACTORY

        public static final ThreadFactory DEFAULT_THREAD_FACTORY
    • Constructor Detail

      • DefaultShardManager

        public DefaultShardManager​(@Nonnull
                                   String token)
      • 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
                                   ChunkingFilter chunkingFilter)
    • Method Detail

      • addEventListener

        public void addEventListener​(@Nonnull
                                     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), the given listener must be an instance of EventListener!

        Specified by:
        addEventListener in interface ShardManager
        Parameters:
        listeners - The listener(s) which will react to events.
      • removeEventListener

        public void removeEventListener​(@Nonnull
                                        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 interface ShardManager
        Parameters:
        listeners - The listener(s) to be removed.
      • addEventListeners

        public void addEventListeners​(@Nonnull
                                      IntFunction<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), the given listener must be an instance of EventListener!

        Specified by:
        addEventListeners in interface ShardManager
        Parameters:
        eventListenerProvider - The provider of listener(s) which will react to events.
      • removeEventListenerProvider

        public void removeEventListenerProvider​(@Nonnull
                                                IntFunction<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 like removeEventListenerProvider(IntFunction) for actual code
        Specified by:
        removeEventListenerProvider in interface ShardManager
        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 interface ShardManager
        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 this ShardManager. This includes shards currently queued for a restart.
        Specified by:
        getShardsTotal in interface ShardManager
        Returns:
        The managed amount of shards.
      • getGuildById

        public Guild getGuildById​(long id)
        Description copied from interface: ShardManager
        This returns the Guild 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 return null.
        Specified by:
        getGuildById in interface ShardManager
        Parameters:
        id - The id of the Guild.
        Returns:
        Possibly-null Guild with matching id.
      • 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 like ShardManager.start(int).
        Specified by:
        restart in interface ShardManager
        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 interface ShardManager
      • 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 interface ShardManager
        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 interface ShardManager
        Parameters:
        shardId - The id of the shard that should be started
      • setIdleProvider

        public void setIdleProvider​(@Nonnull
                                    IntFunction<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 interface ShardManager
        Parameters:
        idleProvider - Provider for a boolean