diff options
Diffstat (limited to 'guava/src/com/google/common/util/concurrent/MoreExecutors.java')
-rw-r--r-- | guava/src/com/google/common/util/concurrent/MoreExecutors.java | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/guava/src/com/google/common/util/concurrent/MoreExecutors.java b/guava/src/com/google/common/util/concurrent/MoreExecutors.java index 90776bc9e..ea3536957 100644 --- a/guava/src/com/google/common/util/concurrent/MoreExecutors.java +++ b/guava/src/com/google/common/util/concurrent/MoreExecutors.java @@ -17,10 +17,11 @@ package com.google.common.util.concurrent; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.util.concurrent.Internal.toNanosSaturated; +import static java.util.Objects.requireNonNull; -import com.google.common.annotations.Beta; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; import com.google.common.base.Throwables; @@ -80,7 +81,7 @@ public final class MoreExecutors { * @return an unmodifiable version of the input which will not hang the JVM * @since 28.0 */ - @Beta + @J2ktIncompatible @GwtIncompatible // TODO public static ExecutorService getExitingExecutorService( ThreadPoolExecutor executor, Duration terminationTimeout) { @@ -101,7 +102,7 @@ public final class MoreExecutors { * @param timeUnit unit of time for the time parameter * @return an unmodifiable version of the input which will not hang the JVM */ - @Beta + @J2ktIncompatible @GwtIncompatible // TODO @SuppressWarnings("GoodTime") // should accept a java.time.Duration public static ExecutorService getExitingExecutorService( @@ -122,7 +123,7 @@ public final class MoreExecutors { * @param executor the executor to modify to make sure it exits when the application is finished * @return an unmodifiable version of the input which will not hang the JVM */ - @Beta + @J2ktIncompatible @GwtIncompatible // concurrency public static ExecutorService getExitingExecutorService(ThreadPoolExecutor executor) { return new Application().getExitingExecutorService(executor); @@ -141,7 +142,7 @@ public final class MoreExecutors { * @return an unmodifiable version of the input which will not hang the JVM * @since 28.0 */ - @Beta + @J2ktIncompatible @GwtIncompatible // java.time.Duration public static ScheduledExecutorService getExitingScheduledExecutorService( ScheduledThreadPoolExecutor executor, Duration terminationTimeout) { @@ -162,7 +163,7 @@ public final class MoreExecutors { * @param timeUnit unit of time for the time parameter * @return an unmodifiable version of the input which will not hang the JVM */ - @Beta + @J2ktIncompatible @GwtIncompatible // TODO @SuppressWarnings("GoodTime") // should accept a java.time.Duration public static ScheduledExecutorService getExitingScheduledExecutorService( @@ -184,7 +185,7 @@ public final class MoreExecutors { * @param executor the executor to modify to make sure it exits when the application is finished * @return an unmodifiable version of the input which will not hang the JVM */ - @Beta + @J2ktIncompatible @GwtIncompatible // TODO public static ScheduledExecutorService getExitingScheduledExecutorService( ScheduledThreadPoolExecutor executor) { @@ -202,7 +203,7 @@ public final class MoreExecutors { * JVM * @since 28.0 */ - @Beta + @J2ktIncompatible @GwtIncompatible // java.time.Duration public static void addDelayedShutdownHook(ExecutorService service, Duration terminationTimeout) { addDelayedShutdownHook(service, toNanosSaturated(terminationTimeout), TimeUnit.NANOSECONDS); @@ -219,7 +220,7 @@ public final class MoreExecutors { * JVM * @param timeUnit unit of time for the time parameter */ - @Beta + @J2ktIncompatible @GwtIncompatible // TODO @SuppressWarnings("GoodTime") // should accept a java.time.Duration public static void addDelayedShutdownHook( @@ -228,6 +229,7 @@ public final class MoreExecutors { } /** Represents the current application to register shutdown hooks. */ + @J2ktIncompatible @GwtIncompatible // TODO @VisibleForTesting static class Application { @@ -288,6 +290,7 @@ public final class MoreExecutors { } } + @J2ktIncompatible @GwtIncompatible // TODO private static void useDaemonThreadFactory(ThreadPoolExecutor executor) { executor.setThreadFactory( @@ -298,6 +301,7 @@ public final class MoreExecutors { } // See newDirectExecutorService javadoc for behavioral notes. + @J2ktIncompatible @GwtIncompatible // TODO private static final class DirectExecutorService extends AbstractListeningExecutorService { /** Lock used whenever accessing the state variables (runningTasks, shutdown) of the executor */ @@ -426,6 +430,7 @@ public final class MoreExecutors { * * @since 18.0 (present as MoreExecutors.sameThreadExecutor() since 10.0) */ + @J2ktIncompatible @GwtIncompatible // TODO public static ListeningExecutorService newDirectExecutorService() { return new DirectExecutorService(); @@ -447,10 +452,10 @@ public final class MoreExecutors { * complete, the listener runs immediately in that thread. * <li>When a thread attaches a listener to a {@code ListenableFuture} that's * <em>in</em>complete and the {@code ListenableFuture} later completes normally, the - * listener runs in the the thread that completes the {@code ListenableFuture}. + * listener runs in the thread that completes the {@code ListenableFuture}. * <li>When a listener is attached to a {@code ListenableFuture} and the {@code - * ListenableFuture} gets cancelled, the listener runs immediately in the the thread - * that cancelled the {@code Future}. + * ListenableFuture} gets cancelled, the listener runs immediately in the thread that + * cancelled the {@code Future}. * </ol> * Given all these possibilities, it is frequently possible for listeners to execute in UI * threads, RPC network threads, or other latency-sensitive threads. In those cases, slow @@ -540,6 +545,7 @@ public final class MoreExecutors { * * @since 23.3 (since 23.1 as {@code sequentialExecutor}) */ + @J2ktIncompatible @GwtIncompatible public static Executor newSequentialExecutor(Executor delegate) { return new SequentialExecutor(delegate); @@ -560,6 +566,7 @@ public final class MoreExecutors { * * @since 10.0 */ + @J2ktIncompatible @GwtIncompatible // TODO public static ListeningExecutorService listeningDecorator(ExecutorService delegate) { return (delegate instanceof ListeningExecutorService) @@ -585,6 +592,7 @@ public final class MoreExecutors { * * @since 10.0 */ + @J2ktIncompatible @GwtIncompatible // TODO public static ListeningScheduledExecutorService listeningDecorator( ScheduledExecutorService delegate) { @@ -593,6 +601,7 @@ public final class MoreExecutors { : new ScheduledListeningDecorator(delegate); } + @J2ktIncompatible @GwtIncompatible // TODO private static class ListeningDecorator extends AbstractListeningExecutorService { private final ExecutorService delegate; @@ -637,6 +646,7 @@ public final class MoreExecutors { } } + @J2ktIncompatible @GwtIncompatible // TODO private static final class ScheduledListeningDecorator extends ListeningDecorator implements ListeningScheduledExecutorService { @@ -715,6 +725,7 @@ public final class MoreExecutors { } } + @J2ktIncompatible @GwtIncompatible // TODO private static final class NeverSuccessfulListenableFutureTask extends AbstractFuture.TrustedFuture<@Nullable Void> implements Runnable { @@ -728,9 +739,9 @@ public final class MoreExecutors { public void run() { try { delegate.run(); - } catch (Throwable t) { + } catch (RuntimeException | Error t) { setException(t); - throw Throwables.propagate(t); + throw t; } } @@ -756,6 +767,7 @@ public final class MoreExecutors { * An implementation of {@link ExecutorService#invokeAny} for {@link ListeningExecutorService} * implementations. */ + @J2ktIncompatible @GwtIncompatible @ParametricNullness static <T extends @Nullable Object> T invokeAnyImpl( @@ -773,6 +785,7 @@ public final class MoreExecutors { * implementations. */ @SuppressWarnings("GoodTime") // should accept a java.time.Duration + @J2ktIncompatible @GwtIncompatible @ParametricNullness static <T extends @Nullable Object> T invokeAnyImpl( @@ -854,6 +867,7 @@ public final class MoreExecutors { /** * Submits the task and adds a listener that adds the future to {@code queue} when it completes. */ + @J2ktIncompatible @GwtIncompatible // TODO private static <T extends @Nullable Object> ListenableFuture<T> submitAndAddQueueListener( ListeningExecutorService executorService, @@ -881,7 +895,7 @@ public final class MoreExecutors { * * @since 14.0 */ - @Beta + @J2ktIncompatible @GwtIncompatible // concurrency public static ThreadFactory platformThreadFactory() { if (!isAppEngineWithApiClasses()) { @@ -908,6 +922,7 @@ public final class MoreExecutors { } } + @J2ktIncompatible @GwtIncompatible // TODO private static boolean isAppEngineWithApiClasses() { if (System.getProperty("com.google.appengine.runtime.environment") == null) { @@ -943,11 +958,13 @@ public final class MoreExecutors { * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} unless * changing the name is forbidden by the security manager. */ + @J2ktIncompatible @GwtIncompatible // concurrency static Thread newThread(String name, Runnable runnable) { checkNotNull(name); checkNotNull(runnable); - Thread result = platformThreadFactory().newThread(runnable); + // TODO(b/139726489): Confirm that null is impossible here. + Thread result = requireNonNull(platformThreadFactory().newThread(runnable)); try { result.setName(name); } catch (SecurityException e) { @@ -970,6 +987,7 @@ public final class MoreExecutors { * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ + @J2ktIncompatible @GwtIncompatible // concurrency static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); @@ -993,6 +1011,7 @@ public final class MoreExecutors { * @param service The executor to decorate * @param nameSupplier The source of names for each task */ + @J2ktIncompatible @GwtIncompatible // concurrency static ExecutorService renamingDecorator( final ExecutorService service, final Supplier<String> nameSupplier) { @@ -1022,6 +1041,7 @@ public final class MoreExecutors { * @param service The executor to decorate * @param nameSupplier The source of names for each task */ + @J2ktIncompatible @GwtIncompatible // concurrency static ScheduledExecutorService renamingDecorator( final ScheduledExecutorService service, final Supplier<String> nameSupplier) { @@ -1063,8 +1083,8 @@ public final class MoreExecutors { * if the call timed out or was interrupted * @since 28.0 */ - @Beta @CanIgnoreReturnValue + @J2ktIncompatible @GwtIncompatible // java.time.Duration public static boolean shutdownAndAwaitTermination(ExecutorService service, Duration timeout) { return shutdownAndAwaitTermination(service, toNanosSaturated(timeout), TimeUnit.NANOSECONDS); @@ -1094,8 +1114,8 @@ public final class MoreExecutors { * if the call timed out or was interrupted * @since 17.0 */ - @Beta @CanIgnoreReturnValue + @J2ktIncompatible @GwtIncompatible // concurrency @SuppressWarnings("GoodTime") // should accept a java.time.Duration public static boolean shutdownAndAwaitTermination( |