Interface AsyncHandlerMethodReturnValueHandler
- All Superinterfaces:
HandlerMethodReturnValueHandler
- All Known Implementing Classes:
AbstractAsyncReturnValueHandler
,CompletableFutureReturnValueHandler
,HandlerMethodReturnValueHandlerComposite
,ListenableFutureReturnValueHandler
,ReactiveReturnValueHandler
HandlerMethodReturnValueHandler
for handling async,
Future-like return value types that support success and error callbacks.
Essentially anything that can be adapted to a
ListenableFuture
.
Implementations should consider extending the convenient base class
AbstractAsyncReturnValueHandler
.
- Since:
- 4.2
- Author:
- Rossen Stoyanchev
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isAsyncReturnValue
(Object returnValue, MethodParameter returnType) Whether the return value represents an asynchronous, Future-like type with success and error callbacks.toCompletableFuture
(Object returnValue, MethodParameter returnType) Adapt the asynchronous return value to aCompletableFuture
.default ListenableFuture<?>
toListenableFuture
(Object returnValue, MethodParameter returnType) Deprecated.Methods inherited from interface org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler
handleReturnValue, supportsReturnType
-
Method Details
-
isAsyncReturnValue
Whether the return value represents an asynchronous, Future-like type with success and error callbacks. If this method returnstrue
, thentoCompletableFuture(java.lang.Object, org.springframework.core.MethodParameter)
is invoked next. If it returnsfalse
, thenHandlerMethodReturnValueHandler.handleReturnValue(java.lang.Object, org.springframework.core.MethodParameter, org.springframework.messaging.Message<?>)
is called.Note: this method will only be invoked after
HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
is called and it returnstrue
.- Parameters:
returnValue
- the value returned from the handler methodreturnType
- the type of the return value- Returns:
true
if the return value type represents an async value
-
toListenableFuture
@Deprecated(since="6.0") @Nullable default ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) Deprecated.as of 6.0, in favor oftoCompletableFuture(Object, MethodParameter)
Adapt the asynchronous return value to aListenableFuture
.Implementations should consider returning an instance of
SettableListenableFuture
. Return value handling will then continue when the ListenableFuture is completed with either success or error.Note: this method will only be invoked after
HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
is called and it returnstrue
.- Parameters:
returnValue
- the value returned from the handler methodreturnType
- the type of the return value- Returns:
- the resulting ListenableFuture, or
null
in which case no further handling will be performed
-
toCompletableFuture
Adapt the asynchronous return value to aCompletableFuture
.Return value handling will then continue when the CompletableFuture is completed with either success or error.
Note: this method will only be invoked after
HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
is called and it returnstrue
.- Parameters:
returnValue
- the value returned from the handler methodreturnType
- the type of the return value- Returns:
- the resulting CompletableFuture, or
null
in which case no further handling will be performed - Since:
- 6.0
-
toCompletableFuture(Object, MethodParameter)