2 * Copyright (c) 2014 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.md.sal.dom.store.impl;
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.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
16 final class ChainedTransactionCommitImpl implements DOMStoreThreePhaseCommitCohort {
17 private final SnapshotBackedWriteTransaction transaction;
18 private final DOMStoreThreePhaseCommitCohort delegate;
19 private final DOMStoreTransactionChainImpl txChain;
21 protected ChainedTransactionCommitImpl(final SnapshotBackedWriteTransaction transaction,
22 final DOMStoreThreePhaseCommitCohort delegate, final DOMStoreTransactionChainImpl txChain) {
23 this.transaction = Preconditions.checkNotNull(transaction);
24 this.delegate = Preconditions.checkNotNull(delegate);
25 this.txChain = Preconditions.checkNotNull(txChain);
29 public ListenableFuture<Boolean> canCommit() {
30 return delegate.canCommit();
34 public ListenableFuture<Void> preCommit() {
35 return delegate.preCommit();
39 public ListenableFuture<Void> abort() {
40 return delegate.abort();
44 public ListenableFuture<Void> commit() {
45 ListenableFuture<Void> commitFuture = delegate.commit();
46 Futures.addCallback(commitFuture, new FutureCallback<Void>() {
48 public void onFailure(final Throwable t) {
49 txChain.onTransactionFailed(transaction, t);
53 public void onSuccess(final Void result) {
54 txChain.onTransactionCommited(transaction);