FutureCallback.java revision 1d580d0f6ee4f21eb309ba7b509d2c6d671c4044
1/*
2 * Copyright (C) 2011 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.util.concurrent;
18
19import com.google.common.annotations.Beta;
20
21import java.util.concurrent.ExecutionException;
22import java.util.concurrent.Future;
23
24/**
25 * A callback for accepting the results of a {@link java.util.concurrent.Future}
26 * computation asynchronously.
27 *
28 * <p>To attach to a {@link ListenableFuture} use {@link Futures#addCallback}.
29 *
30 * @author Anthony Zana
31 * @since 10.0
32 */
33@Beta
34public interface FutureCallback<V> {
35  /**
36   * Invoked with the result of the {@code Future} computation when it is
37   * successful.
38   */
39  void onSuccess(V result);
40
41  /**
42   * Invoked when a {@code Future} computation fails or is canceled.
43   *
44   * <p>If the future's {@link Future#get() get} method throws an {@link
45   * ExecutionException}, then the cause is passed to this method. Any other
46   * thrown object is passed unaltered.
47   */
48  void onFailure(Throwable t);
49}
50