Class LocalShardCoordinator

java.lang.Object
discord4j.core.shard.LocalShardCoordinator
All Implemented Interfaces:
ShardCoordinator

public class LocalShardCoordinator extends Object implements ShardCoordinator
A centralized local ShardCoordinator that can operate on a single JVM instance to coordinate Gateway connection and identifying attempts across multiple shards.
  • Field Details

  • Method Details

    • create

      public static LocalShardCoordinator create()
      Create a new LocalShardCoordinator that is able to locally coordinate multiple shards under a single JVM instance.
    • create

      public static LocalShardCoordinator create(Supplier<PayloadTransformer> identifyLimiterFactory)
      Create a new LocalShardCoordinator that is able to locally coordinate multiple shards under a single JVM instance.
      Parameters:
      identifyLimiterFactory - a supplier of PayloadTransformer 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 interface ShardCoordinator
      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 interface ShardCoordinator
      Parameters:
      shardInfo - the disconnected shard details
      sessionInfo - the disconnected shard session details to resume, or null 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 interface ShardCoordinator
      Parameters:
      shardInfo - the shard from where to retrieve the limiter
      maxConcurrency - 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 interface ShardCoordinator
      Returns:
      a Mono with the number of connected shards