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;
18 * Abstract base for transactions running on SharrdDataTree.
20 * @param <T> Backing transaction type.
23 abstract class AbstractShardDataTreeTransaction<T extends DataTreeSnapshot>
24 implements Identifiable<TransactionIdentifier> {
25 private final TransactionIdentifier id;
26 private final T snapshot;
28 private boolean closed;
30 AbstractShardDataTreeTransaction(final TransactionIdentifier id, final T snapshot) {
31 this.snapshot = Preconditions.checkNotNull(snapshot);
32 this.id = Preconditions.checkNotNull(id);
36 public final TransactionIdentifier getIdentifier() {
40 final T getSnapshot() {
44 final boolean isClosed() {
49 * Close this transaction and mark it as closed, allowing idempotent invocations.
51 * @return True if the transaction got closed by this method invocation.
53 protected final boolean close() {
63 public final String toString() {
64 return MoreObjects.toStringHelper(this).add("id", id).add("closed", closed).add("snapshot", snapshot)
68 abstract void abort();