2 * Copyright (c) 2015 Brocade Communications 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.annotations.VisibleForTesting;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.List;
16 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import scala.concurrent.Future;
22 * An AbstractThreePhaseCommitCohort implementation used for debugging. If a failure occurs, the transaction
23 * call site is printed.
25 * @author Thomas Pantelis
27 class DebugThreePhaseCommitCohort extends AbstractThreePhaseCommitCohort<Object> {
28 private static final Logger LOG = LoggerFactory.getLogger(DebugThreePhaseCommitCohort.class);
30 private final AbstractThreePhaseCommitCohort<?> delegate;
31 private final Throwable debugContext;
32 private final TransactionIdentifier transactionId;
33 private Logger log = LOG;
35 DebugThreePhaseCommitCohort(TransactionIdentifier transactionId, AbstractThreePhaseCommitCohort<?> delegate,
36 Throwable debugContext) {
37 this.delegate = Preconditions.checkNotNull(delegate);
38 this.debugContext = Preconditions.checkNotNull(debugContext);
39 this.transactionId = Preconditions.checkNotNull(transactionId);
42 private <V> ListenableFuture<V> addFutureCallback(ListenableFuture<V> future) {
43 Futures.addCallback(future, new FutureCallback<V>() {
45 public void onSuccess(V result) {
50 public void onFailure(Throwable t) {
51 log.warn("Transaction {} failed with error \"{}\" - was allocated in the following context",
52 transactionId, t, debugContext);
60 public ListenableFuture<Boolean> canCommit() {
61 return addFutureCallback(delegate.canCommit());
65 public ListenableFuture<Void> preCommit() {
66 return addFutureCallback(delegate.preCommit());
70 public ListenableFuture<Void> commit() {
71 return addFutureCallback(delegate.commit());
75 public ListenableFuture<Void> abort() {
76 return delegate.abort();
79 @SuppressWarnings({ "rawtypes", "unchecked" })
81 List<Future<Object>> getCohortFutures() {
82 return ((AbstractThreePhaseCommitCohort)delegate).getCohortFutures();
86 void setLogger(Logger log) {