Class UUIDPipeline

java.lang.Object
com.plotsquared.core.uuid.UUIDPipeline

public class UUIDPipeline extends Object
An UUID pipeline is essentially an ordered list of uuid services that each get the opportunity of providing usernames or UUIDs.

Each request is then passed through a secondary list of consumers, that can then be used to cache them, etc

  • Constructor Details

    • UUIDPipeline

      public UUIDPipeline(@NonNull Executor executor)
      Construct a new UUID pipeline
      Parameters:
      executor - Executor that is used to run asynchronous tasks inside of the pipeline
  • Method Details

    • registerService

      public void registerService(@NonNull UUIDService uuidService)
      Register a UUID service
      Parameters:
      uuidService - UUID service to register
    • registerConsumer

      public void registerConsumer(@NonNull Consumer<@NonNull List<@NonNull UUIDMapping>> mappingConsumer)
      Register a mapping consumer
      Parameters:
      mappingConsumer - Consumer to register
    • getServiceListInstance

      public @NonNull List<@NonNull UUIDService> getServiceListInstance()
      Get a copy of the service list
      Returns:
      Copy of service list
    • consume

      public void consume(@NonNull List<@NonNull UUIDMapping> mappings)
      Let all consumers act on the given mapping.
      Parameters:
      mappings - Mappings
    • consume

      public void consume(@NonNull UUIDMapping mapping)
      Consume a single mapping
      Parameters:
      mapping - Mapping to consume
    • storeImmediately

      public void storeImmediately(@NonNull String username, @NonNull UUID uuid)
      This will store the given username-UUID pair directly, and overwrite any existing caches. This can be used to update usernames automatically whenever a player joins the server, to make sure an up-to-date UUID mapping is stored
      Parameters:
      username - Player username
      uuid - Player uuid
    • getSingle

      public @Nullable UUID getSingle(@NonNull String username, long timeout)
      Get a single UUID from a username. This is blocking.
      Parameters:
      username - Username
      timeout - Timeout in milliseconds
      Returns:
      The mapped uuid. Will return null if the request timed out.
    • getSingle

      public @Nullable String getSingle(@NonNull UUID uuid, long timeout)
      Get a single username from a UUID. This is blocking.
      Parameters:
      uuid - UUID
      timeout - Timeout in milliseconds
      Returns:
      The mapped username. Will return null if the request timeout.
    • getSingle

      public void getSingle(@NonNull String username, @NonNull BiConsumer<@Nullable UUID,@Nullable Throwable> uuid)
      Get a single UUID from a username. This is non-blocking.
      Parameters:
      username - Username
      uuid - UUID consumer
    • getSingle

      public void getSingle(@NonNull UUID uuid, @NonNull BiConsumer<@Nullable String,@Nullable Throwable> username)
      Get a single username from a UUID. This is non-blocking.
      Parameters:
      uuid - UUID
      username - Username consumer
    • getNames

      Asynchronously attempt to fetch the mapping from a list of UUIDs.

      This will timeout after the specified time and throws a TimeoutException if this happens

      Parameters:
      requests - UUIDs
      timeout - Timeout in milliseconds
      Returns:
      Mappings
    • getUUIDs

      public @NonNull CompletableFuture<List<UUIDMapping>> getUUIDs(@NonNull Collection<String> requests, long timeout)
      Asynchronously attempt to fetch the mapping from a list of names.

      This will timeout after the specified time and throws a TimeoutException if this happens

      Parameters:
      requests - Names
      timeout - Timeout in milliseconds
      Returns:
      Mappings
    • getNames

      Asynchronously attempt to fetch the mapping from a list of UUIDs
      Parameters:
      requests - UUIDs
      Returns:
      Mappings
    • getUUIDs

      Asynchronously attempt to fetch the mapping from a list of names
      Parameters:
      requests - Names
      Returns:
      Mappings
    • getAllImmediately

      public final @NonNull Collection<@NonNull UUIDMapping> getAllImmediately()
      Get as many UUID mappings as possible under the condition that the operation cannot be blocking (for an extended amount of time)
      Returns:
      All mappings that could be provided immediately
    • getImmediately

      public final @Nullable UUIDMapping getImmediately(@NonNull Object object)
      Get a single UUID mapping immediately, if possible
      Parameters:
      object - Username (String) or UUID
      Returns:
      Mapping, if it could be found immediately