Class DefaultFutureManager

java.lang.Object
com.iohao.net.framework.communication.DefaultFutureManager
All Implemented Interfaces:
FutureManager

public final class DefaultFutureManager extends Object implements FutureManager
Default implementation of FutureManager backed by a concurrent map.

Manages pending CompletableFuture instances keyed by auto-incremented IDs. Each future is automatically timed out after the configured timeout period (from CoreGlobalConfig.getFutureTimeoutMillis()).

Since:
25.1
Author:
渔民小镇
date:
2025-09-16
  • Constructor Details

    • DefaultFutureManager

      public DefaultFutureManager()
      Create a new manager using the global future timeout configuration.
  • Method Details

    • nextFutureId

      public long nextFutureId()
      Generate the next unique future ID.
      Specified by:
      nextFutureId in interface FutureManager
      Returns:
      a monotonically increasing future ID
    • ofFuture

      public <T> CompletableFuture<T> ofFuture(long futureId)
      Create and register a new CompletableFuture for the given ID.

      The future will automatically time out and be removed from the map after futureTimeoutMillis milliseconds.

      Specified by:
      ofFuture in interface FutureManager
      Type Parameters:
      T - the expected result type
      Parameters:
      futureId - the unique ID to associate with the future
      Returns:
      the newly created future
    • remove

      public <T> CompletableFuture<T> remove(long futureId)
      Remove and return the future associated with the given ID.
      Specified by:
      remove in interface FutureManager
      Type Parameters:
      T - the expected result type
      Parameters:
      futureId - the ID of the future to remove
      Returns:
      the removed future, or null if no future was registered for the ID