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.common.annotations.J2ktIncompatible; 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 * <p><b>{@code default} method warning:</b> This class does <i>not</i> forward calls to {@code 029 * default} methods. Instead, it inherits their default implementations. When those implementations 030 * invoke methods, they invoke methods on the {@code ForwardingListeningExecutorService}. 031 * 032 * @author Isaac Shum 033 * @since 10.0 034 */ 035@J2ktIncompatible 036@GwtIncompatible 037@ElementTypesAreNonnullByDefault 038public abstract class ForwardingListeningExecutorService extends ForwardingExecutorService 039 implements ListeningExecutorService { 040 /** Constructor for use by subclasses. */ 041 protected ForwardingListeningExecutorService() {} 042 043 @Override 044 protected abstract ListeningExecutorService delegate(); 045 046 @Override 047 public <T extends @Nullable Object> ListenableFuture<T> submit(Callable<T> task) { 048 return delegate().submit(task); 049 } 050 051 @Override 052 public ListenableFuture<?> submit(Runnable task) { 053 return delegate().submit(task); 054 } 055 056 @Override 057 public <T extends @Nullable Object> ListenableFuture<T> submit( 058 Runnable task, @ParametricNullness T result) { 059 return delegate().submit(task, result); 060 } 061}