001/*
002 * Copyright 2002-2017 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.util.concurrent;
018
019import java.util.concurrent.Future;
020
021/**
022 * Extend {@link Future} with the capability to accept completion callbacks.
023 * If the future has completed when the callback is added, the callback is
024 * triggered immediately.
025 *
026 * <p>Inspired by {@code com.google.common.util.concurrent.ListenableFuture}.
027 *
028 * @author Arjen Poutsma
029 * @author Sebastien Deleuze
030 * @since 4.0
031 */
032public interface ListenableFuture<T> extends Future<T> {
033
034        /**
035         * Register the given {@code ListenableFutureCallback}.
036         * @param callback the callback to register
037         */
038        void addCallback(ListenableFutureCallback<? super T> callback);
039
040        /**
041         * Java 8 lambda-friendly alternative with success and failure callbacks.
042         * @param successCallback the success callback
043         * @param failureCallback the failure callback
044         * @since 4.1
045         */
046        void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback);
047
048}