1ff69e7f4a0ccf198c11333f013bd1d46b7c910a
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ReplicatedLogImplEntry.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
9 package org.opendaylight.controller.cluster.raft;
10
11 import com.google.common.base.Preconditions;
12 import java.io.Serializable;
13 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
14
15 /**
16  * A {@link ReplicatedLogEntry} implementation.
17  */
18 public final class ReplicatedLogImplEntry implements ReplicatedLogEntry, Serializable {
19     private static final long serialVersionUID = -9085798014576489130L;
20
21     private final long index;
22     private final long term;
23     private final Payload payload;
24
25     /**
26      * Constructs an instance.
27      *
28      * @param index the index
29      * @param term the term
30      * @param payload the payload
31      */
32     public ReplicatedLogImplEntry(final long index, final long term, final Payload payload) {
33         this.index = index;
34         this.term = term;
35         this.payload = Preconditions.checkNotNull(payload);
36     }
37
38     @Override
39     public Payload getData() {
40         return payload;
41     }
42
43     @Override
44     public long getTerm() {
45         return term;
46     }
47
48     @Override
49     public long getIndex() {
50         return index;
51     }
52
53     @Override
54     public int size() {
55         return getData().size();
56     }
57
58     @Override
59     public String toString() {
60         return "Entry{index=" + index + ", term=" + term + '}';
61     }
62 }