Fix CS warnings in cds-access-api and enable enforcement
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / ABIVersion.java
index c25c156a2746d2b64a6c3d0aca001ff372cec254..b476536b744b41d0cba493da91733092d504811a 100644 (file)
@@ -15,6 +15,8 @@ import java.io.DataOutput;
 import java.io.IOException;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.WritableObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Enumeration of all ABI versions supported by this implementation of the client access API.
@@ -23,7 +25,7 @@ import org.opendaylight.yangtools.concepts.WritableObject;
  */
 @Beta
 public enum ABIVersion implements WritableObject {
-    // NOTE: enumeration values need to be sorted in asceding order of their version to keep Comparable working
+    // NOTE: enumeration values need to be sorted in ascending order of their version to keep Comparable working
 
     /**
      * Version which is older than any other version. This version exists purely for testing purposes.
@@ -43,6 +45,8 @@ public enum ABIVersion implements WritableObject {
     @VisibleForTesting
     TEST_FUTURE_VERSION(65535);
 
+    private static final Logger LOG = LoggerFactory.getLogger(ABIVersion.class);
+
     private final short value;
 
     ABIVersion(final int intVersion) {
@@ -65,7 +69,8 @@ public enum ABIVersion implements WritableObject {
      *
      * @return Current {@link ABIVersion}
      */
-    public static @Nonnull ABIVersion current() {
+    @Nonnull
+    public static ABIVersion current() {
         return BORON;
     }
 
@@ -73,23 +78,24 @@ public enum ABIVersion implements WritableObject {
      * Return the {@link ABIVersion} corresponding to an unsigned short integer. This method is provided for callers
      * which provide their own recovery strategy in case of version incompatibility.
      *
-     * @param s Short integer as returned from {@link #shortValue()}
+     * @param value Short integer as returned from {@link #shortValue()}
      * @return {@link ABIVersion}
      * @throws FutureVersionException if the specified integer identifies a future version
      * @throws PastVersionException if the specified integer identifies a past version which is no longer supported
      */
-    public static @Nonnull ABIVersion valueOf(final short s) throws FutureVersionException, PastVersionException {
-        switch (Short.toUnsignedInt(s)) {
+    @Nonnull
+    public static ABIVersion valueOf(final short value) throws FutureVersionException, PastVersionException {
+        switch (Short.toUnsignedInt(value)) {
             case 0:
             case 1:
             case 2:
             case 3:
             case 4:
-                throw new PastVersionException(s, BORON);
+                throw new PastVersionException(value, BORON);
             case 5:
                 return BORON;
             default:
-                throw new FutureVersionException(s, BORON);
+                throw new FutureVersionException(value, BORON);
         }
     }
 
@@ -106,7 +112,8 @@ public enum ABIVersion implements WritableObject {
      * @return An {@link ABIVersion}
      * @throws IOException If read fails or an unsupported version is encountered
      */
-    public static @Nonnull ABIVersion readFrom(final @Nonnull DataInput in) throws IOException {
+    @Nonnull
+    public static ABIVersion readFrom(@Nonnull final DataInput in) throws IOException {
         final short s = in.readShort();
         try {
             return valueOf(s);
@@ -114,4 +121,17 @@ public enum ABIVersion implements WritableObject {
             throw new IOException("Unsupported version", e);
         }
     }
+
+    public static ABIVersion inexactReadFrom(@Nonnull final DataInput in) throws IOException {
+        final short onWire = in.readShort();
+        try {
+            return ABIVersion.valueOf(onWire);
+        } catch (FutureVersionException e) {
+            LOG.debug("Received future version", e);
+            return ABIVersion.TEST_FUTURE_VERSION;
+        } catch (PastVersionException e) {
+            LOG.debug("Received past version", e);
+            return ABIVersion.TEST_PAST_VERSION;
+        }
+    }
 }