    001    /*
    002     * Copyright (C) 2010 The Guava 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     * http://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
    017    package com.google.common.util.concurrent;
    018
    019    import java.util.Collection;
    020    import java.util.List;
    021    import java.util.concurrent.Callable;
    022    import java.util.concurrent.ExecutorService;
    023    import java.util.concurrent.Future;
    024    import java.util.concurrent.TimeUnit;
    025
    026    /**
    027     * An {@link ExecutorService} that returns {@link ListenableFuture} instances. To create an instance
    028     * from an existing {@link ExecutorService}, call
    029     * {@link MoreExecutors#listeningDecorator(ExecutorService)}.
    030     *
    031     * @author Chris Povirk
    032     * @since 10.0
    033     */
    034    public interface ListeningExecutorService extends ExecutorService {
    035      /**
    036       * @return a {@code ListenableFuture} representing pending completion of the task
    037       */
    038      @Override
    039      <T> ListenableFuture<T> submit(Callable<T> task);
    040
    041      /**
    042       * @return a {@code ListenableFuture} representing pending completion of the task
    043       */
    044      @Override
    045      ListenableFuture<?> submit(Runnable task);
    046
    047      /**
    048       * @return a {@code ListenableFuture} representing pending completion of the task
    049       */
    050      @Override
    051      <T> ListenableFuture<T> submit(Runnable task, T result);
    052
    053      /**
    054       * {@inheritDoc}
    055       *
    056       * <p>All elements in the returned list must be {@link ListenableFuture} instances.
    057       *
    058       * @return A list of {@code ListenableFuture} instances representing the tasks, in the same
    059       *         sequential order as produced by the iterator for the given task list, each of which has
    060       *         completed.
    061       */
    062      @Override
    063      <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
    064          throws InterruptedException;
    065
    066      /**
    067       * {@inheritDoc}
    068       *
    069       * <p>All elements in the returned list must be {@link ListenableFuture} instances.
    070       *
    071       * @return a list of {@code ListenableFuture} instances representing the tasks, in the same
    072       *         sequential order as produced by the iterator for the given task list. If the operation
    073       *         did not time out, each task will have completed. If it did time out, some of these
    074       *         tasks will not have completed.
    075       */
    076      @Override
    077      <T> List<Future<T>> invokeAll(
    078          Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
    079          throws InterruptedException;
    080    }