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
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `isAsyncReturnValue(Object returnValue, MethodParameter returnType)` Whether the return value represents an asynchronous, Future-like type with success and error callbacks.
    `ListenableFuture<?>` | `toListenableFuture(Object returnValue, 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,
                                     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
          ListenableFuture<?> toListenableFuture(Object returnValue,
                                                           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