|
| 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 io.microsphere.concurrent; |
| 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 | + * Delegating {@link ScheduledExecutorService} |
| 31 | + * |
| 32 | + * @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/> |
| 33 | + * @see ScheduledExecutorService |
| 34 | + * @since 1.0.0 |
| 35 | + */ |
| 36 | +public class DelegatingScheduledExecutorService implements ScheduledExecutorService { |
| 37 | + |
| 38 | + private volatile ScheduledExecutorService delegate; |
| 39 | + |
| 40 | + public DelegatingScheduledExecutorService(ScheduledExecutorService delegate) { |
| 41 | + this.delegate = delegate; |
| 42 | + } |
| 43 | + |
| 44 | + public void setDelegate(ScheduledExecutorService delegate) { |
| 45 | + this.delegate = delegate; |
| 46 | + } |
| 47 | + |
| 48 | + public ScheduledExecutorService getDelegate() { |
| 49 | + return delegate; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { |
| 54 | + return getDelegate().schedule(command, delay, unit); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { |
| 59 | + return getDelegate().schedule(callable, delay, unit); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { |
| 64 | + return getDelegate().scheduleAtFixedRate(command, initialDelay, period, unit); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { |
| 69 | + return getDelegate().scheduleWithFixedDelay(command, initialDelay, delay, unit); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public void shutdown() { |
| 74 | + getDelegate().shutdown(); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public List<Runnable> shutdownNow() { |
| 79 | + return getDelegate().shutdownNow(); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public boolean isShutdown() { |
| 84 | + return getDelegate().isShutdown(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public boolean isTerminated() { |
| 89 | + return getDelegate().isTerminated(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { |
| 94 | + return getDelegate().awaitTermination(timeout, unit); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public <T> Future<T> submit(Callable<T> task) { |
| 99 | + return getDelegate().submit(task); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public <T> Future<T> submit(Runnable task, T result) { |
| 104 | + return getDelegate().submit(task, result); |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public Future<?> submit(Runnable task) { |
| 109 | + return getDelegate().submit(task); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { |
| 114 | + return getDelegate().invokeAll(tasks); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException { |
| 119 | + return getDelegate().invokeAll(tasks, timeout, unit); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { |
| 124 | + return getDelegate().invokeAny(tasks); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { |
| 129 | + return getDelegate().invokeAny(tasks, timeout, unit); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public void execute(Runnable command) { |
| 134 | + getDelegate().execute(command); |
| 135 | + } |
| 136 | +} |
0 commit comments