X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fmessages%2FVersionedExternalizableMessage.java;h=f28250b766ba86885dd909aac78a91824682f8c4;hp=2a660fa4b2ab0804b9bb91670bc0d2129c7f6d0e;hb=c9587253579a7b34f4c397a254f83890d4d3ba03;hpb=8aeb4a575b7b5988e3a50d6c9a4c05418c926fd9 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/VersionedExternalizableMessage.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/VersionedExternalizableMessage.java index 2a660fa4b2..f28250b766 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/VersionedExternalizableMessage.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/VersionedExternalizableMessage.java @@ -11,6 +11,9 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion; /** * Abstract base class for a versioned Externalizable message. @@ -20,26 +23,54 @@ import java.io.ObjectOutput; public abstract class VersionedExternalizableMessage implements Externalizable, SerializableMessage { private static final long serialVersionUID = 1L; - private short version; + private short version = DataStoreVersions.CURRENT_VERSION; public VersionedExternalizableMessage() { } - public VersionedExternalizableMessage(short version) { - this.version = version; + public VersionedExternalizableMessage(final short version) { + this.version = version <= DataStoreVersions.CURRENT_VERSION ? version : DataStoreVersions.CURRENT_VERSION; } public short getVersion() { return version; } + protected final @NonNull NormalizedNodeStreamVersion getStreamVersion() { + if (version >= DataStoreVersions.MAGNESIUM_VERSION) { + return NormalizedNodeStreamVersion.MAGNESIUM; + } else if (version == DataStoreVersions.SODIUM_SR1_VERSION) { + return NormalizedNodeStreamVersion.SODIUM_SR1; + } else if (version == DataStoreVersions.NEON_SR2_VERSION) { + return NormalizedNodeStreamVersion.NEON_SR2; + } else { + return NormalizedNodeStreamVersion.LITHIUM; + } + } + @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { version = in.readShort(); } @Override - public void writeExternal(ObjectOutput out) throws IOException { + public void writeExternal(final ObjectOutput out) throws IOException { out.writeShort(version); } + + @Override + public final Object toSerializable() { + final short ver = getVersion(); + if (ver < DataStoreVersions.BORON_VERSION) { + throw new UnsupportedOperationException("Version " + ver + + " is older than the oldest version supported version " + DataStoreVersions.BORON_VERSION); + } + + return this; + } + + @Override + public String toString() { + return getClass().getSimpleName() + " [version=" + getVersion() + "]"; + } }