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
8 package org.opendaylight.controller.cluster.raft.persisted;
10 import static java.util.Objects.requireNonNull;
12 import java.io.Serializable;
13 import org.apache.commons.lang3.SerializationUtils;
14 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
15 import org.opendaylight.controller.cluster.raft.messages.Payload;
18 * A {@link ReplicatedLogEntry} implementation.
20 * @author Thomas Pantelis
22 public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
24 private static final long serialVersionUID = 1L;
25 // Estimate to how big the proxy is. Note this includes object stream overhead, so it is a bit conservative.
26 private static final int PROXY_SIZE = SerializationUtils.serialize(new LE((Void) null)).length;
28 private final long index;
29 private final long term;
30 private final Payload payload;
31 private boolean persistencePending;
34 * Constructs an instance.
36 * @param index the index
37 * @param term the term
38 * @param payload the payload
40 public SimpleReplicatedLogEntry(final long index, final long term, final Payload payload) {
43 this.payload = requireNonNull(payload);
47 public Payload getData() {
52 public long getTerm() {
57 public long getIndex() {
63 return payload.size();
67 public int serializedSize() {
68 return PROXY_SIZE + payload.serializedSize();
72 public boolean isPersistencePending() {
73 return persistencePending;
77 public void setPersistencePending(final boolean pending) {
78 persistencePending = pending;
82 public int hashCode() {
85 result = prime * result + payload.hashCode();
86 result = prime * result + (int) (index ^ index >>> 32);
87 result = prime * result + (int) (term ^ term >>> 32);
92 public boolean equals(final Object obj) {
93 return this == obj || obj instanceof SimpleReplicatedLogEntry other && index == other.index
94 && term == other.term && payload.equals(other.payload);
98 public String toString() {
99 return "SimpleReplicatedLogEntry [index=" + index + ", term=" + term + ", payload=" + payload + "]";
103 private Object writeReplace() {