BUG 5656 : Entity ownership candidates not removed consistently on leadership change
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / AbstractTransactionContext.java
1 /*
2  * Copyright (c) 2015 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.datastore;
9
10 import javax.annotation.Nonnull;
11 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 abstract class AbstractTransactionContext implements TransactionContext {
16     private static final Logger LOG = LoggerFactory.getLogger(AbstractTransactionContext.class);
17     private final TransactionIdentifier transactionIdentifier;
18     private long modificationCount = 0;
19     private boolean handOffComplete;
20     private final short transactionVersion;
21
22     protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier) {
23         this(transactionIdentifier, DataStoreVersions.CURRENT_VERSION);
24     }
25
26     protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier,
27             short transactionVersion) {
28         this.transactionIdentifier = transactionIdentifier;
29         this.transactionVersion = transactionVersion;
30     }
31
32     /**
33      * Get the transaction identifier associated with this context.
34      *
35      * @return Transaction identifier.
36      */
37     @Nonnull protected final TransactionIdentifier getIdentifier() {
38         return transactionIdentifier;
39     }
40
41     protected final void incrementModificationCount() {
42         modificationCount++;
43     }
44
45     protected final void logModificationCount() {
46         LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount);
47     }
48
49     @Override
50     public final void operationHandOffComplete() {
51         handOffComplete = true;
52     }
53
54     protected boolean isOperationHandOffComplete(){
55         return handOffComplete;
56     }
57
58     @Override
59     public boolean usesOperationLimiting() {
60         return false;
61     }
62
63     @Override
64     public short getTransactionVersion() {
65         return transactionVersion;
66     }
67 }