Class DefaultFutureManager
java.lang.Object
com.iohao.net.framework.communication.DefaultFutureManager
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCreate a new manager using the global future timeout configuration. -
Method Summary
Modifier and TypeMethodDescriptionlongGenerate the next unique future ID.<T> CompletableFuture<T> ofFuture(long futureId) Create and register a newCompletableFuturefor the given ID.<T> CompletableFuture<T> remove(long futureId) Remove and return the future associated with the given ID.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface FutureManager
cleanTimeouts, complete
-
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:
nextFutureIdin interfaceFutureManager- Returns:
- a monotonically increasing future ID
-
ofFuture
Create and register a newCompletableFuturefor the given ID.The future will automatically time out and be removed from the map after
futureTimeoutMillismilliseconds.- Specified by:
ofFuturein interfaceFutureManager- Type Parameters:
T- the expected result type- Parameters:
futureId- the unique ID to associate with the future- Returns:
- the newly created future
-
remove
Remove and return the future associated with the given ID.- Specified by:
removein interfaceFutureManager- Type Parameters:
T- the expected result type- Parameters:
futureId- the ID of the future to remove- Returns:
- the removed future, or
nullif no future was registered for the ID
-