Merge "BUG-1393 Fix ignoring module based capabilities in sal-netconf-connector"
[controller.git] / opendaylight / md-sal / sal-common-util / src / main / java / org / opendaylight / controller / md / sal / common / util / jmx / ThreadExecutorStatsMXBeanImpl.java
index 58677103c2df020fd7ac3fdaaa38353a59a328a4..3de49ae296f391bfa9b33afb3524a3ed4e0cc3ae 100644 (file)
@@ -44,25 +44,47 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean
         this.executor = Preconditions.checkNotNull(executor);
     }
 
+    private static ThreadExecutorStatsMXBeanImpl createInternal(final Executor executor,
+            final String mBeanName, final String mBeanType, final String mBeanCategory) {
+        if (executor instanceof ThreadPoolExecutor) {
+            final ThreadExecutorStatsMXBeanImpl ret = new ThreadExecutorStatsMXBeanImpl(
+                    (ThreadPoolExecutor) executor, mBeanName, mBeanType, mBeanCategory);
+            return ret;
+        }
+
+        LOG.info("Executor {} is not supported", executor);
+        return null;
+    }
+
     /**
-     * Create a new bean for the statistics, which is already registered.
+     * Creates a new bean if the backing executor is a ThreadPoolExecutor and registers it.
      *
-     * @param executor
-     * @param mBeanName
-     * @param mBeanType
-     * @param mBeanCategory
-     * @return
+     * @param executor the backing {@link Executor}
+     * @param mBeanName Used as the <code>name</code> property in the bean's ObjectName.
+     * @param mBeanType Used as the <code>type</code> property in the bean's ObjectName.
+     * @param mBeanCategory Used as the <code>Category</code> property in the bean's ObjectName.
+     * @return a registered ThreadExecutorStatsMXBeanImpl instance if the backing executor
+     *         is a ThreadPoolExecutor, otherwise null.
      */
     public static ThreadExecutorStatsMXBeanImpl create(final Executor executor, final String mBeanName,
             final String mBeanType, @Nullable final String mBeanCategory) {
-        if (executor instanceof ThreadPoolExecutor) {
-            final ThreadExecutorStatsMXBeanImpl ret = new ThreadExecutorStatsMXBeanImpl((ThreadPoolExecutor) executor, mBeanName, mBeanType, mBeanCategory);
+        ThreadExecutorStatsMXBeanImpl ret = createInternal(executor, mBeanName, mBeanType, mBeanCategory);
+        if(ret != null) {
             ret.registerMBean();
-            return ret;
         }
 
-        LOG.info("Executor {} is not supported", executor);
-        return null;
+        return ret;
+    }
+
+    /**
+     * Creates a new bean if the backing executor is a ThreadPoolExecutor.
+     *
+     * @param executor the backing {@link Executor}
+     * @return a ThreadExecutorStatsMXBeanImpl instance if the backing executor
+     *         is a ThreadPoolExecutor, otherwise null.
+     */
+    public static ThreadExecutorStatsMXBeanImpl create(final Executor executor) {
+        return createInternal(executor, "", "", null);
     }
 
     @Override