1 /* 2 * Copyright (C) 2013 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.common.util.concurrent; 17 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 abstract class WrappingScheduledExecutorService extends WrappingExecutorService 32 implements ScheduledExecutorService { 33 final ScheduledExecutorService delegate; 34 WrappingScheduledExecutorService(ScheduledExecutorService delegate)35 protected WrappingScheduledExecutorService(ScheduledExecutorService delegate) { 36 super(delegate); 37 this.delegate = delegate; 38 } 39 40 @Override schedule(Runnable command, long delay, TimeUnit unit)41 public final ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { 42 return delegate.schedule(wrapTask(command), delay, unit); 43 } 44 45 @Override schedule(Callable<V> task, long delay, TimeUnit unit)46 public final <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit unit) { 47 return delegate.schedule(wrapTask(task), delay, unit); 48 } 49 50 @Override scheduleAtFixedRate( Runnable command, long initialDelay, long period, TimeUnit unit)51 public final ScheduledFuture<?> scheduleAtFixedRate( 52 Runnable command, long initialDelay, long period, TimeUnit unit) { 53 return delegate.scheduleAtFixedRate(wrapTask(command), initialDelay, period, unit); 54 } 55 56 @Override scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit)57 public final ScheduledFuture<?> scheduleWithFixedDelay( 58 Runnable command, long initialDelay, long delay, TimeUnit unit) { 59 return delegate.scheduleWithFixedDelay(wrapTask(command), initialDelay, delay, unit); 60 } 61 } 62