• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.google.common.util.concurrent;
18 
19 import com.google.common.annotations.Beta;
20 
21 import java.util.concurrent.AbstractExecutorService;
22 import java.util.concurrent.Callable;
23 
24 import javax.annotation.Nullable;
25 
26 /**
27  * Abstract {@link ListeningExecutorService} implementation that creates
28  * {@link ListenableFutureTask} instances for each {@link Runnable} and {@link Callable} submitted
29  * to it. These tasks are run with the abstract {@link #execute execute(Runnable)} method.
30  *
31  * <p>In addition to {@link #execute}, subclasses must implement all methods related to shutdown and
32  * termination.
33  *
34  * @author Chris Povirk
35  * @since 14.0
36  */
37 @Beta
38 public abstract class AbstractListeningExecutorService
39     extends AbstractExecutorService implements ListeningExecutorService {
40 
newTaskFor(Runnable runnable, T value)41   @Override protected final <T> ListenableFutureTask<T> newTaskFor(Runnable runnable, T value) {
42     return ListenableFutureTask.create(runnable, value);
43   }
44 
newTaskFor(Callable<T> callable)45   @Override protected final <T> ListenableFutureTask<T> newTaskFor(Callable<T> callable) {
46     return ListenableFutureTask.create(callable);
47   }
48 
submit(Runnable task)49   @Override public ListenableFuture<?> submit(Runnable task) {
50     return (ListenableFuture<?>) super.submit(task);
51   }
52 
submit(Runnable task, @Nullable T result)53   @Override public <T> ListenableFuture<T> submit(Runnable task, @Nullable T result) {
54     return (ListenableFuture<T>) super.submit(task, result);
55   }
56 
submit(Callable<T> task)57   @Override public <T> ListenableFuture<T> submit(Callable<T> task) {
58     return (ListenableFuture<T>) super.submit(task);
59   }
60 }
61