Interface ShardingStrategy

All Known Implementing Classes:
DefaultShardingStrategy

public interface ShardingStrategy
Strategy to build sharding GatewayClient instances.
  • Method Details

    • getShardCount

      Mono<Integer> getShardCount(RestClient restClient)
      Return the shard count used to create a group of sharded clients.
      Parameters:
      restClient - a handle to consume REST API resources, typically to retrieve the number of recommended shards
      Returns:
      a shard count as a Mono to obtain this number asynchronously.
    • getShards

      default Flux<ShardInfo> getShards(int shardCount)
      Return the shard factory used to create a group of sharded clients.
      Parameters:
      shardCount - the total number of shards
      Returns:
      a shard factory as a sequence of ShardInfo items.
    • getGroupManager

      discord4j.core.shard.GatewayClientGroupManager getGroupManager(int shardCount)
      Return the GatewayClientGroupManager to maintain each gateway client in the created group.
      Parameters:
      shardCount - the total number of shards
      Returns:
      a GatewayClientGroupManager used by this strategy
    • getMaxConcurrency

      @Deprecated int getMaxConcurrency()
      Deprecated.
      Return the number of shards that can be identified concurrently. Must be 1 unless your application is authorized to use the large bot sharding system.
      Returns:
      a value determining the sharding factor this strategy has
      See Also:
    • getMaxConcurrency

      default Mono<Integer> getMaxConcurrency(RestClient restClient)
      Return the number of shards that can be identified concurrently. Must be 1 unless your application is authorized to use the large bot sharding system.
      Parameters:
      restClient - a handle to consume REST API resources, typically to retrieve the recommended concurrency
      Returns:
      a value determining the sharding factor this strategy has
      See Also:
    • recommended

      static ShardingStrategy recommended()
      Sharding strategy that retrieves the recommended shard count and concurrency, and creates as many GatewayClient instances as indexes given by that count.
      Returns:
      a recommended ShardingStrategy
    • fixed

      static ShardingStrategy fixed(int count)
      Sharding strategy that creates a fixed number of GatewayClient instances, using the given count.
      Parameters:
      count - the number of GatewayClient instances to create, each representing a Discord shard
      Returns:
      a fixed-count ShardingStrategy
    • single

      static ShardingStrategy single()
      Sharding strategy that creates a single GatewayClient. Useful for basic bots or for advanced worker GatewayClient that do not directly perform authentication to the Discord Gateway.
      Returns:
      a simple non-sharded ShardingStrategy
    • builder

      Return a builder to customize the ShardingStrategy using commonly used parameters.
      Returns:
      a DefaultShardingStrategy.Builder to create a custom ShardingStrategy