Interface FutureManager

All Known Implementing Classes:
DefaultFutureManager

public interface FutureManager
Manage the lifecycle of CompletableFuture instances used for asynchronous request-response communication between servers.

Each future is identified by a unique ID generated via nextFutureId(). Futures are created and registered with ofFuture(long), completed when a response arrives via complete(FutureMessage), and can be cleaned up on timeout via cleanTimeouts().

Since:
25.1
Author:
渔民小镇
date:
2025-09-04
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Clean up any futures that have exceeded their timeout threshold.
    default void
    Complete the future matching the given message's future ID with the message itself.
    long
    Generate the next unique future identifier.
    ofFuture(long futureId)
    Create and register a new CompletableFuture associated with the given ID.
    remove(long futureId)
    Remove and return the CompletableFuture associated with the given ID.
  • Method Details

    • nextFutureId

      long nextFutureId()
      Generate the next unique future identifier.
      Returns:
      a monotonically increasing future ID
    • ofFuture

      <T> CompletableFuture<T> ofFuture(long futureId)
      Create and register a new CompletableFuture associated with the given ID.
      Type Parameters:
      T - the expected result type
      Parameters:
      futureId - the unique identifier for the future
      Returns:
      a new completable future bound to the given ID
    • remove

      <T> CompletableFuture<T> remove(long futureId)
      Remove and return the CompletableFuture associated with the given ID.
      Type Parameters:
      T - the expected result type
      Parameters:
      futureId - the unique identifier of the future to remove
      Returns:
      the removed future, or null if no future was registered for the ID
    • cleanTimeouts

      default void cleanTimeouts()
      Clean up any futures that have exceeded their timeout threshold.

      The default implementation is a no-op; concrete implementations may override to perform periodic housekeeping.

    • complete

      default void complete(FutureMessage message)
      Complete the future matching the given message's future ID with the message itself.

      If no future is found for the ID (e.g., it already timed out), the message is silently discarded.

      Parameters:
      message - the response message containing the future ID and result data