2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore;
10 import com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 abstract class AbstractTransactionContext implements TransactionContext {
17 private static final Logger LOG = LoggerFactory.getLogger(AbstractTransactionContext.class);
18 private final OperationLimiter limiter;
19 private long modificationCount = 0;
20 private boolean handoffComplete;
22 protected AbstractTransactionContext(final OperationLimiter limiter) {
23 this.limiter = Preconditions.checkNotNull(limiter);
27 * Get the transaction identifier associated with this context.
29 * @return Transaction identifier.
31 @Nonnull protected final TransactionIdentifier getIdentifier() {
32 return limiter.getIdentifier();
36 * Return the operation limiter associated with this context.
37 * @return Operation limiter.
39 @Nonnull protected final OperationLimiter getLimiter() {
44 * Indicate whether all operations have been handed off by the {@link TransactionContextWrapper}.
46 * @return True if this context is responsible for throttling.
48 protected final boolean isOperationHandoffComplete() {
49 return handoffComplete;
53 * Acquire operation from the limiter if the handoff has completed. If
54 * the handoff is still ongoing, this method does nothing.
56 protected final void acquireOperation() {
57 if (handoffComplete) {
63 * Acquire operation from the limiter if the handoff has NOT completed. If
64 * the handoff has completed, this method does nothing.
66 protected final void releaseOperation() {
67 if (!handoffComplete) {
72 protected final void incrementModificationCount() {
76 protected final void logModificationCount() {
77 LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount);
81 public final void operationHandoffComplete() {
82 handoffComplete = true;