Package discord4j.core.shard
Interface ShardingStrategy
-
- All Known Implementing Classes:
DefaultShardingStrategy
public interface ShardingStrategy
Strategy to build shardingGatewayClient
instances.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description static DefaultShardingStrategy.Builder
builder()
Return a builder to customize theShardingStrategy
using commonly used parameters.static ShardingStrategy
fixed(int count)
Sharding strategy that creates a fixed number ofGatewayClient
instances, using the givencount
.discord4j.core.shard.GatewayClientGroupManager
getGroupManager(int shardCount)
Return theGatewayClientGroupManager
to maintain each gateway client in the created group.int
getMaxConcurrency()
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 ShardingStrategy
recommended()
Sharding strategy that retrieves the recommended shard count and concurrency, and creates as manyGatewayClient
instances as indexes given by that count.static ShardingStrategy
single()
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
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 theGatewayClientGroupManager
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.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 manyGatewayClient
instances as indexes given by that count.- Returns:
- a recommended
ShardingStrategy
-
fixed
static ShardingStrategy fixed(int count)
Sharding strategy that creates a fixed number ofGatewayClient
instances, using the givencount
.- Parameters:
count
- the number ofGatewayClient
instances 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 workerGatewayClient
that 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 theShardingStrategy
using commonly used parameters.- Returns:
- a
DefaultShardingStrategy.Builder
to create a customShardingStrategy
-
-