Package discord4j.core.shard
Interface ShardingStrategy
-
- All Known Implementing Classes:
DefaultShardingStrategy
public interface ShardingStrategyStrategy to build shardingGatewayClientinstances.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description static DefaultShardingStrategy.Builderbuilder()Return a builder to customize theShardingStrategyusing commonly used parameters.static ShardingStrategyfixed(int count)Sharding strategy that creates a fixed number ofGatewayClientinstances, using the givencount.discord4j.core.shard.GatewayClientGroupManagergetGroupManager(int shardCount)Return theGatewayClientGroupManagerto maintain each gateway client in the created group.intgetMaxConcurrency()Deprecated.usegetMaxConcurrency(RestClient)insteaddefault Mono<Integer>getMaxConcurrency(RestClient restClient)Return the number of shards that can be identified concurrently.Mono<Integer>getShardCount(RestClient restClient)Return the shard count used to create a group of sharded clients.default Flux<ShardInfo>getShards(int shardCount)Return the shard factory used to create a group of sharded clients.static ShardingStrategyrecommended()Sharding strategy that retrieves the recommended shard count and concurrency, and creates as manyGatewayClientinstances as indexes given by that count.static ShardingStrategysingle()Sharding strategy that creates a singleGatewayClient.
-
-
-
Method Detail
-
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
Monoto 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
ShardInfoitems.
-
getGroupManager
discord4j.core.shard.GatewayClientGroupManager getGroupManager(int shardCount)
Return theGatewayClientGroupManagerto maintain each gateway client in the created group.- Parameters:
shardCount- the total number of shards- Returns:
- a
GatewayClientGroupManagerused by this strategy
-
getMaxConcurrency
@Deprecated int getMaxConcurrency()
Deprecated.usegetMaxConcurrency(RestClient)insteadReturn 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:
- Sharding for very large bots
-
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:
- Sharding for very large bots
-
recommended
static ShardingStrategy recommended()
Sharding strategy that retrieves the recommended shard count and concurrency, and creates as manyGatewayClientinstances as indexes given by that count.- Returns:
- a recommended
ShardingStrategy
-
fixed
static ShardingStrategy fixed(int count)
Sharding strategy that creates a fixed number ofGatewayClientinstances, using the givencount.- Parameters:
count- the number ofGatewayClientinstances to create, each representing a Discord shard- Returns:
- a fixed-count
ShardingStrategy
-
single
static ShardingStrategy single()
Sharding strategy that creates a singleGatewayClient. Useful for basic bots or for advanced workerGatewayClientthat do not directly perform authentication to the Discord Gateway.- Returns:
- a simple non-sharded
ShardingStrategy
-
builder
static DefaultShardingStrategy.Builder builder()
Return a builder to customize theShardingStrategyusing commonly used parameters.- Returns:
- a
DefaultShardingStrategy.Builderto create a customShardingStrategy
-
-