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 com.google.common.primitives.UnsignedLong;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 final class ChainedCommitCohort extends ShardDataTreeCohort {
22 private static final Logger LOG = LoggerFactory.getLogger(ChainedCommitCohort.class);
23 private final ReadWriteShardDataTreeTransaction transaction;
24 private final ShardDataTreeTransactionChain chain;
25 private final ShardDataTreeCohort delegate;
27 ChainedCommitCohort(final ShardDataTreeTransactionChain chain, final ReadWriteShardDataTreeTransaction transaction,
28 final ShardDataTreeCohort delegate) {
29 this.transaction = Preconditions.checkNotNull(transaction);
30 this.delegate = Preconditions.checkNotNull(delegate);
31 this.chain = Preconditions.checkNotNull(chain);
35 public void commit(final FutureCallback<UnsignedLong> callback) {
36 delegate.commit(new FutureCallback<UnsignedLong>() {
38 public void onSuccess(final UnsignedLong result) {
39 chain.clearTransaction(transaction);
40 LOG.debug("Committed transaction {}", transaction);
41 callback.onSuccess(result);
45 public void onFailure(final Throwable failure) {
46 LOG.error("Transaction {} commit failed, cannot recover", transaction, failure);
47 callback.onFailure(failure);
53 public TransactionIdentifier getIdentifier() {
54 return delegate.getIdentifier();
58 public void canCommit(final FutureCallback<Void> callback) {
59 delegate.canCommit(callback);
63 public void preCommit(final FutureCallback<DataTreeCandidate> callback) {
64 delegate.preCommit(callback);
68 public ListenableFuture<Void> abort() {
69 return delegate.abort();
73 DataTreeCandidateTip getCandidate() {
74 return delegate.getCandidate();
78 DataTreeModification getDataTreeModification() {
79 return delegate.getDataTreeModification();
83 public boolean isFailed() {
84 return delegate.isFailed();
88 public State getState() {
89 return delegate.getState();