From accd03cce21cc1589c4954089ca1985b75248637 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 10 Jul 2019 15:11:09 +0200 Subject: [PATCH] Use OptionalInt in FlexibleThreadPoolWrapper This gets rid of Guava Optional and fixes an unboxing warning through use of Java 8. Change-Id: I9c22bbedfcdd08f18c5ff14283dd8f130d6020c6 Signed-off-by: Robert Varga --- .../util/FlexibleThreadPoolWrapper.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/FlexibleThreadPoolWrapper.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/FlexibleThreadPoolWrapper.java index b89657a3bd..a2fb009929 100644 --- a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/FlexibleThreadPoolWrapper.java +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/FlexibleThreadPoolWrapper.java @@ -5,11 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.config.threadpool.util; -import com.google.common.base.Optional; import java.io.Closeable; +import java.util.OptionalInt; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -28,18 +27,18 @@ import org.opendaylight.controller.config.threadpool.ThreadPool; public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable { private final ThreadPoolExecutor executor; - public FlexibleThreadPoolWrapper(int minThreadCount, int maxThreadCount, long keepAlive, TimeUnit timeUnit, - ThreadFactory threadFactory) { - this(minThreadCount, maxThreadCount, keepAlive, timeUnit, threadFactory, getQueue(Optional.absent())); + public FlexibleThreadPoolWrapper(final int minThreadCount, final int maxThreadCount, final long keepAlive, + final TimeUnit timeUnit, final ThreadFactory threadFactory) { + this(minThreadCount, maxThreadCount, keepAlive, timeUnit, threadFactory, getQueue(OptionalInt.empty())); } - public FlexibleThreadPoolWrapper(int minThreadCount, int maxThreadCount, long keepAlive, TimeUnit timeUnit, - ThreadFactory threadFactory, Optional queueCapacity) { + public FlexibleThreadPoolWrapper(final int minThreadCount, final int maxThreadCount, final long keepAlive, + final TimeUnit timeUnit, final ThreadFactory threadFactory, final OptionalInt queueCapacity) { this(minThreadCount, maxThreadCount, keepAlive, timeUnit, threadFactory, getQueue(queueCapacity)); } - private FlexibleThreadPoolWrapper(int minThreadCount, int maxThreadCount, long keepAlive, TimeUnit timeUnit, - ThreadFactory threadFactory, BlockingQueue queue) { + private FlexibleThreadPoolWrapper(final int minThreadCount, final int maxThreadCount, final long keepAlive, + final TimeUnit timeUnit, final ThreadFactory threadFactory, final BlockingQueue queue) { executor = new ThreadPoolExecutor(minThreadCount, maxThreadCount, keepAlive, timeUnit, queue, threadFactory, new FlexibleRejectionHandler()); @@ -52,8 +51,9 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable { * occurs in RejectedExecutionHandler. * This impl saturates threadpool first, then queue. When both are full caller will get blocked. */ - private static ForwardingBlockingQueue getQueue(Optional capacity) { - final BlockingQueue delegate = capacity.isPresent() ? new LinkedBlockingQueue<>(capacity.get()) : new LinkedBlockingQueue<>(); + private static ForwardingBlockingQueue getQueue(final OptionalInt capacity) { + final BlockingQueue delegate = capacity.isPresent() ? new LinkedBlockingQueue<>(capacity.getAsInt()) + : new LinkedBlockingQueue<>(); return new ForwardingBlockingQueue(delegate); } @@ -66,7 +66,7 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable { return executor.getCorePoolSize(); } - public void setMinThreadCount(int minThreadCount) { + public void setMinThreadCount(final int minThreadCount) { executor.setCorePoolSize(minThreadCount); } @@ -75,7 +75,7 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable { return executor.getMaximumPoolSize(); } - public void setMaxThreadCount(int maxThreadCount) { + public void setMaxThreadCount(final int maxThreadCount) { executor.setMaximumPoolSize(maxThreadCount); } @@ -83,11 +83,11 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable { return executor.getKeepAliveTime(TimeUnit.MILLISECONDS); } - public void setKeepAliveMillis(long keepAliveMillis) { + public void setKeepAliveMillis(final long keepAliveMillis) { executor.setKeepAliveTime(keepAliveMillis, TimeUnit.MILLISECONDS); } - public void setThreadFactory(ThreadFactory threadFactory) { + public void setThreadFactory(final ThreadFactory threadFactory) { executor.setThreadFactory(threadFactory); } @@ -114,10 +114,11 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable { } } - private static class ForwardingBlockingQueue extends com.google.common.util.concurrent.ForwardingBlockingQueue { + private static class ForwardingBlockingQueue + extends com.google.common.util.concurrent.ForwardingBlockingQueue { private final BlockingQueue delegate; - public ForwardingBlockingQueue(BlockingQueue delegate) { + public ForwardingBlockingQueue(final BlockingQueue delegate) { this.delegate = delegate; } -- 2.36.6