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 / CommitLocalTransactionRequest.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.base.Preconditions;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
18
19 /**
20  * Request to commit a local transaction. Since local transactions do not introduce state on the backend until they
21  * are ready, this message carries a complete set of modifications.
22  *
23  * @author Robert Varga
24  */
25 @Beta
26 public final class CommitLocalTransactionRequest
27         extends AbstractLocalTransactionRequest<CommitLocalTransactionRequest> {
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 DataTreeModification mod;
34     private final boolean coordinated;
35
36     public CommitLocalTransactionRequest(@Nonnull final TransactionIdentifier identifier,
37             @Nonnull final ActorRef replyTo, @Nonnull final DataTreeModification mod, final boolean coordinated) {
38         super(identifier, 0, replyTo);
39         this.mod = Preconditions.checkNotNull(mod);
40         this.coordinated = coordinated;
41     }
42
43     public DataTreeModification getModification() {
44         return mod;
45     }
46
47     /**
48      * Indicate if this is a coordinated, multi-backend request. If this method returns true, the backend must
49      * act as a cohort participating in the three-phase commit (3PC) protocol to commit this transaction.  If this
50      * method returns false, the backend should proceed to commit the transaction and respond once the commit completes
51      * or fails to complete.
52      *
53      * @return Indication of coordinated commit.
54      */
55     public boolean isCoordinated() {
56         return coordinated;
57     }
58
59     @Override
60     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
61         return super.addToStringAttributes(toStringHelper).add("coordinated", coordinated);
62     }
63 }