Fix shard deadlock in 3 nodes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ForwardedReadyTransaction.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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.messages;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Optional;
13 import java.util.SortedSet;
14 import javax.annotation.Nullable;
15 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
16 import org.opendaylight.controller.cluster.datastore.ReadWriteShardDataTreeTransaction;
17
18 /**
19  * Transaction ReadyTransaction message that is forwarded to the local Shard from the ShardTransaction.
20  *
21  * @author Thomas Pantelis
22  */
23 public class ForwardedReadyTransaction {
24     private final TransactionIdentifier transactionId;
25     private final ReadWriteShardDataTreeTransaction transaction;
26     private final boolean doImmediateCommit;
27     private final short txnClientVersion;
28     @Nullable
29     private final SortedSet<String> participatingShardNames;
30
31     public ForwardedReadyTransaction(TransactionIdentifier transactionId, short txnClientVersion,
32             ReadWriteShardDataTreeTransaction transaction, boolean doImmediateCommit,
33             Optional<SortedSet<String>> participatingShardNames) {
34         this.transactionId = requireNonNull(transactionId);
35         this.transaction = requireNonNull(transaction);
36         this.txnClientVersion = txnClientVersion;
37         this.doImmediateCommit = doImmediateCommit;
38         this.participatingShardNames = requireNonNull(participatingShardNames).orElse(null);
39     }
40
41     public TransactionIdentifier getTransactionId() {
42         return transactionId;
43     }
44
45     public ReadWriteShardDataTreeTransaction getTransaction() {
46         return transaction;
47     }
48
49     public short getTxnClientVersion() {
50         return txnClientVersion;
51     }
52
53     public boolean isDoImmediateCommit() {
54         return doImmediateCommit;
55     }
56
57     public Optional<SortedSet<String>> getParticipatingShardNames() {
58         return Optional.ofNullable(participatingShardNames);
59     }
60
61     @Override
62     public String toString() {
63         return "ForwardedReadyTransaction [transactionId=" + transactionId + ", transaction=" + transaction
64                 + ", doImmediateCommit=" + doImmediateCommit + ", participatingShardNames=" + participatingShardNames
65                 + ", txnClientVersion=" + txnClientVersion + "]";
66     }
67 }