Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / MN.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.access.concepts;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.nio.charset.StandardCharsets;
17
18 /**
19  * Serialization proxy for {@link MemberName}.
20  */
21 final class MN implements Externalizable {
22     @java.io.Serial
23     private static final long serialVersionUID = 1L;
24
25     private byte[] serialized;
26
27     @SuppressWarnings("checkstyle:RedundantModifier")
28     public MN() {
29         // for Externalizable
30     }
31
32     MN(final byte[] serialized) {
33         this.serialized = requireNonNull(serialized);
34     }
35
36     @Override
37     public void writeExternal(final ObjectOutput out) throws IOException {
38         out.writeInt(serialized.length);
39         out.write(serialized);
40     }
41
42     @Override
43     public void readExternal(final ObjectInput in) throws IOException {
44         serialized = new byte[in.readInt()];
45         in.readFully(serialized);
46     }
47
48     @java.io.Serial
49     private Object readResolve() {
50         // TODO: consider caching instances here
51         return new MemberName(new String(serialized, StandardCharsets.UTF_8), serialized);
52     }
53 }