e5bf72233c197952daac0152f4eef53d01737c17
[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     public ReplicatedLogImplEntry(final long index, final long term, final Payload payload) {
26         this.index = index;
27         this.term = term;
28         this.payload = Preconditions.checkNotNull(payload);
29     }
30
31     @Override
32     public Payload getData() {
33         return payload;
34     }
35
36     @Override
37     public long getTerm() {
38         return term;
39     }
40
41     @Override
42     public long getIndex() {
43         return index;
44     }
45
46     @Override
47     public int size() {
48         return getData().size();
49     }
50
51     @Override
52     public String toString() {
53         return "Entry{index=" + index + ", term=" + term + '}';
54     }
55 }