View Javadoc
1   /*
2    * Copyright (C) 2013 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package com.google.common.util.concurrent;
15  
16  import com.google.common.annotations.GwtIncompatible;
17  import com.google.errorprone.annotations.CanIgnoreReturnValue;
18  import java.util.concurrent.Callable;
19  import java.util.concurrent.ScheduledExecutorService;
20  import java.util.concurrent.ScheduledFuture;
21  import java.util.concurrent.TimeUnit;
22  
23  /**
24   * An abstract {@code ScheduledExecutorService} that allows subclasses to
25   * {@linkplain #wrapTask(Callable) wrap} tasks before they are submitted to the underlying executor.
26   *
27   * <p>Note that task wrapping may occur even if the task is never executed.
28   *
29   * @author Luke Sandberg
30   */
31  @CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict.
32  @GwtIncompatible
33  abstract class WrappingScheduledExecutorService extends WrappingExecutorService
34      implements ScheduledExecutorService {
35    final ScheduledExecutorService delegate;
36  
37    protected WrappingScheduledExecutorService(ScheduledExecutorService delegate) {
38      super(delegate);
39      this.delegate = delegate;
40    }
41  
42    @Override
43    public final ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
44      return delegate.schedule(wrapTask(command), delay, unit);
45    }
46  
47    @Override
48    public final <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit unit) {
49      return delegate.schedule(wrapTask(task), delay, unit);
50    }
51  
52    @Override
53    public final ScheduledFuture<?> scheduleAtFixedRate(
54        Runnable command, long initialDelay, long period, TimeUnit unit) {
55      return delegate.scheduleAtFixedRate(wrapTask(command), initialDelay, period, unit);
56    }
57  
58    @Override
59    public final ScheduledFuture<?> scheduleWithFixedDelay(
60        Runnable command, long initialDelay, long delay, TimeUnit unit) {
61      return delegate.scheduleWithFixedDelay(wrapTask(command), initialDelay, delay, unit);
62    }
63  }