Remove deprecated Rpcs and RpcErrors
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / codegen / impl / SingletonHolder.java
index 6bcd74d213526b83c94b43087443e50ba9385da6..13312b51b3a6606d84f2c710ec85aa74c16e2b4d 100644 (file)
@@ -16,18 +16,17 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import javassist.ClassPool;
 import org.apache.commons.lang3.StringUtils;
-import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
+import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SingletonHolder {
-    private static final Logger logger = LoggerFactory.getLogger(SingletonHolder.class);
+public final class SingletonHolder {
+    private static final Logger LOG = LoggerFactory.getLogger(SingletonHolder.class);
 
     public static final ClassPool CLASS_POOL = ClassPool.getDefault();
     public static final JavassistUtils JAVASSIST = JavassistUtils.forClassPool(CLASS_POOL);
@@ -43,7 +42,12 @@ public class SingletonHolder {
     private static ListeningExecutorService COMMIT_EXECUTOR = null;
     private static ListeningExecutorService CHANGE_EVENT_EXECUTOR = null;
 
+    private SingletonHolder() {
+    }
+
     /**
+     * Deprecated.
+     *
      * @deprecated This method is only used from configuration modules and thus callers of it
      *             should use service injection to make the executor configurable.
      */
@@ -56,9 +60,9 @@ public class SingletonHolder {
             if (StringUtils.isNotBlank(queueValue)) {
                 try {
                     queueSize = Integer.parseInt(queueValue);
-                    logger.trace("Queue size was set to {}", queueSize);
+                    LOG.trace("Queue size was set to {}", queueSize);
                 } catch (final NumberFormatException e) {
-                    logger.warn("Cannot parse {} as set by {}, using default {}", queueValue,
+                    LOG.warn("Cannot parse {} as set by {}, using default {}", queueValue,
                             NOTIFICATION_QUEUE_SIZE_PROPERTY, queueSize);
                 }
             }
@@ -75,31 +79,26 @@ public class SingletonHolder {
                 }
 
                 @Override
-                public boolean offer(final Runnable r) {
+                public boolean offer(final Runnable runnrunnableable) {
                     // ThreadPoolExecutor will spawn a new thread after core size is reached only
                     // if the queue.offer returns false.
                     return false;
                 }
             };
 
-            final ThreadFactory factory = new ThreadFactoryBuilder()
-            .setDaemon(true)
-            .setNameFormat("md-sal-binding-notification-%d")
-            .build();
+            final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true)
+                    .setNameFormat("md-sal-binding-notification-%d").build();
 
-            final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_NOTIFICATION_THREADS, MAX_NOTIFICATION_THREADS,
-                    NOTIFICATION_THREAD_LIFE, TimeUnit.SECONDS, queue, factory,
-                    new RejectedExecutionHandler() {
+            final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_NOTIFICATION_THREADS,
+                MAX_NOTIFICATION_THREADS, NOTIFICATION_THREAD_LIFE, TimeUnit.SECONDS, queue, factory,
                 // if the max threads are met, then it will raise a rejectedExecution. We then push to the queue.
-                @Override
-                public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
+                (runnable, executor1) -> {
                     try {
-                        executor.getQueue().put(r);
+                        executor1.getQueue().put(runnable);
                     } catch (final InterruptedException e) {
                         throw new RejectedExecutionException("Interrupted while waiting on the queue", e);
                     }
-                }
-            });
+                });
 
             NOTIFICATION_EXECUTOR = MoreExecutors.listeningDecorator(executor);
         }
@@ -108,13 +107,16 @@ public class SingletonHolder {
     }
 
     /**
+     * Deprecated.
+     *
      * @deprecated This method is only used from configuration modules and thus callers of it
      *             should use service injection to make the executor configurable.
      */
     @Deprecated
     public static synchronized ListeningExecutorService getDefaultCommitExecutor() {
         if (COMMIT_EXECUTOR == null) {
-            final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("md-sal-binding-commit-%d").build();
+            final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true)
+                    .setNameFormat("md-sal-binding-commit-%d").build();
             /*
              * FIXME: this used to be newCacheThreadPool(), but MD-SAL does not have transaction
              *        ordering guarantees, which means that using a concurrent threadpool results
@@ -129,9 +131,10 @@ public class SingletonHolder {
         return COMMIT_EXECUTOR;
     }
 
-    public static ExecutorService getDefaultChangeEventExecutor() {
+    public static synchronized ExecutorService getDefaultChangeEventExecutor() {
         if (CHANGE_EVENT_EXECUTOR == null) {
-            final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("md-sal-binding-change-%d").build();
+            final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true)
+                    .setNameFormat("md-sal-binding-change-%d").build();
             /*
              * FIXME: this used to be newCacheThreadPool(), but MD-SAL does not have transaction
              *        ordering guarantees, which means that using a concurrent threadpool results