BUG 3340 : Log the count of modifications on a given transaction context
[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 org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 abstract class AbstractTransactionContext implements TransactionContext {
15
16     private static final Logger LOG = LoggerFactory.getLogger(AbstractTransactionContext.class);
17
18     private long modificationCount = 0;
19
20     private final TransactionIdentifier identifier;
21
22     protected AbstractTransactionContext(TransactionIdentifier identifier) {
23         this.identifier = identifier;
24     }
25
26     protected final TransactionIdentifier getIdentifier() {
27         return identifier;
28     }
29
30     protected void incrementModificationCount(){
31         modificationCount++;
32     }
33
34     protected void logModificationCount(){
35         LOG.debug("Total modifications on Tx {} = [ {} ]", identifier, modificationCount);
36     }
37 }