Migrate DatastoreContextIntrospectorFactory to OSGi DS
[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.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.controller.cluster.access.concepts.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, short transactionVersion) {
27         // FIXME: requireNonNull()?
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     // FIXME: does this imply Identifiable?
38     protected final @NonNull TransactionIdentifier getIdentifier() {
39         return transactionIdentifier;
40     }
41
42     protected final void incrementModificationCount() {
43         modificationCount++;
44     }
45
46     protected final void logModificationCount() {
47         LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount);
48     }
49
50     @Override
51     public final void operationHandOffComplete() {
52         handOffComplete = true;
53     }
54
55     protected boolean isOperationHandOffComplete() {
56         return handOffComplete;
57     }
58
59     @Override
60     public boolean usesOperationLimiting() {
61         return false;
62     }
63
64     @Override
65     public short getTransactionVersion() {
66         return transactionVersion;
67     }
68 }