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.mdsal.dom.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import com.google.common.util.concurrent.FluentFuture;
14 import com.google.common.util.concurrent.FutureCallback;
15 import com.google.common.util.concurrent.SettableFuture;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.common.api.CommitInfo;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
22 * Transaction context. Tracks the relationship with the backend transaction.
23 * We never leak this class to the user and have it implement the {@link FutureCallback}
24 * interface so we have a simple way of propagating the result.
26 final class PingPongTransaction implements FutureCallback<CommitInfo> {
27 private final @NonNull SettableFuture<CommitInfo> future = SettableFuture.create();
28 private final @NonNull FluentFuture<CommitInfo> fluent =
29 FluentFuture.from(new UncancellableListenableFuture<>(future));
30 private final @NonNull DOMDataTreeReadWriteTransaction delegate;
32 private @Nullable DOMDataTreeReadWriteTransaction frontendTransaction;
34 PingPongTransaction(final DOMDataTreeReadWriteTransaction delegate) {
35 this.delegate = requireNonNull(delegate);
38 @NonNull DOMDataTreeReadWriteTransaction getTransaction() {
42 DOMDataTreeReadWriteTransaction getFrontendTransaction() {
43 return frontendTransaction;
46 @NonNull FluentFuture<? extends CommitInfo> completionFuture() {
51 public void onSuccess(final CommitInfo result) {
56 public void onFailure(final Throwable throwable) {
57 future.setException(throwable);
60 void recordFrontendTransaction(final DOMDataTreeReadWriteTransaction tx) {
61 if (frontendTransaction == null) {
62 frontendTransaction = requireNonNull(tx);
67 public String toString() {
68 return MoreObjects.toStringHelper(this).add("delegate", delegate).toString();