Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / IR.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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 package org.opendaylight.controller.cluster.raft.messages;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
12
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;
18
19 /**
20  * Serialization proxy for {@link InstallSnapshotReply}.
21  */
22 final class IR implements Externalizable {
23     @java.io.Serial
24     private static final long serialVersionUID = 1L;
25
26     // Flags
27     private static final int SUCCESS = 0x10;
28
29     private InstallSnapshotReply installSnapshotReply;
30
31     @SuppressWarnings("checkstyle:RedundantModifier")
32     public IR() {
33         // For Externalizable
34     }
35
36     IR(final InstallSnapshotReply installSnapshotReply) {
37         this.installSnapshotReply = requireNonNull(installSnapshotReply);
38     }
39
40     @Override
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());
45     }
46
47     @Override
48     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
49         final byte hdr = WritableObjects.readLongHeader(in);
50         final int flags = WritableObjects.longHeaderFlags(hdr);
51
52         long term = WritableObjects.readLongBody(in, hdr);
53         String followerId = (String) in.readObject();
54         int chunkIndex = in.readInt();
55
56         installSnapshotReply = new InstallSnapshotReply(term, followerId, chunkIndex, (flags & SUCCESS) != 0);
57     }
58
59     @java.io.Serial
60     private Object readResolve() {
61         return verifyNotNull(installSnapshotReply);
62     }
63 }