fd35046f04630461da0128ea7aaadd243df48a1c
[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.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Abstract base class for snapshots of the ShardDataTree.
21  *
22  * @author Robert Varga
23  */
24 @Beta
25 public abstract class ShardDataTreeSnapshot {
26     private static final Logger LOG = LoggerFactory.getLogger(ShardDataTreeSnapshot.class);
27
28     ShardDataTreeSnapshot() {
29         // Hidden to prevent subclassing from outside of this package
30     }
31
32     public static ShardDataTreeSnapshot deserialize(final ObjectInput in) throws IOException {
33         final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.versionedDeserialize(in);
34
35         // Make sure we consume all bytes, otherwise something went very wrong
36         final int bytesLeft = in.available();
37         if (bytesLeft != 0) {
38             throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
39         }
40
41
42         return ret;
43     }
44
45     /**
46      * Get the root data node contained in this snapshot.
47      *
48      * @return An optional root node.
49      */
50     public abstract Optional<NormalizedNode<?, ?>> getRootNode();
51
52     public abstract void serialize(ObjectOutput out) throws IOException;
53 }
54