All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.controller.cluster.datastore.AbstractTransactionContext Maven / Gradle / Ivy

/*
 * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.cluster.datastore;

import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

abstract class AbstractTransactionContext implements TransactionContext {
    private static final Logger LOG = LoggerFactory.getLogger(AbstractTransactionContext.class);
    private final TransactionIdentifier transactionIdentifier;
    private long modificationCount = 0;
    private boolean handOffComplete;
    private final short transactionVersion;

    protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier) {
        this(transactionIdentifier, DataStoreVersions.CURRENT_VERSION);
    }

    protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier, short transactionVersion) {
        // FIXME: requireNonNull()?
        this.transactionIdentifier = transactionIdentifier;
        this.transactionVersion = transactionVersion;
    }

    /**
     * Get the transaction identifier associated with this context.
     *
     * @return Transaction identifier.
     */
    // FIXME: does this imply Identifiable?
    protected final @NonNull TransactionIdentifier getIdentifier() {
        return transactionIdentifier;
    }

    protected final void incrementModificationCount() {
        modificationCount++;
    }

    protected final void logModificationCount() {
        LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount);
    }

    @Override
    public final void operationHandOffComplete() {
        handOffComplete = true;
    }

    protected boolean isOperationHandOffComplete() {
        return handOffComplete;
    }

    @Override
    public boolean usesOperationLimiting() {
        return false;
    }

    @Override
    public short getTransactionVersion() {
        return transactionVersion;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy