001/* 002 * Copyright (C) 2011 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 017package com.google.common.util.concurrent; 018 019import com.google.common.annotations.Beta; 020 021import java.util.concurrent.AbstractExecutorService; 022import java.util.concurrent.Callable; 023 024import javax.annotation.Nullable; 025 026/** 027 * Abstract {@link ListeningExecutorService} implementation that creates 028 * {@link ListenableFutureTask} instances for each {@link Runnable} and {@link Callable} submitted 029 * to it. These tasks are run with the abstract {@link #execute execute(Runnable)} method. 030 * 031 * <p>In addition to {@link #execute}, subclasses must implement all methods related to shutdown and 032 * termination. 033 * 034 * @author Chris Povirk 035 * @since 14.0 036 */ 037@Beta 038public abstract class AbstractListeningExecutorService 039 extends AbstractExecutorService implements ListeningExecutorService { 040 041 @Override protected final <T> ListenableFutureTask<T> newTaskFor(Runnable runnable, T value) { 042 return ListenableFutureTask.create(runnable, value); 043 } 044 045 @Override protected final <T> ListenableFutureTask<T> newTaskFor(Callable<T> callable) { 046 return ListenableFutureTask.create(callable); 047 } 048 049 @Override public ListenableFuture<?> submit(Runnable task) { 050 return (ListenableFuture<?>) super.submit(task); 051 } 052 053 @Override public <T> ListenableFuture<T> submit(Runnable task, @Nullable T result) { 054 return (ListenableFuture<T>) super.submit(task, result); 055 } 056 057 @Override public <T> ListenableFuture<T> submit(Callable<T> task) { 058 return (ListenableFuture<T>) super.submit(task); 059 } 060}