Skip to content

Package: MoreExecutors

MoreExecutors

nameinstructionbranchcomplexitylinemethod
preventShutdown(ScheduledExecutorService)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Red Hat Inc and others.
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Red Hat Inc - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.client.gateway.spi.util;
14:
15: import java.util.Collection;
16: import java.util.List;
17: import java.util.Objects;
18: import java.util.concurrent.Callable;
19: import java.util.concurrent.ExecutionException;
20: import java.util.concurrent.Future;
21: import java.util.concurrent.ScheduledExecutorService;
22: import java.util.concurrent.ScheduledFuture;
23: import java.util.concurrent.TimeUnit;
24: import java.util.concurrent.TimeoutException;
25:
26: public final class MoreExecutors {
27:
28: private MoreExecutors() {
29: }
30:
31: public static ScheduledExecutorService preventShutdown(ScheduledExecutorService executor) {
32: Objects.requireNonNull(executor);
33: return new PreventShutdownScheduledExecutorService(executor);
34: }
35:
36: private static final class PreventShutdownScheduledExecutorService implements ScheduledExecutorService {
37:
38: private final ScheduledExecutorService executor;
39:
40: private PreventShutdownScheduledExecutorService(final ScheduledExecutorService executor) {
41: this.executor = executor;
42: }
43:
44: @Override
45: public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
46: return executor.schedule(command, delay, unit);
47: }
48:
49: @Override
50: public void execute(Runnable command) {
51: executor.execute(command);
52: }
53:
54: @Override
55: public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
56: return executor.schedule(callable, delay, unit);
57: }
58:
59: @Override
60: public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
61: return executor.scheduleAtFixedRate(command, initialDelay, period, unit);
62: }
63:
64: @Override
65: public void shutdown() {
66: throw new UnsupportedOperationException("This executor service can not be shut down");
67: }
68:
69: @Override
70: public List<Runnable> shutdownNow() {
71: throw new UnsupportedOperationException("This executor service can not be shut down");
72: }
73:
74: @Override
75: public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
76: return executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
77: }
78:
79: @Override
80: public boolean isShutdown() {
81: return executor.isShutdown();
82: }
83:
84: @Override
85: public boolean isTerminated() {
86: return executor.isTerminated();
87: }
88:
89: @Override
90: public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
91: return executor.awaitTermination(timeout, unit);
92: }
93:
94: @Override
95: public <T> Future<T> submit(Callable<T> task) {
96: return executor.submit(task);
97: }
98:
99: @Override
100: public <T> Future<T> submit(Runnable task, T result) {
101: return executor.submit(task, result);
102: }
103:
104: @Override
105: public Future<?> submit(Runnable task) {
106: return executor.submit(task);
107: }
108:
109: @Override
110: public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
111: return executor.invokeAll(tasks);
112: }
113:
114: @Override
115: public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
116: return executor.invokeAll(tasks, timeout, unit);
117: }
118:
119: @Override
120: public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
121: return executor.invokeAny(tasks);
122: }
123:
124: @Override
125: public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
126: return executor.invokeAny(tasks, timeout, unit);
127: }
128:
129: }
130:
131: }