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