Use OptionalInt in FlexibleThreadPoolWrapper 00/83000/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 13:11:09 +0000 (15:11 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Jul 2019 13:11:09 +0000 (15:11 +0200)
This gets rid of Guava Optional and fixes an unboxing warning
through use of Java 8.

Change-Id: I9c22bbedfcdd08f18c5ff14283dd8f130d6020c6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/FlexibleThreadPoolWrapper.java

index b89657a..a2fb009 100644 (file)
@@ -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
  */
  * 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;
 
 package org.opendaylight.controller.config.threadpool.util;
 
-import com.google.common.base.Optional;
 import java.io.Closeable;
 import java.io.Closeable;
+import java.util.OptionalInt;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 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 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.<Integer>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<Integer> 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));
     }
 
         this(minThreadCount, maxThreadCount, keepAlive, timeUnit, threadFactory, getQueue(queueCapacity));
     }
 
-    private FlexibleThreadPoolWrapper(int minThreadCount, int maxThreadCount, long keepAlive, TimeUnit timeUnit,
-            ThreadFactory threadFactory, BlockingQueue<Runnable> queue) {
+    private FlexibleThreadPoolWrapper(final int minThreadCount, final int maxThreadCount, final long keepAlive,
+            final TimeUnit timeUnit, final ThreadFactory threadFactory, final BlockingQueue<Runnable> queue) {
 
         executor = new ThreadPoolExecutor(minThreadCount, maxThreadCount, keepAlive, timeUnit,
                 queue, threadFactory, new FlexibleRejectionHandler());
 
         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.
      */
      * occurs in RejectedExecutionHandler.
      * This impl saturates threadpool first, then queue. When both are full caller will get blocked.
      */
-    private static ForwardingBlockingQueue getQueue(Optional<Integer> capacity) {
-        final BlockingQueue<Runnable> delegate = capacity.isPresent() ? new LinkedBlockingQueue<>(capacity.get()) : new LinkedBlockingQueue<>();
+    private static ForwardingBlockingQueue getQueue(final OptionalInt capacity) {
+        final BlockingQueue<Runnable> delegate = capacity.isPresent() ? new LinkedBlockingQueue<>(capacity.getAsInt())
+                : new LinkedBlockingQueue<>();
         return new ForwardingBlockingQueue(delegate);
     }
 
         return new ForwardingBlockingQueue(delegate);
     }
 
@@ -66,7 +66,7 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable {
         return executor.getCorePoolSize();
     }
 
         return executor.getCorePoolSize();
     }
 
-    public void setMinThreadCount(int minThreadCount) {
+    public void setMinThreadCount(final int minThreadCount) {
         executor.setCorePoolSize(minThreadCount);
     }
 
         executor.setCorePoolSize(minThreadCount);
     }
 
@@ -75,7 +75,7 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable {
         return executor.getMaximumPoolSize();
     }
 
         return executor.getMaximumPoolSize();
     }
 
-    public void setMaxThreadCount(int maxThreadCount) {
+    public void setMaxThreadCount(final int maxThreadCount) {
         executor.setMaximumPoolSize(maxThreadCount);
     }
 
         executor.setMaximumPoolSize(maxThreadCount);
     }
 
@@ -83,11 +83,11 @@ public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable {
         return executor.getKeepAliveTime(TimeUnit.MILLISECONDS);
     }
 
         return executor.getKeepAliveTime(TimeUnit.MILLISECONDS);
     }
 
-    public void setKeepAliveMillis(long keepAliveMillis) {
+    public void setKeepAliveMillis(final long keepAliveMillis) {
         executor.setKeepAliveTime(keepAliveMillis, TimeUnit.MILLISECONDS);
     }
 
         executor.setKeepAliveTime(keepAliveMillis, TimeUnit.MILLISECONDS);
     }
 
-    public void setThreadFactory(ThreadFactory threadFactory) {
+    public void setThreadFactory(final ThreadFactory threadFactory) {
         executor.setThreadFactory(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<Runnable> {
+    private static class ForwardingBlockingQueue
+            extends com.google.common.util.concurrent.ForwardingBlockingQueue<Runnable> {
         private final BlockingQueue<Runnable> delegate;
 
         private final BlockingQueue<Runnable> delegate;
 
-        public ForwardingBlockingQueue(BlockingQueue<Runnable> delegate) {
+        public ForwardingBlockingQueue(final BlockingQueue<Runnable> delegate) {
             this.delegate = delegate;
         }
 
             this.delegate = delegate;
         }
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.