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