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.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 final class ChainedCommitCohort extends ShardDataTreeCohort {
20 private static final Logger LOG = LoggerFactory.getLogger(ChainedCommitCohort.class);
21 private final ReadWriteShardDataTreeTransaction transaction;
22 private final ShardDataTreeTransactionChain chain;
23 private final ShardDataTreeCohort delegate;
25 ChainedCommitCohort(final ShardDataTreeTransactionChain chain, final ReadWriteShardDataTreeTransaction transaction, final ShardDataTreeCohort delegate) {
26 this.transaction = Preconditions.checkNotNull(transaction);
27 this.delegate = Preconditions.checkNotNull(delegate);
28 this.chain = Preconditions.checkNotNull(chain);
32 public ListenableFuture<Void> commit() {
33 final ListenableFuture<Void> ret = delegate.commit();
35 Futures.addCallback(ret, new FutureCallback<Void>() {
37 public void onSuccess(Void result) {
38 chain.clearTransaction(transaction);
39 LOG.debug("Committed transaction {}", transaction);
43 public void onFailure(Throwable t) {
44 LOG.error("Transaction {} commit failed, cannot recover", transaction, t);
52 public ListenableFuture<Boolean> canCommit() {
53 return delegate.canCommit();
57 public ListenableFuture<Void> preCommit() {
58 return delegate.preCommit();
62 public ListenableFuture<Void> abort() {
63 return delegate.abort();
67 DataTreeCandidateTip getCandidate() {
68 return delegate.getCandidate();
72 DataTreeModification getDataTreeModification() {
73 return delegate.getDataTreeModification();