Bug 4564: Implement GetSnapshot message in ShardManager
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / DatastoreSnapshot.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.messages;
9
10 import com.google.common.base.Preconditions;
11 import java.io.Serializable;
12 import java.util.List;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15
16 /**
17  * Stores a snapshot of the internal state of a data store.
18  *
19  * @author Thomas Pantelis
20  */
21 public class DatastoreSnapshot implements Serializable {
22     private static final long serialVersionUID = 1L;
23
24     private final String type;
25     private final byte[] shardManagerSnapshot;
26     private final List<ShardSnapshot> shardSnapshots;
27
28     public DatastoreSnapshot(@Nonnull String type, @Nullable byte[] shardManagerSnapshot,
29             @Nonnull List<ShardSnapshot> shardSnapshots) {
30         this.type = Preconditions.checkNotNull(type);
31         this.shardManagerSnapshot = shardManagerSnapshot;
32         this.shardSnapshots = Preconditions.checkNotNull(shardSnapshots);
33     }
34
35     @Nonnull
36     public String getType() {
37         return type;
38     }
39
40     @Nullable
41     public byte[] getShardManagerSnapshot() {
42         return shardManagerSnapshot;
43     }
44
45     @Nonnull
46     public List<ShardSnapshot> getShardSnapshots() {
47         return shardSnapshots;
48     }
49
50     public static class ShardSnapshot implements Serializable {
51         private static final long serialVersionUID = 1L;
52
53         private final String name;
54         private final byte[] snapshot;
55
56         public ShardSnapshot(@Nonnull String name, @Nonnull byte[] snapshot) {
57             this.name = Preconditions.checkNotNull(name);
58             this.snapshot = Preconditions.checkNotNull(snapshot);
59         }
60
61         @Nonnull
62         public String getName() {
63             return name;
64         }
65
66         @Nonnull
67         public byte[] getSnapshot() {
68             return snapshot;
69         }
70     }
71 }