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.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.raft.persisted.LegacySerializable;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Payload persisted when a transaction is aborted. It contains the transaction identifier.
22 * @author Robert Varga
24 public sealed class AbortTransactionPayload extends AbstractIdentifiablePayload<TransactionIdentifier> {
25 @Deprecated(since = "7.0.0", forRemoval = true)
26 private static final class Magnesium extends AbortTransactionPayload implements LegacySerializable {
28 private static final long serialVersionUID = 1L;
30 Magnesium(final TransactionIdentifier transactionId, final byte[] serialized) {
31 super(transactionId, serialized);
35 @Deprecated(since = "7.0.0", forRemoval = true)
36 private static final class Proxy extends AbstractProxy<TransactionIdentifier> {
38 private static final long serialVersionUID = 1L;
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")
48 protected TransactionIdentifier readIdentifier(final DataInput in) throws IOException {
49 return TransactionIdentifier.readFrom(in);
53 protected AbortTransactionPayload createObject(final TransactionIdentifier identifier,
54 final byte[] serialized) {
55 return new Magnesium(identifier, serialized);
59 private static final Logger LOG = LoggerFactory.getLogger(AbortTransactionPayload.class);
61 private static final long serialVersionUID = 1L;
62 private static final int PROXY_SIZE = externalizableProxySize(AT::new);
64 AbortTransactionPayload(final TransactionIdentifier transactionId, final byte[] serialized) {
65 super(transactionId, serialized);
68 public static AbortTransactionPayload create(final TransactionIdentifier transactionId,
69 final int initialSerializedBufferCapacity) {
70 final ByteArrayDataOutput out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
72 transactionId.writeTo(out);
73 } catch (IOException e) {
74 // This should never happen
75 LOG.error("Failed to serialize {}", transactionId, e);
76 throw new IllegalStateException("Failed to serialized " + transactionId, e);
78 return new AbortTransactionPayload(transactionId, out.toByteArray());
82 protected AT externalizableProxy(final byte[] serialized) {
83 return new AT(serialized);
87 protected int externalizableProxySize() {