1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.tomcat.util.threads;
18
19 import java.util.Collection;
20 import java.util.List;
21 import java.util.concurrent.Callable;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.Future;
24 import java.util.concurrent.ScheduledExecutorService;
25 import java.util.concurrent.ScheduledFuture;
26 import java.util.concurrent.TimeUnit;
27 import java.util.concurrent.TimeoutException;
28
29 /**
30  * Class which wraps a ScheduledExecutorService, while preventing
31  * lifecycle and configuration operations.
32  */

33 public class ScheduledThreadPoolExecutor implements ScheduledExecutorService {
34
35     protected final ScheduledExecutorService executor;
36
37     /**
38      * Builds a wrapper for the given executor.
39      * @param executor the wrapped executor
40      */

41     public ScheduledThreadPoolExecutor(ScheduledExecutorService executor) {
42         this.executor = executor;
43     }
44
45     @Override
46     public void shutdown() {
47         // Do nothing
48     }
49
50
51     @Override
52     public List<Runnable> shutdownNow() {
53         return null;
54     }
55
56     @Override
57     public boolean isShutdown() {
58         return executor.isShutdown();
59     }
60
61     @Override
62     public boolean isTerminated() {
63         return executor.isTerminated();
64     }
65
66     @Override
67     public boolean awaitTermination(long timeout, TimeUnit unit)
68             throws InterruptedException {
69         return executor.awaitTermination(timeout, unit);
70     }
71
72     @Override
73     public <T> Future<T> submit(Callable<T> task) {
74         return executor.submit(task);
75     }
76
77     @Override
78     public <T> Future<T> submit(Runnable task, T result) {
79         return executor.submit(task, result);
80     }
81
82     @Override
83     public Future<?> submit(Runnable task) {
84         return executor.submit(task);
85     }
86
87     @Override
88     public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
89             throws InterruptedException {
90         return executor.invokeAll(tasks);
91     }
92
93     @Override
94     public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout,
95             TimeUnit unit) throws InterruptedException {
96         return executor.invokeAll(tasks, timeout, unit);
97     }
98
99     @Override
100     public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
101             throws InterruptedException, ExecutionException {
102         return executor.invokeAny(tasks);
103     }
104
105     @Override
106     public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
107             long timeout, TimeUnit unit)
108             throws InterruptedException, ExecutionException, TimeoutException {
109         return executor.invokeAny(tasks, timeout, unit);
110     }
111
112     @Override
113     public void execute(Runnable command) {
114         executor.execute(command);
115     }
116
117     @Override
118     public ScheduledFuture<?> schedule(Runnable command, long delay,
119             TimeUnit unit) {
120         return executor.schedule(command, delay, unit);
121     }
122
123     @Override
124     public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay,
125             TimeUnit unit) {
126         return executor.schedule(callable, delay, unit);
127     }
128
129     @Override
130     public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
131             long initialDelay, long period, TimeUnit unit) {
132         return executor.scheduleAtFixedRate(command, initialDelay, period, unit);
133     }
134
135     @Override
136     public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
137             long initialDelay, long delay, TimeUnit unit) {
138         return executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
139     }
140
141 }
142