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.MoreObjects;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.concurrent.NotThreadSafe;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14 import org.opendaylight.yangtools.concepts.Identifiable;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Abstract base for transactions running on SharrdDataTree.
22 * @param <T> Backing transaction type.
25 abstract class AbstractShardDataTreeTransaction<T extends DataTreeSnapshot>
26 implements Identifiable<TransactionIdentifier> {
27 private static final Logger LOG = LoggerFactory.getLogger(AbstractShardDataTreeTransaction.class);
29 private final ShardDataTreeTransactionParent parent;
30 private final TransactionIdentifier id;
31 private final T snapshot;
33 private boolean closed;
35 AbstractShardDataTreeTransaction(final ShardDataTreeTransactionParent parent, final TransactionIdentifier id,
37 this.parent = Preconditions.checkNotNull(parent);
38 this.snapshot = Preconditions.checkNotNull(snapshot);
39 this.id = Preconditions.checkNotNull(id);
43 public final TransactionIdentifier getIdentifier() {
47 final ShardDataTreeTransactionParent getParent() {
51 final T getSnapshot() {
55 final boolean isClosed() {
60 * Close this transaction and mark it as closed, allowing idempotent invocations.
62 * @return True if the transaction got closed by this method invocation.
64 protected final boolean close() {
73 final void abort(final Runnable callback) {
74 Preconditions.checkState(close(), "Transaction is already closed");
75 parent.abortTransaction(this, callback);
79 public final String toString() {
80 return MoreObjects.toStringHelper(this).add("id", id).add("closed", closed).add("snapshot", snapshot)