2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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 static java.util.Objects.requireNonNull;
12 import com.google.common.io.ByteStreams;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import java.io.IOException;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
17 import org.opendaylight.controller.cluster.datastore.utils.ImmutableUnsignedLongSet;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Payload persisted when a local history is instructed some transaction identifiers, i.e. the frontend has used them
23 * for other purposes. It contains a {@link LocalHistoryIdentifier} and a list of transaction identifiers within that
26 public final class SkipTransactionsPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
27 private static final Logger LOG = LoggerFactory.getLogger(SkipTransactionsPayload.class);
29 private static final long serialVersionUID = 1L;
30 private static final int PROXY_SIZE = externalizableProxySize(ST::new);
32 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Handled via externalizable proxy")
33 private final @NonNull ImmutableUnsignedLongSet transactionIds;
35 SkipTransactionsPayload(final @NonNull LocalHistoryIdentifier historyId,
36 final byte @NonNull [] serialized, final ImmutableUnsignedLongSet transactionIds) {
37 super(historyId, serialized);
38 this.transactionIds = requireNonNull(transactionIds);
41 public static @NonNull SkipTransactionsPayload create(final LocalHistoryIdentifier historyId,
42 final ImmutableUnsignedLongSet transactionIds, final int initialSerializedBufferCapacity) {
43 final var out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
45 historyId.writeTo(out);
46 transactionIds.writeTo(out);
47 } catch (IOException e) {
48 // This should never happen
49 LOG.error("Failed to serialize {} ids {}", historyId, transactionIds, e);
50 throw new IllegalStateException("Failed to serialize " + historyId + " ids " + transactionIds, e);
53 return new SkipTransactionsPayload(historyId, out.toByteArray(), transactionIds);
56 public @NonNull ImmutableUnsignedLongSet getTransactionIds() {
57 return transactionIds;
61 protected ST externalizableProxy(final byte[] serialized) {
62 return new ST(serialized);
66 protected int externalizableProxySize() {