Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / UT.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.persisted;
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 UpdateElectionTerm}.
21  */
22 final class UT implements Externalizable {
23     @java.io.Serial
24     private static final long serialVersionUID = 1L;
25
26     private UpdateElectionTerm updateElectionTerm;
27
28     @SuppressWarnings("checkstyle:RedundantModifier")
29     public UT() {
30         // For Externalizable
31     }
32
33     UT(final UpdateElectionTerm updateElectionTerm) {
34         this.updateElectionTerm = requireNonNull(updateElectionTerm);
35     }
36
37     @Override
38     public void writeExternal(final ObjectOutput out) throws IOException {
39         WritableObjects.writeLong(out, updateElectionTerm.getCurrentTerm());
40         out.writeObject(updateElectionTerm.getVotedFor());
41     }
42
43     @Override
44     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45         updateElectionTerm = new UpdateElectionTerm(WritableObjects.readLong(in), (String) in.readObject());
46     }
47
48     @java.io.Serial
49     private Object readResolve() {
50         return verifyNotNull(updateElectionTerm);
51     }
52 }