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.jspecify.annotations.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 037public abstract class ForwardingListeningExecutorService extends ForwardingExecutorService 038 implements ListeningExecutorService { 039 /** Constructor for use by subclasses. */ 040 protected ForwardingListeningExecutorService() {} 041 042 @Override 043 protected abstract ListeningExecutorService delegate(); 044 045 @Override 046 public <T extends @Nullable Object> ListenableFuture<T> submit(Callable<T> task) { 047 return delegate().submit(task); 048 } 049 050 @Override 051 public ListenableFuture<?> submit(Runnable task) { 052 return delegate().submit(task); 053 } 054 055 @Override 056 public <T extends @Nullable Object> ListenableFuture<T> submit( 057 Runnable task, @ParametricNullness T result) { 058 return delegate().submit(task, result); 059 } 060}