2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.raft;
11 import com.google.common.base.Preconditions;
12 import java.io.Serializable;
13 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
16 * A {@link ReplicatedLogEntry} implementation.
18 public class ReplicatedLogImplEntry implements ReplicatedLogEntry, Serializable {
19 private static final long serialVersionUID = -9085798014576489130L;
21 private final long index;
22 private final long term;
23 private final Payload payload;
24 private transient boolean persistencePending = false;
27 * Constructs an instance.
29 * @param index the index
30 * @param term the term
31 * @param payload the payload
33 public ReplicatedLogImplEntry(final long index, final long term, final Payload payload) {
36 this.payload = Preconditions.checkNotNull(payload);
40 public Payload getData() {
45 public long getTerm() {
50 public long getIndex() {
56 return getData().size();
60 public boolean isPersistencePending() {
61 return persistencePending;
65 public void setPersistencePending(boolean pending) {
66 persistencePending = pending;
70 public int hashCode() {
73 result = prime * result + payload.hashCode();
74 result = prime * result + (int) (index ^ index >>> 32);
75 result = prime * result + (int) (term ^ term >>> 32);
80 public boolean equals(Object obj) {
89 if (getClass() != obj.getClass()) {
93 ReplicatedLogImplEntry other = (ReplicatedLogImplEntry) obj;
94 if (payload == null) {
95 if (other.payload != null) {
98 } else if (!payload.equals(other.payload)) {
102 if (index != other.index) {
106 if (term != other.term) {
114 public String toString() {
115 return "Entry{index=" + index + ", term=" + term + '}';