416297d81a0fe5bc8d03dcceb052cb6a1b1f6fc4
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ModifyTransactionRequest.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 com.google.common.annotations.Beta;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.collect.ImmutableList;
14 import java.util.List;
15 import java.util.Optional;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
18
19 /**
20  * A transaction request to apply a particular set of operations on top of the current transaction. This message is
21  * used to also finish a transaction by specifying a {@link PersistenceProtocol}.
22  *
23  * @author Robert Varga
24  */
25 @Beta
26 public final class ModifyTransactionRequest extends TransactionRequest<ModifyTransactionRequest> {
27     private static final long serialVersionUID = 1L;
28     private final List<TransactionModification> modifications;
29     private final PersistenceProtocol protocol;
30
31     ModifyTransactionRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo,
32         final List<TransactionModification> modifications, final PersistenceProtocol protocol) {
33         super(target, sequence, replyTo);
34         this.modifications = ImmutableList.copyOf(modifications);
35         this.protocol = protocol;
36     }
37
38     public Optional<PersistenceProtocol> getPersistenceProtocol() {
39         return Optional.ofNullable(protocol);
40     }
41
42     public List<TransactionModification> getModifications() {
43         return modifications;
44     }
45
46     @Override
47     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
48         return super.addToStringAttributes(toStringHelper).add("operations", modifications).add("protocol", protocol);
49     }
50
51     @Override
52     protected ModifyTransactionRequestProxyV1 externalizableProxy(final ABIVersion version) {
53         return new ModifyTransactionRequestProxyV1(this);
54     }
55
56     @Override
57     protected ModifyTransactionRequest cloneAsVersion(final ABIVersion version) {
58         return this;
59     }
60 }