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.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 final class ChainedCommitCohort extends ShardDataTreeCohort {
19 private static final Logger LOG = LoggerFactory.getLogger(ChainedCommitCohort.class);
20 private final ReadWriteShardDataTreeTransaction transaction;
21 private final ShardDataTreeTransactionChain chain;
22 private final ShardDataTreeCohort delegate;
24 ChainedCommitCohort(final ShardDataTreeTransactionChain chain, final ReadWriteShardDataTreeTransaction transaction, final ShardDataTreeCohort delegate) {
25 this.transaction = Preconditions.checkNotNull(transaction);
26 this.delegate = Preconditions.checkNotNull(delegate);
27 this.chain = Preconditions.checkNotNull(chain);
31 public ListenableFuture<Void> commit() {
32 final ListenableFuture<Void> ret = delegate.commit();
34 Futures.addCallback(ret, new FutureCallback<Void>() {
36 public void onSuccess(Void result) {
37 chain.clearTransaction(transaction);
38 LOG.debug("Committed transaction {}", transaction);
42 public void onFailure(Throwable t) {
43 LOG.error("Transaction {} commit failed, cannot recover", transaction, t);
51 public ListenableFuture<Boolean> canCommit() {
52 return delegate.canCommit();
56 public ListenableFuture<Void> preCommit() {
57 return delegate.preCommit();
61 public ListenableFuture<Void> abort() {
62 return delegate.abort();
66 DataTreeCandidateTip getCandidate() {
67 return delegate.getCandidate();