BUG-5280: add CommitTransactionPayload
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / AbortTransactionPayload.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.TransactionIdentifier;
15
16 /**
17  * Payload persisted when a transaction is aborted. It contains the transaction identifier.
18  *
19  * @author Robert Varga
20  */
21 public final class AbortTransactionPayload extends AbstractIdentifiablePayload<TransactionIdentifier> {
22     private static final class Proxy extends AbstractProxy<TransactionIdentifier> {
23         private static final long serialVersionUID = 1L;
24
25         public Proxy() {
26             // For Externalizable
27         }
28
29         Proxy(final byte[] serialized) {
30             super(serialized);
31         }
32
33         @Override
34         protected TransactionIdentifier readIdentifier(final DataInput in) throws IOException {
35             return TransactionIdentifier.readFrom(in);
36         }
37
38         @Override
39         protected AbortTransactionPayload createObject(final TransactionIdentifier identifier,
40                 final byte[] serialized) {
41             return new AbortTransactionPayload(identifier, serialized);
42         }
43     }
44
45     private static final long serialVersionUID = 1L;
46
47     AbortTransactionPayload(final TransactionIdentifier transactionId, final byte[] serialized) {
48         super(transactionId, serialized);
49     }
50
51     public static AbortTransactionPayload create(final TransactionIdentifier transactionId) throws IOException {
52         final ByteArrayDataOutput out = ByteStreams.newDataOutput();
53         transactionId.writeTo(out);
54         return new AbortTransactionPayload(transactionId, out.toByteArray());
55     }
56
57     @Override
58     protected Proxy externalizableProxy(final byte[] serialized) {
59         return new Proxy(serialized);
60     }
61 }