Remove unneeded SuppressWarnings
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / Snapshot.java
1 /*
2  * Copyright (c) 2014 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.raft;
9
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.io.Serializable;
12 import java.util.List;
13 import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
14
15 /**
16  * Represents a snapshot of the raft data.
17  *
18  * @author Moiz Raja
19  * @author Thomas Pantelis
20  *
21  * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.Snapshot} instead.
22  */
23 @Deprecated
24 public class Snapshot implements Serializable {
25     private static final long serialVersionUID = -8298574936724056236L;
26
27     private final byte[] state;
28     private final List<ReplicatedLogEntry> unAppliedEntries;
29     private final long lastIndex;
30     private final long lastTerm;
31     private final long lastAppliedIndex;
32     private final long lastAppliedTerm;
33     private final long electionTerm;
34     private final String electionVotedFor;
35     private final ServerConfigurationPayload serverConfig;
36
37     private Snapshot(byte[] state, List<ReplicatedLogEntry> unAppliedEntries, long lastIndex, long lastTerm,
38             long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor,
39             ServerConfigurationPayload serverConfig) {
40         this.state = state;
41         this.unAppliedEntries = unAppliedEntries;
42         this.lastIndex = lastIndex;
43         this.lastTerm = lastTerm;
44         this.lastAppliedIndex = lastAppliedIndex;
45         this.lastAppliedTerm = lastAppliedTerm;
46         this.electionTerm = electionTerm;
47         this.electionVotedFor = electionVotedFor;
48         this.serverConfig = serverConfig;
49     }
50
51     public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
52             long lastAppliedIndex, long lastAppliedTerm) {
53         return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, -1, null, null);
54     }
55
56     public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
57             long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor) {
58         return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
59                 electionTerm, electionVotedFor, null);
60     }
61
62     public static Snapshot create(byte[] state, List<ReplicatedLogEntry> entries, long lastIndex, long lastTerm,
63             long lastAppliedIndex, long lastAppliedTerm, long electionTerm, String electionVotedFor,
64             ServerConfigurationPayload serverConfig) {
65         return new Snapshot(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm,
66                 electionTerm, electionVotedFor, serverConfig);
67     }
68
69     @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but "
70             + "this is OK since this class is merely a DTO and does not process the byte[] internally. "
71             + "Also it would be inefficient to create a return copy as the byte[] could be large.")
72     public byte[] getState() {
73         return state;
74     }
75
76     public List<ReplicatedLogEntry> getUnAppliedEntries() {
77         return unAppliedEntries;
78     }
79
80     public long getLastTerm() {
81         return lastTerm;
82     }
83
84     public long getLastAppliedIndex() {
85         return lastAppliedIndex;
86     }
87
88     public long getLastAppliedTerm() {
89         return lastAppliedTerm;
90     }
91
92     public long getLastIndex() {
93         return this.lastIndex;
94     }
95
96     public long getElectionTerm() {
97         return electionTerm;
98     }
99
100
101     public String getElectionVotedFor() {
102         return electionVotedFor;
103     }
104
105     public ServerConfigurationPayload getServerConfiguration() {
106         return serverConfig;
107     }
108
109     @Override
110     public String toString() {
111         return "Snapshot [lastIndex=" + lastIndex + ", lastTerm=" + lastTerm + ", lastAppliedIndex=" + lastAppliedIndex
112                 + ", lastAppliedTerm=" + lastAppliedTerm + ", unAppliedEntries size=" + unAppliedEntries.size()
113                 + ", state size=" + state.length + ", electionTerm=" + electionTerm + ", electionVotedFor="
114                 + electionVotedFor + ", ServerConfigPayload="  + serverConfig + "]";
115     }
116 }