X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-common-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fcommon%2Futil%2Fjmx%2FThreadExecutorStatsMXBeanImpl.java;h=2323e2d541c26bddf72cbe6a0155c2e159df4aaf;hb=refs%2Fchanges%2F11%2F80211%2F6;hp=3de49ae296f391bfa9b33afb3524a3ed4e0cc3ae;hpb=b5b204bafd8ee18692fc023cb2eae6e123369340;p=controller.git diff --git a/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStatsMXBeanImpl.java b/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStatsMXBeanImpl.java index 3de49ae296..2323e2d541 100644 --- a/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStatsMXBeanImpl.java +++ b/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStatsMXBeanImpl.java @@ -5,15 +5,15 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.md.sal.common.util.jmx; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; -import javax.annotation.Nullable; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.util.concurrent.CountingRejectedExecutionHandler; import org.opendaylight.yangtools.util.concurrent.TrackingLinkedBlockingQueue; import org.slf4j.Logger; @@ -34,21 +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 name property in the bean's ObjectName. - * @param mBeanType Used as the type property in the bean's ObjectName. - * @param mBeanCategory Used as the Category property in the bean's ObjectName. + * @param beanName Used as the name property in the bean's ObjectName. + * @param beanType Used as the type property in the bean's ObjectName. + * @param beanCategory Used as the Category 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); - this.executor = Preconditions.checkNotNull(executor); + public ThreadExecutorStatsMXBeanImpl(final ThreadPoolExecutor executor, final String beanName, + final String beanType, final @Nullable String beanCategory) { + super(beanName, beanType, beanCategory); + this.executor = requireNonNull(executor); } private static ThreadExecutorStatsMXBeanImpl createInternal(final Executor executor, - final String mBeanName, final String mBeanType, final String mBeanCategory) { + final String beanName, final String beanType, final String beanCategory) { if (executor instanceof ThreadPoolExecutor) { final ThreadExecutorStatsMXBeanImpl ret = new ThreadExecutorStatsMXBeanImpl( - (ThreadPoolExecutor) executor, mBeanName, mBeanType, mBeanCategory); + (ThreadPoolExecutor) executor, beanName, beanType, beanCategory); return ret; } @@ -60,22 +60,36 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean * Creates a new bean if the backing executor is a ThreadPoolExecutor and registers it. * * @param executor the backing {@link Executor} - * @param mBeanName Used as the name property in the bean's ObjectName. - * @param mBeanType Used as the type property in the bean's ObjectName. - * @param mBeanCategory Used as the Category property in the bean's ObjectName. + * @param beanName Used as the name property in the bean's ObjectName. + * @param beanType Used as the type property in the bean's ObjectName. + * @param beanCategory Used as the Category 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) { - ThreadExecutorStatsMXBeanImpl ret = createInternal(executor, mBeanName, mBeanType, mBeanCategory); - if(ret != null) { + public static ThreadExecutorStatsMXBeanImpl create(final Executor executor, final String beanName, + final String beanType, final @Nullable 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 name property in the bean's ObjectName. + * @param beanType Used as the type 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. * @@ -110,7 +124,7 @@ public class ThreadExecutorStatsMXBeanImpl extends AbstractMXBean @Override public Long getLargestQueueSize() { BlockingQueue queue = executor.getQueue(); - if(queue instanceof TrackingLinkedBlockingQueue) { + if (queue instanceof TrackingLinkedBlockingQueue) { return Long.valueOf(((TrackingLinkedBlockingQueue)queue).getLargestQueueSize()); } @@ -141,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()); }