Package discord4j.core.shard
Class LocalShardCoordinator
- java.lang.Object
-
- discord4j.core.shard.LocalShardCoordinator
-
- All Implemented Interfaces:
ShardCoordinator
public class LocalShardCoordinator extends Object implements ShardCoordinator
A centralized localShardCoordinator
that can operate on a single JVM instance to coordinate Gateway connection and identifying attempts across multiple shards.
-
-
Field Summary
Fields Modifier and Type Field Description static Supplier<PayloadTransformer>
DEFAULT_IDENTIFY_LIMITER_FACTORY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LocalShardCoordinator
create()
Create a newLocalShardCoordinator
that is able to locally coordinate multiple shards under a single JVM instance.static LocalShardCoordinator
create(Supplier<PayloadTransformer> identifyLimiterFactory)
Create a newLocalShardCoordinator
that is able to locally coordinate multiple shards under a single JVM instance.Mono<Integer>
getConnectedCount()
Return the number of currently connected shards.PayloadTransformer
getIdentifyLimiter(ShardInfo shardInfo, int maxConcurrency)
Returns a transformation function for a sequence of payloads that can be held or delayed in order to successfully identify multiple shards in a coordinated manner.Mono<Void>
publishConnected(ShardInfo shardInfo)
Notifies this coordinator that a given shard has connected successfully.Mono<Void>
publishDisconnected(ShardInfo shardInfo, SessionInfo sessionInfo)
Notifies this coordinator that a given shard has disconnected.
-
-
-
Field Detail
-
DEFAULT_IDENTIFY_LIMITER_FACTORY
public static final Supplier<PayloadTransformer> DEFAULT_IDENTIFY_LIMITER_FACTORY
-
-
Method Detail
-
create
public static LocalShardCoordinator create()
Create a newLocalShardCoordinator
that is able to locally coordinate multiple shards under a single JVM instance.
-
create
public static LocalShardCoordinator create(Supplier<PayloadTransformer> identifyLimiterFactory)
Create a newLocalShardCoordinator
that is able to locally coordinate multiple shards under a single JVM instance.- Parameters:
identifyLimiterFactory
- a supplier ofPayloadTransformer
instances for limiting IDENTIFY access across buckets.
-
publishConnected
public Mono<Void> publishConnected(ShardInfo shardInfo)
Description copied from interface:ShardCoordinator
Notifies this coordinator that a given shard has connected successfully. Can be used to signal other shards for authentication.- Specified by:
publishConnected
in interfaceShardCoordinator
- Parameters:
shardInfo
- the connected shard details- Returns:
- a
Mono
indicating when this operation has completed
-
publishDisconnected
public Mono<Void> publishDisconnected(ShardInfo shardInfo, SessionInfo sessionInfo)
Description copied from interface:ShardCoordinator
Notifies this coordinator that a given shard has disconnected.- Specified by:
publishDisconnected
in interfaceShardCoordinator
- Parameters:
shardInfo
- the disconnected shard detailssessionInfo
- the disconnected shard session details to resume, ornull
if resume is not available- Returns:
- a
Mono
indicating when this operation has completed
-
getIdentifyLimiter
public PayloadTransformer getIdentifyLimiter(ShardInfo shardInfo, int maxConcurrency)
Description copied from interface:ShardCoordinator
Returns a transformation function for a sequence of payloads that can be held or delayed in order to successfully identify multiple shards in a coordinated manner.- Specified by:
getIdentifyLimiter
in interfaceShardCoordinator
- Parameters:
shardInfo
- the shard from where to retrieve the limitermaxConcurrency
- the number of shards that can be concurrently identified- Returns:
- a
PayloadTransformer
allowing IDENTIFY payload coordination across shards
-
getConnectedCount
public Mono<Integer> getConnectedCount()
Description copied from interface:ShardCoordinator
Return the number of currently connected shards.- Specified by:
getConnectedCount
in interfaceShardCoordinator
- Returns:
- a
Mono
with the number of connected shards
-
-