001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.messaging.handler.invocation;
018
019import org.springframework.core.MethodParameter;
020import org.springframework.messaging.Message;
021
022/**
023 * Convenient base class for {@link AsyncHandlerMethodReturnValueHandler}
024 * implementations that support only asynchronous (Future-like) return values
025 * and merely serve as adapters of such types to Spring's
026 * {@link org.springframework.util.concurrent.ListenableFuture ListenableFuture}.
027 *
028 * @author Sebastien Deleuze
029 * @since 4.2
030 */
031public abstract class AbstractAsyncReturnValueHandler implements AsyncHandlerMethodReturnValueHandler {
032
033        @Override
034        public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
035                return true;
036        }
037
038        @Override
039        public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) {
040                // Should never be called since we return "true" from isAsyncReturnValue
041                throw new IllegalStateException("Unexpected invocation");
042        }
043
044}