org.springframework.messaging.handler.invocation

## Interface AsyncHandlerMethodReturnValueHandler

All Superinterfaces:
  HandlerMethodReturnValueHandler

All Known Implementing Classes:
  AbstractAsyncReturnValueHandler, CompletableFutureReturnValueHandler, HandlerMethodReturnValueHandlerComposite, ListenableFutureReturnValueHandler, ReactiveReturnValueHandler

    public interface AsyncHandlerMethodReturnValueHandler
    extends HandlerMethodReturnValueHandler

An extension of `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:
  `AbstractAsyncReturnValueHandler`

### Method Summary

All Methods Instance Methods Abstract Methods
`boolean` `isAsyncReturnValue(Object returnValue, org.springframework.core.MethodParameter returnType)` Whether the return value represents an asynchronous, Future-like type with success and error callbacks.
`org.springframework.util.concurrent.ListenableFuture<?>` `toListenableFuture(Object returnValue, org.springframework.core.MethodParameter returnType)` Adapt the asynchronous return value to a `ListenableFuture`.

### Methods inherited from interface org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler

`handleReturnValue, supportsReturnType`

### Method Detail

#### isAsyncReturnValue

    boolean isAsyncReturnValue(Object returnValue,
                               org.springframework.core.MethodParameter returnType)

Whether the return value represents an asynchronous, Future-like type with success and error callbacks. If this method returns `true`, then `toListenableFuture(java.lang.Object, org.springframework.core.MethodParameter)` is invoked next. If it returns `false`, then `HandlerMethodReturnValueHandler.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 returns `true`.

Parameters:
  `returnValue` - the value returned from the handler method
  `returnType` - the type of the return value
Returns:
  `true` if the return value type represents an async value

#### toListenableFuture

    @Nullable
    org.springframework.util.concurrent.ListenableFuture<?> toListenableFuture(Object returnValue,
                                                                                         org.springframework.core.MethodParameter returnType)

Adapt the asynchronous return value to a `ListenableFuture`. 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 returns `true`.

Parameters:
  `returnValue` - the value returned from the handler method
  `returnType` - the type of the return value
Returns:
  the resulting ListenableFuture, or `null` in which case no further handling will be performed