View Javadoc
1   /*
2    * #%L
3    * ListenableFuture.java - mongodb-async-driver - Allanbank Consulting, Inc.
4    * %%
5    * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.allanbank.mongodb;
21  
22  import java.util.concurrent.Executor;
23  import java.util.concurrent.Future;
24  import java.util.concurrent.RejectedExecutionException;
25  
26  /**
27   * Enhancement to the {@link Future} interface inspired by the Google Guava's
28   * ListenableFuture.
29   * 
30   * @param <V>
31   *            The type of the result of the {@link Future}.
32   * 
33   * @see <a
34   *      href="https://code.google.com/p/guava-libraries/wiki/ListenableFutureExplained">Listenable
35   *      Future Explained</a>
36   * @api.yes This interface is part of the driver's API. Public and protected
37   *          members will be deprecated for at least 1 non-bugfix release
38   *          (version numbers are &lt;major&gt;.&lt;minor&gt;.&lt;bugfix&gt;)
39   *          before being removed or modified.
40   * @copyright 2013, Allanbank Consulting, Inc., All Rights Reserved
41   */
42  public interface ListenableFuture<V> extends Future<V> {
43      /**
44       * Add a {@link Runnable} to be executed once the future is completed via
45       * the provided executable.
46       * 
47       * <p>
48       * The order that {@link Runnable Runnables} are executed is unspecified.
49       * </p>
50       * 
51       * @param runnable
52       *            The myRunnable to execute.
53       * @param executor
54       *            Executor to use with the myRunnable.
55       * @throws RejectedExecutionException
56       *             If the future is already complete and the executor rejects
57       *             the request.
58       * @throws IllegalArgumentException
59       *             On the {@code myRunnable} or {@code executor} being null.
60       */
61      void addListener(Runnable runnable, Executor executor)
62              throws RejectedExecutionException, IllegalArgumentException;
63  }