Shared system services configurability (ONOS-1304)

Change-Id: I42210128fd973f16bb07955175d8e361858a9034
diff --git a/utils/misc/src/main/java/org/onlab/util/SharedExecutors.java b/utils/misc/src/main/java/org/onlab/util/SharedExecutors.java
index eca59bd..626aafb 100644
--- a/utils/misc/src/main/java/org/onlab/util/SharedExecutors.java
+++ b/utils/misc/src/main/java/org/onlab/util/SharedExecutors.java
@@ -18,6 +18,8 @@
 
 import java.util.Timer;
 import java.util.concurrent.ExecutorService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static java.util.concurrent.Executors.newFixedThreadPool;
 import static java.util.concurrent.Executors.newSingleThreadExecutor;
@@ -34,15 +36,18 @@
  */
 public final class SharedExecutors {
 
+    private static final Logger log = LoggerFactory.getLogger(SharedExecutors.class);
+
     // TODO: make this configurable via setPoolSize static method
-    private static int numberOfThreads = 30;
+    public static final int DEFAULT_THREAD_SIZE = 30;
+    private static int poolSize = DEFAULT_THREAD_SIZE;
 
     private static ExecutorService singleThreadExecutor =
             newSingleThreadExecutor(groupedThreads("onos/shared",
                                                    "onos-single-executor"));
 
     private static ExecutorService poolThreadExecutor =
-            newFixedThreadPool(numberOfThreads, groupedThreads("onos/shared",
+            newFixedThreadPool(poolSize, groupedThreads("onos/shared",
                                                                "onos-pool-executor-%d"));
 
     private static Timer sharedTimer = new Timer("onos-shared-timer");
@@ -78,4 +83,19 @@
         return sharedTimer;
     }
 
+    /**
+     * Sets the shared thread pool size.
+     * @param poolSize
+     */
+    public static void setPoolSize(int poolSize) {
+        if (poolSize > 0) {
+            SharedExecutors.poolSize = poolSize;
+            //TODO: wait for execution previous task in the queue .
+            poolThreadExecutor.shutdown();
+            poolThreadExecutor = newFixedThreadPool(poolSize, groupedThreads("onos/shared",
+                    "onos-pool-executor-%d"));
+        } else {
+            log.warn("Shared Pool Size size must be greater than 0");
+        }
+    }
 }