Package discord4j.core.shard
Class DefaultShardingStrategy.Builder
- java.lang.Object
-
- discord4j.core.shard.DefaultShardingStrategy.Builder
-
- Enclosing class:
- DefaultShardingStrategy
public static class DefaultShardingStrategy.Builder extends Object
AShardingStrategy
builder.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ShardingStrategy
build()
Create theShardingStrategy
.DefaultShardingStrategy.Builder
count(int shardCount)
Set the shard count parameter.DefaultShardingStrategy.Builder
filter(Predicate<ShardInfo> shardFilter)
Set a filter to determine which shards should be accepted for identifying to Discord Gateway.DefaultShardingStrategy.Builder
indices(int... shardIndices)
Set the list of shard indices to identify to Discord Gateway.DefaultShardingStrategy.Builder
indices(Function<Integer,Publisher<Integer>> shardIndexSource)
Set a generator function to derive aPublisher
of shard indices to identify to Discord Gateway.DefaultShardingStrategy.Builder
maxConcurrency(int maxConcurrency)
Set the sharding maximum concurrency to use when identifying to the Discord Gateway, determining the amount of shards that will be concurrently identified.
-
-
-
Method Detail
-
count
public DefaultShardingStrategy.Builder count(int shardCount)
Set the shard count parameter. Defaults toRECOMMENDED_SHARD_COUNT
. Must not be negative.- Parameters:
shardCount
- the shard count sent to Discord while identifying eachGatewayClient
- Returns:
- this builder
-
indices
public DefaultShardingStrategy.Builder indices(int... shardIndices)
Set the list of shard indices to identify to Discord Gateway. Defaults to identifying all shards. Any invocation of this method will also replace the previously set value atindices(Function)
.- Parameters:
shardIndices
- the list of shard indices to identify- Returns:
- this builder
-
indices
public DefaultShardingStrategy.Builder indices(Function<Integer,Publisher<Integer>> shardIndexSource)
Set a generator function to derive aPublisher
of shard indices to identify to Discord Gateway. Defaults to identify all shards. Any invocation of this method will also replace the previously set value atindices(int...)
.- Parameters:
shardIndexSource
- the generator function to determine the shards to identify- Returns:
- this builder
-
filter
public DefaultShardingStrategy.Builder filter(Predicate<ShardInfo> shardFilter)
Set a filter to determine which shards should be accepted for identifying to Discord Gateway. Defaults to connecting to all shards given by shard count.- Parameters:
shardFilter
- aPredicate
forShardInfo
objects. Called for each shard determined bycount(int)
and schedules it for connection if returningtrue
.- Returns:
- this builder
-
maxConcurrency
public DefaultShardingStrategy.Builder maxConcurrency(int maxConcurrency)
Set the sharding maximum concurrency to use when identifying to the Discord Gateway, determining the amount of shards that will be concurrently identified. Defaults to 1. You should only change this value if your bot is authorized to use the very large bot sharding system, otherwise you will hit a rate limit on identifying.maxConcurrency
always needs to be a power of 2 and must not be lower than one.- Parameters:
maxConcurrency
- a positive number indicating the amount of shards that can be identified concurrently.- Returns:
- this builder
-
build
public ShardingStrategy build()
Create theShardingStrategy
.- Returns:
- a custom
ShardingStrategy
-
-