2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.persisted;
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;
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}.
23 * @author Robert Varga
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 {
29 private static final long serialVersionUID = 1L;
31 Magnesium(final LocalHistoryIdentifier historyId, final byte[] serialized) {
32 super(historyId, serialized);
36 @Deprecated(since = "7.0.0", forRemoval = true)
37 private static final class Proxy extends AbstractProxy<LocalHistoryIdentifier> {
39 private static final long serialVersionUID = 1L;
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")
49 protected LocalHistoryIdentifier readIdentifier(final DataInput in) throws IOException {
50 return LocalHistoryIdentifier.readFrom(in);
54 protected PurgeLocalHistoryPayload createObject(final LocalHistoryIdentifier identifier,
55 final byte[] serialized) {
56 return new Magnesium(identifier, serialized);
60 private static final Logger LOG = LoggerFactory.getLogger(PurgeLocalHistoryPayload.class);
62 private static final long serialVersionUID = 1L;
63 private static final int PROXY_SIZE = externalizableProxySize(PH::new);
65 PurgeLocalHistoryPayload(final LocalHistoryIdentifier historyId, final byte[] serialized) {
66 super(historyId, serialized);
69 public static PurgeLocalHistoryPayload create(final LocalHistoryIdentifier historyId,
70 final int initialSerializedBufferCapacity) {
71 final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
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);
79 return new PurgeLocalHistoryPayload(historyId, out.toByteArray());
83 protected PH externalizableProxy(final byte[] serialized) {
84 return new PH(serialized);
88 protected int externalizableProxySize() {