Switch to use PayloadVersion.CHLORINE_SR2
[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.DataInput;
13 import java.io.IOException;
14 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
15 import org.opendaylight.controller.cluster.raft.persisted.LegacySerializable;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public sealed class DisableTrackingPayload extends AbstractIdentifiablePayload<ClientIdentifier> {
20     @Deprecated(since = "7.0.0", forRemoval = true)
21     private static final class Magnesium extends DisableTrackingPayload implements LegacySerializable {
22         @java.io.Serial
23         private static final long serialVersionUID = 1L;
24
25         Magnesium(final ClientIdentifier clientId, final byte[] serialized) {
26             super(clientId, serialized);
27         }
28     }
29
30     @Deprecated(since = "7.0.0", forRemoval = true)
31     private static final class Proxy extends AbstractProxy<ClientIdentifier> {
32         @java.io.Serial
33         private static final long serialVersionUID = -5490519942445085251L;
34
35         @SuppressWarnings("checkstyle:RedundantModifier")
36         public Proxy() {
37             // For Externalizable
38         }
39
40         @Override
41         protected ClientIdentifier readIdentifier(final DataInput in) throws IOException {
42             return ClientIdentifier.readFrom(in);
43         }
44
45         @Override
46         protected DisableTrackingPayload createObject(final ClientIdentifier identifier,
47                 final byte[] serialized) {
48             return new Magnesium(identifier, serialized);
49         }
50     }
51
52     private static final Logger LOG = LoggerFactory.getLogger(DisableTrackingPayload.class);
53     @java.io.Serial
54     private static final long serialVersionUID = 1L;
55     private static final int PROXY_SIZE = externalizableProxySize(DT::new);
56
57     DisableTrackingPayload(final ClientIdentifier clientId, final byte[] serialized) {
58         super(clientId, serialized);
59     }
60
61     public static DisableTrackingPayload create(final ClientIdentifier clientId,
62             final int initialSerializedBufferCapacity) {
63         final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
64         try {
65             clientId.writeTo(out);
66         } catch (IOException e) {
67             // This should never happen
68             LOG.error("Failed to serialize {}", clientId, e);
69             throw new IllegalStateException("Failed to serialize " + clientId, e);
70         }
71         return new DisableTrackingPayload(clientId, out.toByteArray());
72     }
73
74     @Override
75     protected DT externalizableProxy(final byte[] serialized) {
76         return new DT(serialized);
77     }
78
79     @Override
80     protected int externalizableProxySize() {
81         return PROXY_SIZE;
82     }
83 }