Fix FindBugs warnings in cds-access-api and enable enforcement
[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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import java.util.List;
16 import java.util.Optional;
17 import org.opendaylight.controller.cluster.access.ABIVersion;
18 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
19
20 /**
21  * A transaction request to apply a particular set of operations on top of the current transaction. This message is
22  * used to also finish a transaction by specifying a {@link PersistenceProtocol}.
23  *
24  * @author Robert Varga
25  */
26 @Beta
27 public final class ModifyTransactionRequest extends TransactionRequest<ModifyTransactionRequest> {
28     private static final long serialVersionUID = 1L;
29
30     @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
31             + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
32             + "aren't serialized. FindBugs does not recognize this.")
33     private final List<TransactionModification> modifications;
34     private final PersistenceProtocol protocol;
35
36     ModifyTransactionRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo,
37         final List<TransactionModification> modifications, final PersistenceProtocol protocol) {
38         super(target, sequence, replyTo);
39         this.modifications = ImmutableList.copyOf(modifications);
40         this.protocol = protocol;
41     }
42
43     public Optional<PersistenceProtocol> getPersistenceProtocol() {
44         return Optional.ofNullable(protocol);
45     }
46
47     public List<TransactionModification> getModifications() {
48         return modifications;
49     }
50
51     @Override
52     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
53         return super.addToStringAttributes(toStringHelper).add("operations", modifications).add("protocol", protocol);
54     }
55
56     @Override
57     protected ModifyTransactionRequestProxyV1 externalizableProxy(final ABIVersion version) {
58         return new ModifyTransactionRequestProxyV1(this);
59     }
60
61     @Override
62     protected ModifyTransactionRequest cloneAsVersion(final ABIVersion version) {
63         return this;
64     }
65 }