BUG-5280: add client connect messages
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / ABIVersion.java
index c25c156a2746d2b64a6c3d0aca001ff372cec254..0e40e6e1cb2dd3e3ac06140ddea0f4677aba0c2c 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.
@@ -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) {
@@ -114,4 +118,17 @@ public enum ABIVersion implements WritableObject {
             throw new IOException("Unsupported version", e);
         }
     }
+
+    public static 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;
+        }
+    }
 }