Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / FM.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.datastore.persisted;
9
10 import com.google.common.collect.ImmutableList;
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import java.util.List;
16
17 /**
18  * Externalizable proxy for {@link FrontendShardDataTreeSnapshotMetadata}.
19  */
20 final class FM implements Externalizable {
21     @java.io.Serial
22     private static final long serialVersionUID = 1L;
23
24     private List<FrontendClientMetadata> clients;
25
26     @SuppressWarnings("checkstyle:RedundantModifier")
27     public FM() {
28         // For Externalizable
29     }
30
31     FM(final FrontendShardDataTreeSnapshotMetadata metadata) {
32         clients = metadata.getClients();
33     }
34
35     @Override
36     public void writeExternal(final ObjectOutput out) throws IOException {
37         out.writeInt(clients.size());
38         for (var c : clients) {
39             c.writeTo(out);
40         }
41     }
42
43     @Override
44     public void readExternal(final ObjectInput in) throws IOException {
45         final int size = in.readInt();
46         final var builder = ImmutableList.<FrontendClientMetadata>builderWithExpectedSize(size);
47         for (int i = 0; i < size ; ++i) {
48             builder.add(FrontendClientMetadata.readFrom(in));
49         }
50         clients = builder.build();
51     }
52
53     @java.io.Serial
54     private Object readResolve() {
55         return new FrontendShardDataTreeSnapshotMetadata(clients);
56     }
57 }