Bump odlparent/yangtools/mdsal
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / ShardDataTreeSnapshot.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.persisted;
9
10 import com.google.common.annotations.Beta;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 /**
19  * Abstract base class for snapshots of the ShardDataTree.
20  *
21  * @author Robert Varga
22  */
23 @Beta
24 public abstract class ShardDataTreeSnapshot {
25     ShardDataTreeSnapshot() {
26         // Hidden to prevent subclassing from outside of this package
27     }
28
29     public static @NonNull ShardSnapshotState deserialize(final ObjectInput in) throws IOException {
30         final ShardSnapshotState ret = AbstractVersionedShardDataTreeSnapshot.versionedDeserialize(in);
31
32         // Make sure we consume all bytes, otherwise something went very wrong
33         final int bytesLeft = in.available();
34         if (bytesLeft != 0) {
35             throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
36         }
37
38         return ret;
39     }
40
41     /**
42      * Get the root data node contained in this snapshot.
43      *
44      * @return An optional root node.
45      */
46     public abstract Optional<NormalizedNode> getRootNode();
47
48     public abstract void serialize(ObjectOutput out) throws IOException;
49 }
50