Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / DisableTrackingPayload.java
1 /*
2  * Copyright (c) 2019 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.io.ByteArrayDataOutput;
11 import com.google.common.io.ByteStreams;
12 import java.io.IOException;
13 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public final class DisableTrackingPayload extends AbstractIdentifiablePayload<ClientIdentifier> {
18     private static final Logger LOG = LoggerFactory.getLogger(DisableTrackingPayload.class);
19     @java.io.Serial
20     private static final long serialVersionUID = 1L;
21     private static final int PROXY_SIZE = externalizableProxySize(DT::new);
22
23     DisableTrackingPayload(final ClientIdentifier clientId, final byte[] serialized) {
24         super(clientId, serialized);
25     }
26
27     public static DisableTrackingPayload create(final ClientIdentifier clientId,
28             final int initialSerializedBufferCapacity) {
29         final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
30         try {
31             clientId.writeTo(out);
32         } catch (IOException e) {
33             // This should never happen
34             LOG.error("Failed to serialize {}", clientId, e);
35             throw new IllegalStateException("Failed to serialize " + clientId, e);
36         }
37         return new DisableTrackingPayload(clientId, out.toByteArray());
38     }
39
40     @Override
41     protected DT externalizableProxy(final byte[] serialized) {
42         return new DT(serialized);
43     }
44
45     @Override
46     protected int externalizableProxySize() {
47         return PROXY_SIZE;
48     }
49 }