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.controller.cluster.datastore.persisted.AbortTransactionPayload;
15 import org.opendaylight.yangtools.concepts.Identifiable;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
19 * Abstract base for transactions running on SharrdDataTree.
21 * @param <T> Backing transaction type.
24 abstract class AbstractShardDataTreeTransaction<T extends DataTreeSnapshot>
25 implements Identifiable<TransactionIdentifier> {
26 private final ShardDataTreeTransactionParent parent;
27 private final TransactionIdentifier id;
28 private final T snapshot;
30 private boolean closed;
32 AbstractShardDataTreeTransaction(final ShardDataTreeTransactionParent parent, final TransactionIdentifier id,
34 this.parent = Preconditions.checkNotNull(parent);
35 this.snapshot = Preconditions.checkNotNull(snapshot);
36 this.id = Preconditions.checkNotNull(id);
40 public final TransactionIdentifier getIdentifier() {
44 final ShardDataTreeTransactionParent getParent() {
48 final T getSnapshot() {
52 final boolean isClosed() {
57 * Close this transaction and mark it as closed, allowing idempotent invocations.
59 * @return True if the transaction got closed by this method invocation.
61 protected final boolean close() {
70 final void abort(final Runnable callback) {
71 Preconditions.checkState(close(), "Transaction is already closed");
72 parent.abortTransaction(this, callback);
76 * This method is exposed for sake of {@link ShardTransaction}, which is an actor. We need to ensure that
77 * the parent is updated to reflect the transaction has been closed, but no journal actions may be invoked.
80 * ShardTransaction is responsible for additionally sending a request to persist an {@link AbortTransactionPayload}
81 * via a message to the Shard actor.
83 final void abortFromTransactionActor() {
85 parent.abortFromTransactionActor(this);
90 public final String toString() {
91 return MoreObjects.toStringHelper(this).add("id", id).add("closed", closed).add("snapshot", snapshot)