*/
package org.opendaylight.controller.cluster.access;
-import com.google.common.annotations.Beta;
+import static com.google.common.base.Preconditions.checkArgument;
+
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.yangtools.concepts.WritableObject;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Enumeration of all ABI versions supported by this implementation of the client access API.
- *
- * @author Robert Varga
*/
-@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.
*/
@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;
+ }
+ },
+ /**
+ * Revised ABI version. The messages remain the same as {@link #BORON}, but messages bearing QNames in any shape
+ * are using {@link NormalizedNodeStreamVersion#MAGNESIUM}, which improves encoding.
+ */
+ MAGNESIUM(8) {
+ @Override
+ public NormalizedNodeStreamVersion getStreamVersion() {
+ return NormalizedNodeStreamVersion.MAGNESIUM;
+ }
+ },
+ /**
+ * Revised ABI version. The messages remain the same as {@link #MAGNESIUM}, the serialization proxies in use are
+ * flat objects without any superclasses.
+ */
+ CHLORINE_SR2(9) {
+ @Override
+ public NormalizedNodeStreamVersion getStreamVersion() {
+ return NormalizedNodeStreamVersion.MAGNESIUM;
+ }
+ },
/**
* 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;
}
*
* @return Current {@link ABIVersion}
*/
- public static @Nonnull ABIVersion current() {
- return BORON;
+ public static @NonNull ABIVersion current() {
+ return MAGNESIUM;
}
/**
* 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)) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- throw new PastVersionException(s, BORON);
- case 5:
- return BORON;
- default:
- throw new FutureVersionException(s, BORON);
- }
+ public static @NonNull ABIVersion valueOf(final short value) throws FutureVersionException, PastVersionException {
+ return switch (Short.toUnsignedInt(value)) {
+ case 0, 1, 2, 3, 4 -> throw new PastVersionException(value, BORON);
+ case 5 -> BORON;
+ case 6 -> NEON_SR2;
+ case 7 -> SODIUM_SR1;
+ case 8 -> MAGNESIUM;
+ case 9 -> CHLORINE_SR2;
+ default -> throw new FutureVersionException(value, CHLORINE_SR2);
+ };
+ }
+
+ /**
+ * Return {@code true} if this version is earier than some {@code other} version.
+ *
+ * @param other Other {@link ABIVersion}
+ * @return {@code true} if {@code other is later}
+ * @throws NullPointerException if {@code other} is null
+ */
+ public boolean lt(final @NonNull ABIVersion other) {
+ return compareTo(other) < 0;
}
@Override
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.
* @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 {
+ public static @NonNull ABIVersion readFrom(final @NonNull DataInput in) throws IOException {
final short s = in.readShort();
try {
return valueOf(s);
throw new IOException("Unsupported version", e);
}
}
+
+ public static @NonNull ABIVersion inexactReadFrom(final @NonNull 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;
+ }
+ }
}