2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.messages;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.opendaylight.yangtools.concepts.WritableObjects;
20 * Serialization proxy for {@link InstallSnapshotReply}.
22 final class IR implements Externalizable {
24 private static final long serialVersionUID = 1L;
27 private static final int SUCCESS = 0x10;
29 private InstallSnapshotReply installSnapshotReply;
31 @SuppressWarnings("checkstyle:RedundantModifier")
36 IR(final InstallSnapshotReply installSnapshotReply) {
37 this.installSnapshotReply = requireNonNull(installSnapshotReply);
41 public void writeExternal(final ObjectOutput out) throws IOException {
42 WritableObjects.writeLong(out, installSnapshotReply.getTerm(), installSnapshotReply.isSuccess() ? SUCCESS : 0);
43 out.writeObject(installSnapshotReply.getFollowerId());
44 out.writeInt(installSnapshotReply.getChunkIndex());
48 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
49 final byte hdr = WritableObjects.readLongHeader(in);
50 final int flags = WritableObjects.longHeaderFlags(hdr);
52 long term = WritableObjects.readLongBody(in, hdr);
53 String followerId = (String) in.readObject();
54 int chunkIndex = in.readInt();
56 installSnapshotReply = new InstallSnapshotReply(term, followerId, chunkIndex, (flags & SUCCESS) != 0);
60 private Object readResolve() {
61 return verifyNotNull(installSnapshotReply);