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 TypeMethodDescriptiondefault voidClean up any futures that have exceeded their timeout threshold.default voidcomplete(FutureMessage message) Complete the future matching the given message's future ID with the message itself.longGenerate the next unique future identifier.<T> CompletableFuture<T> ofFuture(long futureId) Create and register a newCompletableFutureassociated with the given ID.<T> CompletableFuture<T> remove(long futureId) Remove and return theCompletableFutureassociated with the given ID.
-
Method Details
-
nextFutureId
long nextFutureId()Generate the next unique future identifier.- Returns:
- a monotonically increasing future ID
-
ofFuture
Create and register a newCompletableFutureassociated 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
Remove and return theCompletableFutureassociated 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
nullif 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
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
-