BUG-5280: introduce base Transaction request/success
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / TransactionCanCommitSuccessProxyV1.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.access.commands;
9
10 import akka.actor.ActorRef;
11 import akka.serialization.JavaSerializer;
12 import akka.serialization.Serialization;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
17
18 /**
19  * Externalizable proxy for use with {@link TransactionCanCommitSuccess}. It implements the initial (Boron)
20  * serialization format.
21  *
22  * @author Robert Varga
23  */
24 final class TransactionCanCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy<TransactionCanCommitSuccess> {
25     private static final long serialVersionUID = 1L;
26     private ActorRef cohort;
27
28     public TransactionCanCommitSuccessProxyV1() {
29         // For Externalizable
30     }
31
32     TransactionCanCommitSuccessProxyV1(final TransactionCanCommitSuccess success) {
33         super(success);
34         this.cohort = success.getCohort();
35     }
36
37     @Override
38     public void writeExternal(final ObjectOutput out) throws IOException {
39         super.writeExternal(out);
40         out.writeUTF(Serialization.serializedActorPath(cohort));
41     }
42
43     @Override
44     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45         super.readExternal(in);
46         cohort = JavaSerializer.currentSystem().value().provider().resolveActorRef(in.readUTF());
47     }
48
49     @Override
50     protected TransactionCanCommitSuccess createSuccess(final TransactionIdentifier target, final long sequence,
51             final long retry) {
52         return new TransactionCanCommitSuccess(target, sequence, retry, cohort);
53     }
54 }