001/* 002 * Copyright (C) 2011 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.util.concurrent; 016 017import com.google.common.annotations.GwtIncompatible; 018import com.google.errorprone.annotations.CanIgnoreReturnValue; 019import java.util.concurrent.Callable; 020import org.checkerframework.checker.nullness.qual.Nullable; 021 022/** 023 * A listening executor service which forwards all its method calls to another listening executor 024 * service. Subclasses should override one or more methods to modify the behavior of the backing 025 * executor service as desired per the <a 026 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>. 027 * 028 * @author Isaac Shum 029 * @since 10.0 030 */ 031@CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict. 032@GwtIncompatible 033@ElementTypesAreNonnullByDefault 034public abstract class ForwardingListeningExecutorService extends ForwardingExecutorService 035 implements ListeningExecutorService { 036 /** Constructor for use by subclasses. */ 037 protected ForwardingListeningExecutorService() {} 038 039 @Override 040 protected abstract ListeningExecutorService delegate(); 041 042 @Override 043 public <T extends @Nullable Object> ListenableFuture<T> submit(Callable<T> task) { 044 return delegate().submit(task); 045 } 046 047 @Override 048 public ListenableFuture<?> submit(Runnable task) { 049 return delegate().submit(task); 050 } 051 052 @Override 053 public <T extends @Nullable Object> ListenableFuture<T> submit( 054 Runnable task, @ParametricNullness T result) { 055 return delegate().submit(task, result); 056 } 057}