Rename SODIUM versions to NEON_SR2
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / PayloadVersion.java
index 051a375cd66f3f506ce83955620c2fbaafb6d9ca..de30141116b987bc76f0d96d03ca0f9aedf86c68 100644 (file)
@@ -14,14 +14,18 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import javax.annotation.Nonnull;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
 import org.opendaylight.yangtools.concepts.WritableObject;
 
 /**
  * Enumeration of all ABI versions supported by this implementation of persistence. An ABI version has to be bumped
  * whenever:
- * - a new event is defined
- * - serialization format is changed
+ * <ul>
+ * <li>a new event is defined</li>
+ * <li>serialization format is changed</li>
+ * </ul>
  *
+ * <p>
  * This version effectively defines the protocol version between actors participating on a particular shard. A shard
  * participant instance should oppose RAFT candidates which produce persistence of an unsupported version. If a follower
  * encounters an unsupported version it must not become fully-operational, as it does not have an accurate view
@@ -31,25 +35,51 @@ import org.opendaylight.yangtools.concepts.WritableObject;
  */
 @Beta
 public enum PayloadVersion 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.
      */
     @VisibleForTesting
-    TEST_PAST_VERSION(0),
+    TEST_PAST_VERSION(0) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            throw new UnsupportedOperationException();
+        }
+    },
 
     /**
      * Initial ABI version, as shipped with Boron Simultaneous release.
      */
-    // We seed the initial version to be the same as DataStoreVersions.BORON-VERSION for compatibility reasons.
-    BORON(5),
+    // We seed the initial version to be the same as DataStoreVersions.BORON_VERSION for compatibility reasons.
+    BORON(5) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            return NormalizedNodeStreamVersion.LITHIUM;
+        }
+    },
+
+    /**
+     * Revised payload version. Payloads remain the same as {@link #BORON}, but messages bearing QNames in any shape
+     * are using {@link NormalizedNodeStreamVersion#NEON_SR2}, which improves encoding.
+     */
+    NEON_SR2(6) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            return NormalizedNodeStreamVersion.NEON_SR2;
+        }
+    },
 
     /**
      * Version which is newer than any other version. This version exists purely for testing purposes.
      */
     @VisibleForTesting
-    TEST_FUTURE_VERSION(65535);
+    TEST_FUTURE_VERSION(65535) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            throw new UnsupportedOperationException();
+        }
+    };
 
     private final short value;
 
@@ -67,37 +97,49 @@ public enum PayloadVersion implements WritableObject {
         return value;
     }
 
+    /**
+     * Return the NormalizedNode stream version corresponding to this particular ABI.
+     *
+     * @return Stream Version to use for this ABI version
+     */
+    @Nonnull
+    public abstract NormalizedNodeStreamVersion getStreamVersion();
+
     /**
      * Return the codebase-native persistence version. This version is the default version allocated to messages
      * at runtime. Conversion to previous versions may incur additional overhead (such as object allocation).
      *
      * @return Current {@link PayloadVersion}
      */
-    public static @Nonnull PayloadVersion current() {
-        return BORON;
+    @Nonnull
+    public static PayloadVersion current() {
+        return NEON_SR2;
     }
 
     /**
      * Return the {@link PayloadVersion} 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 version Short integer as returned from {@link #shortValue()}
      * @return {@link PayloadVersion}
      * @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 PayloadVersion valueOf(final short s) throws FutureVersionException, PastVersionException {
-        switch (Short.toUnsignedInt(s)) {
+    @Nonnull
+    public static PayloadVersion valueOf(final short version) throws FutureVersionException, PastVersionException {
+        switch (Short.toUnsignedInt(version)) {
             case 0:
             case 1:
             case 2:
             case 3:
             case 4:
-                throw new PastVersionException(s, BORON);
+                throw new PastVersionException(version, BORON);
             case 5:
                 return BORON;
+            case 6:
+                return NEON_SR2;
             default:
-                throw new FutureVersionException(s, BORON);
+                throw new FutureVersionException(version, NEON_SR2);
         }
     }
 
@@ -114,7 +156,8 @@ public enum PayloadVersion implements WritableObject {
      * @return An {@link PayloadVersion}
      * @throws IOException If read fails or an unsupported version is encountered
      */
-    public static @Nonnull PayloadVersion readFrom(final @Nonnull DataInput in) throws IOException {
+    @Nonnull
+    public static PayloadVersion readFrom(@Nonnull final DataInput in) throws IOException {
         final short s = in.readShort();
         try {
             return valueOf(s);
@@ -122,5 +165,4 @@ public enum PayloadVersion implements WritableObject {
             throw new IOException("Unsupported version", e);
         }
     }
-
 }