Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / PurgeLocalHistoryPayload.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.LocalHistoryIdentifier;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Payload persisted when a local history is completely purged, i.e. the frontend has removed it from its tracking.
19  * It contains a {@link LocalHistoryIdentifier}.
20  *
21  * @author Robert Varga
22  */
23 public final class PurgeLocalHistoryPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
24     private static final Logger LOG = LoggerFactory.getLogger(PurgeLocalHistoryPayload.class);
25     @java.io.Serial
26     private static final long serialVersionUID = 1L;
27     private static final int PROXY_SIZE = externalizableProxySize(PH::new);
28
29     PurgeLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
30         super(historyId, serialized);
31     }
32
33     public static PurgeLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
34             final int initialSerializedBufferCapacity) {
35         final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
36         try {
37             historyId.writeTo(out);
38         } catch (IOException e) {
39             // This should never happen
40             LOG.error("Failed to serialize {}", historyId, e);
41             throw new IllegalStateException("Failed to serialize " + historyId, e);
42         }
43         return new PurgeLocalHistoryPayload(historyId, out.toByteArray());
44     }
45
46     @Override
47     protected PH externalizableProxy(final byte[] serialized) {
48         return new PH(serialized);
49     }
50
51     @Override
52     protected int externalizableProxySize() {
53         return PROXY_SIZE;
54     }
55 }