X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2FExecutorServiceUtil.java;h=6ca961f789ad5a78c206e39975136c3a6b6d367f;hb=de93de55fefa6422bffad3fd28d71ab2e71d1900;hp=e3ee6b2d380c7434cdda79a7248fa9e59aeaea02;hpb=c24d6e2f39acbb11e22b5676bb7481ed52bec461;p=yangtools.git diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java index e3ee6b2d38..6ca961f789 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java @@ -14,7 +14,7 @@ import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,9 +24,10 @@ import org.slf4j.LoggerFactory; public final class ExecutorServiceUtil { private static final class WaitInQueueExecutionHandler implements RejectedExecutionHandler { @Override + @SuppressWarnings("checkstyle:parameterName") public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) { - if (executor.isShutdown() ) { - throw new RejectedExecutionException( "Executor has been shutdown." ); + if (executor.isShutdown()) { + throw new RejectedExecutionException("Executor has been shutdown."); } try { @@ -39,25 +40,26 @@ public final class ExecutorServiceUtil { } private static final Logger LOG = LoggerFactory.getLogger(ExecutorServiceUtil.class); - private static final RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler(); + private static final @NonNull RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler(); private ExecutorServiceUtil() { - throw new UnsupportedOperationException("Utility class"); + // Hidden on purpose } /** - * Creates a {@link BlockingQueue} which does not allow for non-blocking addition to the queue. - * This is useful with {@link #waitInQueueExecutionHandler()} to turn force a - * {@link ThreadPoolExecutor} to create as many threads as it is configured to before starting - * to fill the queue. + * Creates a {@link BlockingQueue} which does not allow for non-blocking addition to the queue. This is useful with + * {@link #waitInQueueExecutionHandler()} to turn force a {@link ThreadPoolExecutor} to create as many threads as it + * is configured to before starting to fill the queue. * + * @param type of elements * @param delegate Backing blocking queue. * @return A new blocking queue backed by the delegate */ - public static BlockingQueue offerFailingBlockingQueue(final BlockingQueue delegate) { - return new ForwardingBlockingQueue() { + public static @NonNull BlockingQueue offerFailingBlockingQueue(final BlockingQueue delegate) { + return new ForwardingBlockingQueue<>() { @Override - public boolean offer(@Nonnull final E o) { + @SuppressWarnings("checkstyle:parameterName") + public boolean offer(final E o) { return false; } @@ -69,23 +71,25 @@ public final class ExecutorServiceUtil { } /** - * Returns a {@link RejectedExecutionHandler} which blocks on the {@link ThreadPoolExecutor}'s - * backing queue if a new thread cannot be spawned. + * Returns a {@link RejectedExecutionHandler} which blocks on the {@link ThreadPoolExecutor}'s backing queue if a + * new thread cannot be spawned. * * @return A shared RejectedExecutionHandler instance. */ - public static RejectedExecutionHandler waitInQueueExecutionHandler() { + public static @NonNull RejectedExecutionHandler waitInQueueExecutionHandler() { return WAIT_IN_QUEUE_HANDLER; } /** - * Tries to shutdown the given executor gracefully by awaiting termination for the given - * timeout period. If the timeout elapses before termination, the executor is forcefully - * shutdown. + * Tries to shutdown the given executor gracefully by awaiting termination for the given timeout period. If the + * timeout elapses before termination, the executor is forcefully shutdown. + * + * @param executor Executor to shut down + * @param timeout timeout period + * @param unit timeout unit */ - public static void tryGracefulShutdown(final ExecutorService executor, long timeout, - TimeUnit unit ) { - + public static void tryGracefulShutdown(final @NonNull ExecutorService executor, final long timeout, + final @NonNull TimeUnit unit) { executor.shutdown(); try {