3c5e86b21d6abfb49bcbd7d331de73aeba9ded8d
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / 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.persisted;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.io.Serializable;
14 import java.util.List;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17
18 /**
19  * Stores a snapshot of the internal state of a data store.
20  *
21  * @author Thomas Pantelis
22  */
23 public class DatastoreSnapshot implements Serializable {
24     private static final long serialVersionUID = 1L;
25
26     private final String type;
27     private final byte[] shardManagerSnapshot;
28     private final List<ShardSnapshot> shardSnapshots;
29
30     @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Stores a reference to an externally mutable byte[] "
31             + "object but this is OK since this class is merely a DTO and does not process byte[] internally. "
32             + "Also it would be inefficient to create a return copy as the byte[] could be large.")
33     public DatastoreSnapshot(@Nonnull String type, @Nullable byte[] shardManagerSnapshot,
34             @Nonnull List<ShardSnapshot> shardSnapshots) {
35         this.type = Preconditions.checkNotNull(type);
36         this.shardManagerSnapshot = shardManagerSnapshot;
37         this.shardSnapshots = ImmutableList.copyOf(Preconditions.checkNotNull(shardSnapshots));
38     }
39
40     @Nonnull
41     public String getType() {
42         return type;
43     }
44
45     @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but "
46             + "this is OK since this class is merely a DTO and does not process byte[] internally. "
47             + "Also it would be inefficient to create a return copy as the byte[] could be large.")
48     @Nullable
49     public byte[] getShardManagerSnapshot() {
50         return shardManagerSnapshot;
51     }
52
53     @Nonnull
54     public List<ShardSnapshot> getShardSnapshots() {
55         return shardSnapshots;
56     }
57
58     public static class ShardSnapshot implements Serializable {
59         private static final long serialVersionUID = 1L;
60
61         private final String name;
62         private final byte[] snapshot;
63
64         public ShardSnapshot(@Nonnull String name, @Nonnull byte[] snapshot) {
65             this.name = Preconditions.checkNotNull(name);
66             this.snapshot = Preconditions.checkNotNull(snapshot);
67         }
68
69         @Nonnull
70         public String getName() {
71             return name;
72         }
73
74         @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but "
75                 + "this is OK since this class is merely a DTO and does not process byte[] internally. "
76                 + "Also it would be inefficient to create a return copy as the byte[] could be large.")
77         @Nonnull
78         public byte[] getSnapshot() {
79             return snapshot;
80         }
81     }
82 }