made the executor config have a parent default config which is used if the config has undefined values (see SMX4NMR-246)

git-svn-id: https://svn.apache.org/repos/asf/servicemix/utils/trunk@1058465 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java b/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java
index 5086a4b..76b4df1 100644
--- a/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java
+++ b/src/main/java/org/apache/servicemix/executors/impl/ExecutorConfig.java
@@ -23,29 +23,69 @@
  */

 public class ExecutorConfig {

 

-    private int corePoolSize = 4;

+    public static final int DEFAULT_CORE_POOL_SIZE = 4;

+    public static final int DEFAULT_MAXIMUM_POOL_SIZE = -1;

+    public static final long DEFAULT_KEEP_ALIVE_TIME = 60000;

+    public static final boolean DEFAULT_THREAD_DAEMON = false;

+    public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY;

+    public static final int DEFAULT_QUEUE_SIZE = 1024;

+    public static final long DEFAULT_SHUTDOWN_DELAY = 1000;

+    public static final boolean DEFAULT_ALLOW_CORE_THREAD_TIMEOUT = true;

+    public static final boolean DEFAULT_BYPASS_IF_SYNCHRONOUS = false;

 

-    private int maximumPoolSize = -1;

+    private ExecutorConfig parent;

 

-    private long keepAliveTime = 60000;

+    private Integer corePoolSize;

 

-    private boolean threadDaemon;

+    private Integer maximumPoolSize;

 

-    private int threadPriority = Thread.NORM_PRIORITY;

+    private Long keepAliveTime;

 

-    private int queueSize = 1024;

+    private Boolean threadDaemon;

 

-    private long shutdownDelay = 1000;

+    private Integer threadPriority = Thread.NORM_PRIORITY;

 

-    private boolean allowCoreThreadsTimeout = true;

+    private Integer queueSize;

 

-    private boolean bypassIfSynchronous;

+    private Long shutdownDelay;

+

+    private Boolean allowCoreThreadsTimeout;

+

+    private Boolean bypassIfSynchronous;

+

+    /**

+     * default constructor needed by spring beans

+     */

+    public ExecutorConfig() {

+        this(true, null);

+    }

+

+    /**

+     * creates a new executor config using the given parent

+     *

+     * @param parent the parent config

+     */

+    public ExecutorConfig(boolean isDefaultConfig, ExecutorConfig parent) {

+        this.parent = parent;

+        // if this is the default config we don't want undefined values

+        if (isDefaultConfig) {

+            setQueueSize(DEFAULT_QUEUE_SIZE);

+            setShutdownDelay(DEFAULT_SHUTDOWN_DELAY);

+            setThreadDaemon(DEFAULT_THREAD_DAEMON);

+            setThreadPriority(DEFAULT_THREAD_PRIORITY);

+            setAllowCoreThreadsTimeout(DEFAULT_ALLOW_CORE_THREAD_TIMEOUT);

+            setBypassIfSynchronous(DEFAULT_BYPASS_IF_SYNCHRONOUS);

+            setCorePoolSize(DEFAULT_CORE_POOL_SIZE);

+            setKeepAliveTime(DEFAULT_KEEP_ALIVE_TIME);

+            setMaximumPoolSize(DEFAULT_MAXIMUM_POOL_SIZE);

+        }

+    }

 

     /**

      * @return the corePoolSize

      */

     public int getCorePoolSize() {

-        return corePoolSize;

+        return getParent() != null && corePoolSize == null ? getParent().getCorePoolSize() : corePoolSize;

     }

 

     /**

@@ -60,7 +100,7 @@
      * @return the keepAlive

      */

     public long getKeepAliveTime() {

-        return keepAliveTime;

+        return getParent() != null && keepAliveTime == null ? getParent().getKeepAliveTime() : keepAliveTime;

     }

 

     /**

@@ -75,7 +115,7 @@
      * @return the maximumPoolSize

      */

     public int getMaximumPoolSize() {

-        return maximumPoolSize;

+        return getParent() != null && maximumPoolSize == null ? getParent().getMaximumPoolSize() : maximumPoolSize;

     }

 

     /**

@@ -90,7 +130,7 @@
      * @return the queueSize

      */

     public int getQueueSize() {

-        return queueSize;

+        return getParent() != null && queueSize == null ? getParent().getQueueSize() : queueSize;

     }

 

     /**

@@ -105,7 +145,7 @@
      * @return the threadDaemon

      */

     public boolean isThreadDaemon() {

-        return threadDaemon;

+        return getParent() != null && threadDaemon == null ? getParent().isThreadDaemon() : threadDaemon;

     }

 

     /**

@@ -120,7 +160,7 @@
      * @return the threadPriority

      */

     public int getThreadPriority() {

-        return threadPriority;

+        return getParent() != null && threadPriority == null ? getParent().getThreadPriority() : threadPriority;

     }

 

     /**

@@ -135,7 +175,7 @@
      * @return the shutdownDelay

      */

     public long getShutdownDelay() {

-        return shutdownDelay;

+        return getParent() != null && shutdownDelay == null ? getParent().getShutdownDelay() : shutdownDelay;

     }

 

     /**

@@ -150,7 +190,7 @@
      * @return the allowCoreThreadsTimeout

      */

     public boolean isAllowCoreThreadsTimeout() {

-        return allowCoreThreadsTimeout;

+        return getParent() != null && allowCoreThreadsTimeout == null ? getParent().isAllowCoreThreadsTimeout() : allowCoreThreadsTimeout;

     }

 

     /**

@@ -165,7 +205,7 @@
      * @return if synchronous tasks should bypass the executor

      */

     public boolean isBypassIfSynchronous() {

-        return bypassIfSynchronous;

+        return getParent() != null && bypassIfSynchronous == null ? getParent().isBypassIfSynchronous() : bypassIfSynchronous;

     }

 

     /**

@@ -174,4 +214,12 @@
     public void setBypassIfSynchronous(boolean bypassIfSynchronous) {

         this.bypassIfSynchronous = bypassIfSynchronous;

     }

+

+    public ExecutorConfig getParent() {

+        return parent;

+    }

+

+    public void setParent(ExecutorConfig parent) {

+        this.parent = parent;

+    }

 }

diff --git a/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java b/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java
index aba5175..474309b 100644
--- a/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java
+++ b/src/main/java/org/apache/servicemix/executors/impl/ExecutorFactoryImpl.java
@@ -16,22 +16,15 @@
  */

 package org.apache.servicemix.executors.impl;

 

+import org.apache.servicemix.executors.Executor;

+import org.apache.servicemix.executors.ExecutorFactory;

+

 import java.lang.reflect.Method;

 import java.util.HashMap;

 import java.util.Map;

-import java.util.concurrent.ArrayBlockingQueue;

-import java.util.concurrent.BlockingQueue;

-import java.util.concurrent.LinkedBlockingQueue;

-import java.util.concurrent.RejectedExecutionHandler;

-import java.util.concurrent.SynchronousQueue;

-import java.util.concurrent.ThreadFactory;

-import java.util.concurrent.ThreadPoolExecutor;

-import java.util.concurrent.TimeUnit;

+import java.util.concurrent.*;

 import java.util.concurrent.atomic.AtomicInteger;

 

-import org.apache.servicemix.executors.Executor;

-import org.apache.servicemix.executors.ExecutorFactory;

-

 /**

  * Default implementation of the ExecutorFactory.

  * <p/>

@@ -54,7 +47,7 @@
     private static final String OBJECT_NAME_PREFIX = "org.apache.servicemix:ContainerName=ServiceMix,Name=Executors,Type=";

     private static final String OBJECT_NAME_POSTFIX = ",SubType=";

 

-    private ExecutorConfig defaultConfig = new ExecutorConfig();

+    private ExecutorConfig defaultConfig = new ExecutorConfig(true, null);

 

     private javax.management.MBeanServer mbeanServer;

     private org.fusesource.commons.management.ManagementStrategy managementStrategy;

diff --git a/src/test/java/org/apache/servicemix/executors/RejectedExecutionTest.java b/src/test/java/org/apache/servicemix/executors/RejectedExecutionTest.java
index 5dbb73c..189cfc0 100644
--- a/src/test/java/org/apache/servicemix/executors/RejectedExecutionTest.java
+++ b/src/test/java/org/apache/servicemix/executors/RejectedExecutionTest.java
@@ -17,15 +17,15 @@
 
 package org.apache.servicemix.executors;
 
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.ThreadPoolExecutor.AbortPolicy;
-
 import junit.framework.TestCase;
 import org.apache.servicemix.executors.impl.ExecutorConfig;
 import org.apache.servicemix.executors.impl.ExecutorFactoryImpl;
 import org.apache.servicemix.executors.impl.ExecutorImpl;
 import org.apache.servicemix.executors.impl.ManagedExecutor;
 
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadPoolExecutor.AbortPolicy;
+
 public class RejectedExecutionTest extends TestCase {
 
     private ExecutorFactoryImpl factory;
@@ -40,7 +40,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        config = new ExecutorConfig();
+        config = new ExecutorConfig(true, null);
         config.setCorePoolSize(1);
         config.setMaximumPoolSize(1);
         config.setQueueSize(2);