Home | History | Annotate | Download | only in concurrent
      1 /*
      2  * Copyright (C) 2010 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 
     17 package com.google.common.util.concurrent;
     18 
     19 import java.util.Collection;
     20 import java.util.List;
     21 import java.util.concurrent.Callable;
     22 import java.util.concurrent.ExecutorService;
     23 import java.util.concurrent.Future;
     24 import java.util.concurrent.RejectedExecutionException;
     25 import java.util.concurrent.TimeUnit;
     26 
     27 /**
     28  * An {@link ExecutorService} that returns {@link ListenableFuture} instances. To create an instance
     29  * from an existing {@link ExecutorService}, call
     30  * {@link MoreExecutors#listeningDecorator(ExecutorService)}.
     31  *
     32  * @author Chris Povirk
     33  * @since 10.0
     34  */
     35 public interface ListeningExecutorService extends ExecutorService {
     36   /**
     37    * @return a {@code ListenableFuture} representing pending completion of the task
     38    * @throws RejectedExecutionException {@inheritDoc}
     39    */
     40   @Override
     41   <T> ListenableFuture<T> submit(Callable<T> task);
     42 
     43   /**
     44    * @return a {@code ListenableFuture} representing pending completion of the task
     45    * @throws RejectedExecutionException {@inheritDoc}
     46    */
     47   @Override
     48   ListenableFuture<?> submit(Runnable task);
     49 
     50   /**
     51    * @return a {@code ListenableFuture} representing pending completion of the task
     52    * @throws RejectedExecutionException {@inheritDoc}
     53    */
     54   @Override
     55   <T> ListenableFuture<T> submit(Runnable task, T result);
     56 
     57   /**
     58    * {@inheritDoc}
     59    *
     60    * <p>All elements in the returned list must be {@link ListenableFuture} instances.
     61    *
     62    * @return A list of {@code ListenableFuture} instances representing the tasks, in the same
     63    *         sequential order as produced by the iterator for the given task list, each of which has
     64    *         completed.
     65    * @throws RejectedExecutionException {@inheritDoc}
     66    * @throws NullPointerException if any task is null
     67    */
     68   @Override
     69   <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
     70       throws InterruptedException;
     71 
     72   /**
     73    * {@inheritDoc}
     74    *
     75    * <p>All elements in the returned list must be {@link ListenableFuture} instances.
     76    *
     77    * @return a list of {@code ListenableFuture} instances representing the tasks, in the same
     78    *         sequential order as produced by the iterator for the given task list. If the operation
     79    *         did not time out, each task will have completed. If it did time out, some of these
     80    *         tasks will not have completed.
     81    * @throws RejectedExecutionException {@inheritDoc}
     82    * @throws NullPointerException if any task is null
     83    */
     84   @Override
     85   <T> List<Future<T>> invokeAll(
     86       Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
     87       throws InterruptedException;
     88 }
     89