X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2FABIVersion.java;h=4d3cbc477beb33dec9e885b2ed4dffba65389ef0;hp=b476536b744b41d0cba493da91733092d504811a;hb=598f290a8c88342f16379842ab7e4915e9fcea6c;hpb=93fd87f9e46446be9eb8538669ebbfade205590e diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java index b476536b74..4d3cbc477b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java @@ -7,13 +7,15 @@ */ package org.opendaylight.controller.cluster.access; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.annotations.Beta; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion; import org.opendaylight.yangtools.concepts.WritableObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,26 +33,61 @@ public enum ABIVersion implements WritableObject { * 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), + BORON(5) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + return NormalizedNodeStreamVersion.LITHIUM; + } + }, + /** + * Revised ABI version. The messages 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; + } + }, + /** + * Revised ABI version. The messages remain the same as {@link #BORON}, but messages bearing QNames in any shape + * are using {@link NormalizedNodeStreamVersion#SODIUM_SR1}, which improves encoding. + */ + SODIUM_SR1(7) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + return NormalizedNodeStreamVersion.SODIUM_SR1; + } + }, /** * 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 static final Logger LOG = LoggerFactory.getLogger(ABIVersion.class); private final short value; ABIVersion(final int intVersion) { - Preconditions.checkArgument(intVersion >= 0 && intVersion <= 65535); + checkArgument(intVersion >= 0 && intVersion <= 65535); value = (short) intVersion; } @@ -69,9 +106,8 @@ public enum ABIVersion implements WritableObject { * * @return Current {@link ABIVersion} */ - @Nonnull - public static ABIVersion current() { - return BORON; + public static @NonNull ABIVersion current() { + return SODIUM_SR1; } /** @@ -83,8 +119,7 @@ public enum ABIVersion implements WritableObject { * @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 */ - @Nonnull - public static ABIVersion valueOf(final short value) throws FutureVersionException, PastVersionException { + public static @NonNull ABIVersion valueOf(final short value) throws FutureVersionException, PastVersionException { switch (Short.toUnsignedInt(value)) { case 0: case 1: @@ -94,8 +129,12 @@ public enum ABIVersion implements WritableObject { throw new PastVersionException(value, BORON); case 5: return BORON; + case 6: + return NEON_SR2; + case 7: + return SODIUM_SR1; default: - throw new FutureVersionException(value, BORON); + throw new FutureVersionException(value, SODIUM_SR1); } } @@ -104,6 +143,13 @@ public enum ABIVersion implements WritableObject { out.writeShort(value); } + /** + * Return the NormalizedNode stream version corresponding to this particular ABI. + * + * @return Stream Version to use for this ABI version + */ + public abstract @NonNull NormalizedNodeStreamVersion getStreamVersion(); + /** * Read an {@link ABIVersion} from a {@link DataInput}. This method is provided for callers which do not have * a recovery strategy for dealing with unsupported versions. @@ -112,8 +158,7 @@ public enum ABIVersion implements WritableObject { * @return An {@link ABIVersion} * @throws IOException If read fails or an unsupported version is encountered */ - @Nonnull - public static ABIVersion readFrom(@Nonnull final DataInput in) throws IOException { + public static @NonNull ABIVersion readFrom(final @NonNull DataInput in) throws IOException { final short s = in.readShort(); try { return valueOf(s); @@ -122,7 +167,7 @@ public enum ABIVersion implements WritableObject { } } - public static ABIVersion inexactReadFrom(@Nonnull final DataInput in) throws IOException { + public static @NonNull ABIVersion inexactReadFrom(final @NonNull DataInput in) throws IOException { final short onWire = in.readShort(); try { return ABIVersion.valueOf(onWire);