Integrate MRI projects for Neon
[controller.git] / opendaylight / md-sal / sal-common-util / src / main / java / org / opendaylight / controller / md / sal / common / util / jmx / ThreadExecutorStatsMXBeanImpl.java
index 58677103c2df020fd7ac3fdaaa38353a59a328a4..47a0cc84ccf4db96b97b04c30f49d95003e43ec9 100644 (file)
@@ -34,30 +34,21 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean
      * Constructs an instance for the given {@link Executor}.
      *
      * @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.
+     * @param beanName Used as the <code>name</code> property in the bean's ObjectName.
+     * @param beanType Used as the <code>type</code> property in the bean's ObjectName.
+     * @param beanCategory Used as the <code>Category</code> property in the bean's ObjectName.
      */
-    public ThreadExecutorStatsMXBeanImpl(final ThreadPoolExecutor executor, final String mBeanName,
-            final String mBeanType, @Nullable final String mBeanCategory) {
-        super(mBeanName, mBeanType, mBeanCategory);
+    public ThreadExecutorStatsMXBeanImpl(final ThreadPoolExecutor executor, final String beanName,
+            final String beanType, @Nullable final String beanCategory) {
+        super(beanName, beanType, beanCategory);
         this.executor = Preconditions.checkNotNull(executor);
     }
 
-    /**
-     * Create a new bean for the statistics, which is already registered.
-     *
-     * @param executor
-     * @param mBeanName
-     * @param mBeanType
-     * @param mBeanCategory
-     * @return
-     */
-    public static ThreadExecutorStatsMXBeanImpl create(final Executor executor, final String mBeanName,
-            final String mBeanType, @Nullable final String mBeanCategory) {
+    private static ThreadExecutorStatsMXBeanImpl createInternal(final Executor executor,
+            final String beanName, final String beanType, final String beanCategory) {
         if (executor instanceof ThreadPoolExecutor) {
-            final ThreadExecutorStatsMXBeanImpl ret = new ThreadExecutorStatsMXBeanImpl((ThreadPoolExecutor) executor, mBeanName, mBeanType, mBeanCategory);
-            ret.registerMBean();
+            final ThreadExecutorStatsMXBeanImpl ret = new ThreadExecutorStatsMXBeanImpl(
+                    (ThreadPoolExecutor) executor, beanName, beanType, beanCategory);
             return ret;
         }
 
@@ -65,6 +56,51 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean
         return null;
     }
 
+    /**
+     * Creates a new bean if the backing executor is a ThreadPoolExecutor and registers it.
+     *
+     * @param executor the backing {@link Executor}
+     * @param beanName Used as the <code>name</code> property in the bean's ObjectName.
+     * @param beanType Used as the <code>type</code> property in the bean's ObjectName.
+     * @param beanCategory 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 beanName,
+            final String beanType, @Nullable final String beanCategory) {
+        ThreadExecutorStatsMXBeanImpl ret = createInternal(executor, beanName, beanType, beanCategory);
+        if (ret != null) {
+            ret.registerMBean();
+        }
+
+        return ret;
+    }
+
+    /**
+     * Creates a new bean if the backing executor is a ThreadPoolExecutor and registers it.
+     *
+     * @param executor the backing {@link Executor}
+     * @param beanName Used as the <code>name</code> property in the bean's ObjectName.
+     * @param beanType Used as the <code>type</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 beanName,
+            final String beanType) {
+        return create(executor, beanName, beanType, null);
+    }
+
+    /**
+     * 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
     public long getCurrentThreadPoolSize() {
         return executor.getPoolSize();
@@ -88,7 +124,7 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean
     @Override
     public Long getLargestQueueSize() {
         BlockingQueue<Runnable> queue = executor.getQueue();
-        if(queue instanceof TrackingLinkedBlockingQueue) {
+        if (queue instanceof TrackingLinkedBlockingQueue) {
             return Long.valueOf(((TrackingLinkedBlockingQueue<?>)queue).getLargestQueueSize());
         }
 
@@ -119,7 +155,7 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean
     @Override
     public Long getRejectedTaskCount() {
         RejectedExecutionHandler rejectedHandler = executor.getRejectedExecutionHandler();
-        if(rejectedHandler instanceof CountingRejectedExecutionHandler) {
+        if (rejectedHandler instanceof CountingRejectedExecutionHandler) {
             return Long.valueOf(((CountingRejectedExecutionHandler)rejectedHandler)
                                                                      .getRejectedTaskCount());
         }