2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.access;
10 import com.google.common.annotations.Beta;
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.base.Preconditions;
13 import java.io.DataInput;
14 import java.io.DataOutput;
15 import java.io.IOException;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.yangtools.concepts.WritableObject;
20 * Enumeration of all ABI versions supported by this implementation of the client access API.
22 * @author Robert Varga
25 public enum ABIVersion implements WritableObject {
26 // NOTE: enumeration values need to be sorted in asceding order of their version to keep Comparable working
29 * Version which is older than any other version. This version exists purely for testing purposes.
35 * Initial ABI version, as shipped with Boron Simultaneous release.
37 // We seed the initial version to be the same as DataStoreVersions.BORON-VERSION for compatibility reasons.
41 * Version which is newer than any other version. This version exists purely for testing purposes.
44 TEST_FUTURE_VERSION(65535);
46 private final short value;
48 ABIVersion(final int intVersion) {
49 Preconditions.checkArgument(intVersion >= 0 && intVersion <= 65535);
50 value = (short) intVersion;
54 * Return the unsigned short integer identifying this version.
56 * @return Unsigned short integer identifying this version
58 public short shortValue() {
63 * Return the codebase-native ABI version. This version is the default version allocated to messages at runtime.
64 * Conversion to previous versions may incur additional overhead (such as object allocation).
66 * @return Current {@link ABIVersion}
68 public static @Nonnull ABIVersion current() {
73 * Return the {@link ABIVersion} corresponding to an unsigned short integer. This method is provided for callers
74 * which provide their own recovery strategy in case of version incompatibility.
76 * @param s Short integer as returned from {@link #shortValue()}
77 * @return {@link ABIVersion}
78 * @throws FutureVersionException if the specified integer identifies a future version
79 * @throws PastVersionException if the specified integer identifies a past version which is no longer supported
81 public static @Nonnull ABIVersion valueOf(final short s) throws FutureVersionException, PastVersionException {
82 switch (Short.toUnsignedInt(s)) {
88 throw new PastVersionException(s, BORON);
92 throw new FutureVersionException(s, BORON);
97 public void writeTo(final DataOutput out) throws IOException {
98 out.writeShort(value);
102 * Read an {@link ABIVersion} from a {@link DataInput}. This method is provided for callers which do not have
103 * a recovery strategy for dealing with unsupported versions.
105 * @param in Input from which to read
106 * @return An {@link ABIVersion}
107 * @throws IOException If read fails or an unsupported version is encountered
109 public static @Nonnull ABIVersion readFrom(final @Nonnull DataInput in) throws IOException {
110 final short s = in.readShort();
113 } catch (FutureVersionException | PastVersionException e) {
114 throw new IOException("Unsupported version", e);