* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.raft.persisted;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.io.Serializable;
import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
*
* @author Thomas Pantelis
*/
-public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, MigratedSerializable {
+public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
this.replicatedLogEntry = replicatedLogEntry;
}
+ static int estimatedSerializedSize(final ReplicatedLogEntry replicatedLogEntry) {
+ return 8 /* index */ + 8 /* term */ + replicatedLogEntry.getData().size()
+ + 400 /* estimated extra padding for class info */;
+ }
+
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
out.writeLong(replicatedLogEntry.getIndex());
private final long term;
private final Payload payload;
private boolean persistencePending;
- private final boolean migrated;
-
- private SimpleReplicatedLogEntry(long index, long term, Payload payload, boolean migrated) {
- this.index = index;
- this.term = term;
- this.payload = Preconditions.checkNotNull(payload);
- this.migrated = migrated;
- }
/**
* Constructs an instance.
* @param payload the payload
*/
public SimpleReplicatedLogEntry(final long index, final long term, final Payload payload) {
- this(index, term, payload, false);
- }
-
- @Deprecated
- public static ReplicatedLogEntry createMigrated(final long index, final long term, final Payload payload) {
- return new SimpleReplicatedLogEntry(index, term, payload, true);
+ this.index = index;
+ this.term = term;
+ this.payload = requireNonNull(payload);
}
@Override
}
@Override
- public void setPersistencePending(boolean pending) {
+ public void setPersistencePending(final boolean pending) {
persistencePending = pending;
}
- @Override
- public boolean isMigrated() {
- return migrated;
+ private Object writeReplace() {
+ return new Proxy(this);
}
- @Override
- public Object writeReplace() {
- return new Proxy(this);
+ public int estimatedSerializedSize() {
+ return Proxy.estimatedSerializedSize(this);
}
@Override
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}