X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FShardDataTreeSnapshot.java;h=85d1143a891f743fdc652f1847f4b047c412e8aa;hb=2bc808b02828fde2da3dd9bfabab658156faa3c6;hp=ef901019a586ecd93e826fa7c3a14fc4856fd22e;hpb=b70b396725749d3fd6ca761f02f4b630f6f4f1ce;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java index ef901019a5..85d1143a89 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java @@ -12,9 +12,10 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Optional; -import javax.annotation.Nonnull; -import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +33,8 @@ public abstract class ShardDataTreeSnapshot { // Hidden to prevent subclassing from outside of this package } - public static ShardDataTreeSnapshot deserialize(final byte[] bytes) throws IOException { + @Deprecated + public static ShardDataTreeSnapshot deserializePreCarbon(final byte[] bytes) throws IOException { /** * Unfortunately versions prior to Boron did not include any way to evolve the snapshot format and contained * only the raw data stored in the datastore. Furthermore utilities involved do not check if the array is @@ -49,9 +51,9 @@ public abstract class ShardDataTreeSnapshot { } try { - try (final InputStream is = new ByteArrayInputStream(bytes)) { - try (final DataInputStream dis = new DataInputStream(is)) { - final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserialize(dis); + try (InputStream is = new ByteArrayInputStream(bytes)) { + try (DataInputStream dis = new DataInputStream(is)) { + final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserializePreCarbon(dis); // Make sure we consume all bytes, otherwise something went very wrong final int bytesLeft = dis.available(); @@ -69,6 +71,19 @@ public abstract class ShardDataTreeSnapshot { } } + public static ShardDataTreeSnapshot deserialize(final ObjectInput in) throws IOException { + final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.versionedDeserialize(in); + + // Make sure we consume all bytes, otherwise something went very wrong + final int bytesLeft = in.available(); + if (bytesLeft != 0) { + throw new IOException("Deserialization left " + bytesLeft + " in the buffer"); + } + + + return ret; + } + /** * Get the root data node contained in this snapshot. * @@ -76,14 +91,9 @@ public abstract class ShardDataTreeSnapshot { */ public abstract Optional> getRootNode(); - /** - * Serialize this snapshot into a byte array for persistence. - * - * @return Serialized snapshot - * @throws IOException when a serialization problem occurs - */ - public abstract @Nonnull byte[] serialize() throws IOException; + public abstract void serialize(ObjectOutput out) throws IOException; + @Deprecated private static boolean isLegacyStream(final byte[] bytes) { if (bytes.length < 2) { // Versioned streams have at least two bytes