Fix checkstyle violations in sal-common-util 98/69098/2
authorTom Pantelis <tompantelis@gmail.com>
Mon, 5 Mar 2018 23:27:24 +0000 (18:27 -0500)
committerMichael Vorburger <vorburger@redhat.com>
Wed, 7 Mar 2018 12:48:59 +0000 (12:48 +0000)
Change-Id: I5a552d2bdadda3715b92717a90ed60db39253fd3
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/AbstractMXBean.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/QueuedNotificationManagerMXBeanImpl.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStatsMXBeanImpl.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Arguments.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/RpcErrors.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java

index 40e1bd35fcad9ab2a3312130435d39c271c0888f..d60623aba09a279e688b255d97855a3fb1cae9b8 100644 (file)
@@ -12,16 +12,19 @@ import com.google.common.annotations.Beta;
 import java.lang.management.ManagementFactory;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanRegistrationException;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
 import javax.management.ObjectName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Abstract base for an MXBean implementation class.
+ *
  * <p>
  * This class is not intended for use outside of MD-SAL and its part of private
  * implementation (still exported as public to be reused across MD-SAL implementation
@@ -39,29 +42,29 @@ public abstract class AbstractMXBean {
 
     private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
 
-    private final String mBeanName;
-    private final String mBeanType;
-    private final String mBeanCategory;
+    private final String beanName;
+    private final String beanType;
+    private final String beanCategory;
 
     /**
      * Constructor.
      *
-     * @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.
      */
-    protected AbstractMXBean(@Nonnull String mBeanName, @Nonnull String mBeanType,
-            @Nullable String mBeanCategory) {
-        this.mBeanName = mBeanName;
-        this.mBeanType = mBeanType;
-        this.mBeanCategory = mBeanCategory;
+    protected AbstractMXBean(@Nonnull String beanName, @Nonnull String beanType,
+            @Nullable String beanCategory) {
+        this.beanName = beanName;
+        this.beanType = beanType;
+        this.beanCategory = beanCategory;
     }
 
     private ObjectName getMBeanObjectName() throws MalformedObjectNameException {
         StringBuilder builder = new StringBuilder(BASE_JMX_PREFIX)
                 .append("type=").append(getMBeanType());
 
-        if(getMBeanCategory() != null) {
+        if (getMBeanCategory() != null) {
             builder.append(",Category=").append(getMBeanCategory());
         }
 
@@ -92,14 +95,13 @@ public abstract class AbstractMXBean {
             LOG.debug("Register MBean {}", mbeanName);
 
             // unregistered if already registered
-            if(server.isRegistered(mbeanName)) {
+            if (server.isRegistered(mbeanName)) {
 
                 LOG.debug("MBean {} found to be already registered", mbeanName);
 
                 try {
                     unregisterMBean(mbeanName);
-                } catch(Exception e) {
-
+                } catch (MBeanRegistrationException | InstanceNotFoundException e) {
                     LOG.warn("unregister mbean {} resulted in exception {} ", mbeanName, e);
                 }
             }
@@ -107,10 +109,9 @@ public abstract class AbstractMXBean {
             registered = true;
 
             LOG.debug("MBean {} registered successfully", mbeanName.getCanonicalName());
-        } catch(Exception e) {
-
+        } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException
+                | MalformedObjectNameException e) {
             LOG.error("registration failed {}", e);
-
         }
         return registered;
     }
@@ -134,7 +135,7 @@ public abstract class AbstractMXBean {
             ObjectName mbeanName = this.getMBeanObjectName();
             unregisterMBean(mbeanName);
             unregister = true;
-        } catch(Exception e) {
+        } catch (MBeanRegistrationException | InstanceNotFoundException | MalformedObjectNameException e) {
             LOG.debug("Failed when unregistering MBean {}", e);
         }
 
@@ -150,20 +151,20 @@ public abstract class AbstractMXBean {
      * Returns the <code>name</code> property of the bean's ObjectName.
      */
     public String getMBeanName() {
-        return mBeanName;
+        return beanName;
     }
 
     /**
      * Returns the <code>type</code> property of the bean's ObjectName.
      */
     public String getMBeanType() {
-        return mBeanType;
+        return beanType;
     }
 
     /**
      * Returns the <code>Category</code> property of the bean's ObjectName.
      */
     public String getMBeanCategory() {
-        return mBeanCategory;
+        return beanCategory;
     }
 }
index e6148fcab220d93eff83e1bdb0768961470e969b..0f324cbfd76a4fdf750b78b25f30322c8a26eaac 100644 (file)
@@ -8,13 +8,11 @@
 
 package org.opendaylight.controller.md.sal.common.util.jmx;
 
+import com.google.common.base.Preconditions;
 import java.util.List;
-
 import org.opendaylight.yangtools.util.concurrent.ListenerNotificationQueueStats;
 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
 
-import com.google.common.base.Preconditions;
-
 /**
  * Implementation of the QueuedNotificationManagerMXBean interface.
  *
@@ -31,10 +29,10 @@ public class QueuedNotificationManagerMXBeanImpl extends AbstractMXBean
 
     private final QueuedNotificationManager<?,?> manager;
 
-    public QueuedNotificationManagerMXBeanImpl( QueuedNotificationManager<?,?> manager,
-            String mBeanName, String mBeanType, String mBeanCategory ) {
-        super(mBeanName, mBeanType, mBeanCategory);
-        this.manager = Preconditions.checkNotNull( manager );
+    public QueuedNotificationManagerMXBeanImpl(QueuedNotificationManager<?,?> manager,
+            String beanName, String beanType, String beanCategory) {
+        super(beanName, beanType, beanCategory);
+        this.manager = Preconditions.checkNotNull(manager);
     }
 
     @Override
@@ -48,7 +46,6 @@ public class QueuedNotificationManagerMXBeanImpl extends AbstractMXBean
     }
 
     public QueuedNotificationManagerStats toQueuedNotificationManagerStats() {
-        return new QueuedNotificationManagerStats( getMaxListenerQueueSize(),
-                getCurrentListenerQueueStats() );
+        return new QueuedNotificationManagerStats(getMaxListenerQueueSize(), getCurrentListenerQueueStats());
     }
 }
index 3de49ae296f391bfa9b33afb3524a3ed4e0cc3ae..c6738c77cea34d061796b2ba4863179abcc9dcd2 100644 (file)
@@ -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 <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);
     }
 
     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,16 +60,16 @@ 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 <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.
      * @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, @Nullable final String beanCategory) {
+        ThreadExecutorStatsMXBeanImpl ret = createInternal(executor, beanName, beanType, beanCategory);
+        if (ret != null) {
             ret.registerMBean();
         }
 
@@ -110,7 +110,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());
         }
 
@@ -141,7 +141,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());
         }
index 17ce5dffcf0b97ea18c86774da3acaee428ee6ae..d09024aea0ccf73a50006c9c28bdca4e3b7a9aa1 100644 (file)
@@ -14,8 +14,7 @@ public final class Arguments {
     }
 
     /**
-     * Checks if value is instance of provided class
-     *
+     * Checks if value is instance of provided class.
      *
      * @param value Value to check
      * @param type Type to check
@@ -23,7 +22,7 @@ public final class Arguments {
      */
     @SuppressWarnings("unchecked")
     public static <T> T checkInstanceOf(Object value, Class<T> type) {
-        if(!type.isInstance(value)) {
+        if (!type.isInstance(value)) {
             throw new IllegalArgumentException(String.format("Value %s is not of type %s", value, type));
         }
         return (T) value;
index 28133c5b69770daa895cf49697d1988fe2983663..ad550da293c5ffeb615ee04f088a5a2252a6f9c0 100644 (file)
@@ -12,19 +12,18 @@ import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 
 /**
+ * Deprecated.
+ *
  * @deprecated Use {@link org.opendaylight.yangtools.yang.common.RpcResultBuilder}
  */
 @Deprecated
-public class RpcErrors {
+public final class RpcErrors {
+    private RpcErrors() {
+    }
 
     /**
-     * @param applicationTag
-     * @param tag
-     * @param info
-     * @param severity
-     * @param message
-     * @param errorType
-     * @param cause
+     * Creates an RpcError.
+     *
      * @return {@link RpcError} implementation
      */
     public static RpcError getRpcError(String applicationTag, String tag, String info,
@@ -44,15 +43,6 @@ public class RpcErrors {
         private final ErrorType errorType;
         private final Throwable cause;
 
-        /**
-         * @param applicationTag
-         * @param tag
-         * @param info
-         * @param severity
-         * @param message
-         * @param errorType
-         * @param cause
-         */
         protected RpcErrorTO(String applicationTag, String tag, String info,
                 ErrorSeverity severity, String message, ErrorType errorType, Throwable cause) {
             this.applicationTag = applicationTag;
index 9ffe8ab0644036ed210e0151514312374c2d08a1..7bb8c25e3ded1e6d10043c053724368f7b5e1875 100644 (file)
@@ -7,20 +7,22 @@
  */
 package org.opendaylight.controller.sal.common.util;
 
+import com.google.common.collect.ImmutableList;
 import java.io.Serializable;
 import java.util.Collection;
-
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-import com.google.common.collect.ImmutableList;
-
 /**
+ * Deprecated.
+ *
  * @deprecated Use {@link org.opendaylight.yangtools.yang.common.RpcResultBuilder}
  */
 @Deprecated
-public class Rpcs {
+public final class Rpcs {
+    private Rpcs() {
+    }
 
     public static <T> RpcResult<T> getRpcResult(boolean successful) {
         return new RpcResultTO<>(successful, null, ImmutableList.of());
@@ -41,8 +43,7 @@ public class Rpcs {
         private final T result;
         private final boolean successful;
 
-        public RpcResultTO(boolean successful, T result,
-                Collection<RpcError> errors) {
+        RpcResultTO(boolean successful, T result, Collection<RpcError> errors) {
             this.successful = successful;
             this.result = result;
             this.errors = ImmutableList.copyOf(errors);
@@ -62,6 +63,5 @@ public class Rpcs {
         public Collection<RpcError> getErrors() {
             return errors;
         }
-
     }
 }