Bug 3195: Cleanup on error paths and error handling
[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
21     protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier) {
22         this.transactionIdentifier = transactionIdentifier;
23     }
24
25     /**
26      * Get the transaction identifier associated with this context.
27      *
28      * @return Transaction identifier.
29      */
30     @Nonnull protected final TransactionIdentifier getIdentifier() {
31         return transactionIdentifier;
32     }
33
34     protected final void incrementModificationCount() {
35         modificationCount++;
36     }
37
38     protected final void logModificationCount() {
39         LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount);
40     }
41
42     @Override
43     public final void operationHandOffComplete() {
44         handOffComplete = true;
45     }
46
47     protected boolean isOperationHandOffComplete(){
48         return handOffComplete;
49     }
50
51     @Override
52     public boolean usesOperationLimiting() {
53         return false;
54     }
55 }