|
16 | 16 | import com.google.common.util.concurrent.ForwardingListeningExecutorService; |
17 | 17 | import com.google.common.util.concurrent.ListenableFuture; |
18 | 18 | import com.google.common.util.concurrent.ListeningExecutorService; |
19 | | -import jakarta.annotation.Nullable; |
20 | 19 |
|
21 | | -import java.lang.invoke.MethodHandle; |
22 | | -import java.lang.reflect.Method; |
23 | 20 | import java.time.Duration; |
24 | 21 | import java.util.Collection; |
25 | 22 | import java.util.List; |
26 | 23 | import java.util.concurrent.Callable; |
27 | 24 | import java.util.concurrent.ExecutionException; |
28 | | -import java.util.concurrent.ExecutorService; |
29 | 25 | import java.util.concurrent.Future; |
30 | 26 | import java.util.concurrent.TimeUnit; |
31 | 27 | import java.util.concurrent.TimeoutException; |
32 | 28 |
|
33 | | -import static com.google.common.base.Throwables.throwIfUnchecked; |
34 | 29 | import static com.google.common.collect.ImmutableList.toImmutableList; |
35 | | -import static io.trino.util.Reflection.methodHandle; |
36 | 30 | import static java.util.Objects.requireNonNull; |
37 | 31 |
|
38 | 32 | public class DecoratingListeningExecutorService |
39 | 33 | extends ForwardingListeningExecutorService |
40 | 34 | implements ListeningExecutorService |
41 | 35 | { |
42 | | - // TODO remove after requiring Java 19+ for runtime. |
43 | | - private static final @Nullable MethodHandle CLOSE_METHOD; |
44 | | - |
45 | | - static { |
46 | | - Method closeMethod; |
47 | | - try { |
48 | | - closeMethod = ExecutorService.class.getMethod("close"); |
49 | | - } |
50 | | - catch (NoSuchMethodException e) { |
51 | | - closeMethod = null; |
52 | | - } |
53 | | - CLOSE_METHOD = closeMethod != null |
54 | | - ? methodHandle(closeMethod) |
55 | | - : null; |
56 | | - } |
57 | | - |
58 | 36 | private final ListeningExecutorService delegate; |
59 | 37 | private final TaskDecorator decorator; |
60 | 38 |
|
@@ -194,21 +172,10 @@ public boolean awaitTermination(Duration duration) |
194 | 172 | return super.awaitTermination(duration); |
195 | 173 | } |
196 | 174 |
|
197 | | - // TODO This is temporary, until Guava's ForwardingExecutorService has the method in their interface. See https://github.com/google/guava/issues/6296 |
198 | | - //@Override |
| 175 | + @Override |
199 | 176 | public void close() |
200 | 177 | { |
201 | | - if (CLOSE_METHOD == null) { |
202 | | - throw new UnsupportedOperationException("ExecutorService.close has close() method since Java 19. " + |
203 | | - "The DecoratingListeningExecutorService supports the method only when run with Java 19 runtime."); |
204 | | - } |
205 | | - try { |
206 | | - CLOSE_METHOD.invoke(delegate()); |
207 | | - } |
208 | | - catch (Throwable e) { |
209 | | - throwIfUnchecked(e); |
210 | | - throw new RuntimeException(e); |
211 | | - } |
| 178 | + delegate.close(); |
212 | 179 | } |
213 | 180 |
|
214 | 181 | public interface TaskDecorator |
|
0 commit comments