Switch to use PayloadVersion.CHLORINE_SR2
[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.DataInput;
13 import java.io.IOException;
14 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
15 import org.opendaylight.controller.cluster.raft.persisted.LegacySerializable;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Payload persisted when a local history is completely purged, i.e. the frontend has removed it from its tracking.
21  * It contains a {@link LocalHistoryIdentifier}.
22  *
23  * @author Robert Varga
24  */
25 public sealed class PurgeLocalHistoryPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
26     @Deprecated(since = "7.0.0", forRemoval = true)
27     private static final class Magnesium extends PurgeLocalHistoryPayload implements LegacySerializable {
28         @java.io.Serial
29         private static final long serialVersionUID = 1L;
30
31         Magnesium(final LocalHistoryIdentifier historyId, final byte[] serialized) {
32             super(historyId, serialized);
33         }
34     }
35
36     @Deprecated(since = "7.0.0", forRemoval = true)
37     private static final class Proxy extends AbstractProxy<LocalHistoryIdentifier> {
38         @java.io.Serial
39         private static final long serialVersionUID = 1L;
40
41         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
42         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
43         @SuppressWarnings("checkstyle:RedundantModifier")
44         public Proxy() {
45             // For Externalizable
46         }
47
48         @Override
49         protected LocalHistoryIdentifier readIdentifier(final DataInput in) throws IOException {
50             return LocalHistoryIdentifier.readFrom(in);
51         }
52
53         @Override
54         protected PurgeLocalHistoryPayload createObject(final LocalHistoryIdentifier identifier,
55                 final byte[] serialized) {
56             return new Magnesium(identifier, serialized);
57         }
58     }
59
60     private static final Logger LOG = LoggerFactory.getLogger(PurgeLocalHistoryPayload.class);
61     @java.io.Serial
62     private static final long serialVersionUID = 1L;
63     private static final int PROXY_SIZE = externalizableProxySize(PH::new);
64
65     PurgeLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
66         super(historyId, serialized);
67     }
68
69     public static PurgeLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
70             final int initialSerializedBufferCapacity) {
71         final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
72         try {
73             historyId.writeTo(out);
74         } catch (IOException e) {
75             // This should never happen
76             LOG.error("Failed to serialize {}", historyId, e);
77             throw new IllegalStateException("Failed to serialize " + historyId, e);
78         }
79         return new PurgeLocalHistoryPayload(historyId, out.toByteArray());
80     }
81
82     @Override
83     protected PH externalizableProxy(final byte[] serialized) {
84         return new PH(serialized);
85     }
86
87     @Override
88     protected int externalizableProxySize() {
89         return PROXY_SIZE;
90     }
91 }