BUG-5280: remove support for talking to pre-Boron clients
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / VersionedExternalizableMessage.java
index b34737be542d743e09bdd1a0d2df6abf18a4a78f..51a9079d20cbc11c12295d02a6487d80b0d2c154 100644 (file)
@@ -27,7 +27,7 @@ public abstract class VersionedExternalizableMessage implements Externalizable,
     }
 
     public VersionedExternalizableMessage(short version) {
-        this.version = version;
+        this.version = version <= DataStoreVersions.CURRENT_VERSION ? version: DataStoreVersions.CURRENT_VERSION;
     }
 
     public short getVersion() {
@@ -43,4 +43,18 @@ public abstract class VersionedExternalizableMessage implements Externalizable,
     public void writeExternal(ObjectOutput out) throws IOException {
         out.writeShort(version);
     }
+
+    @Override
+    public final Object toSerializable() {
+        if (getVersion() < DataStoreVersions.BORON_VERSION) {
+            throw new UnsupportedOperationException("Versions prior to " + DataStoreVersions.BORON_VERSION + " are not supported");
+        }
+
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + " [version=" + getVersion() + "]";
+    }
 }