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.broker.impl;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import com.google.common.util.concurrent.FutureCallback;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.SettableFuture;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
18 import org.opendaylight.mdsal.common.api.CommitInfo;
21 * Transaction context. Tracks the relationship with the backend transaction.
22 * We never leak this class to the user and have it implement the {@link FutureCallback}
23 * interface so we have a simple way of propagating the result.
26 final class PingPongTransaction implements FutureCallback<CommitInfo> {
27 private final DOMDataReadWriteTransaction delegate;
28 private final SettableFuture<CommitInfo> future;
29 private DOMDataReadWriteTransaction frontendTransaction;
31 PingPongTransaction(final DOMDataReadWriteTransaction delegate) {
32 this.delegate = requireNonNull(delegate);
33 future = SettableFuture.create();
36 DOMDataReadWriteTransaction getTransaction() {
40 DOMDataReadWriteTransaction getFrontendTransaction() {
41 return frontendTransaction;
44 ListenableFuture<CommitInfo> getCommitFuture() {
49 public void onSuccess(final CommitInfo result) {
54 public void onFailure(final Throwable throwable) {
55 future.setException(throwable);
58 void recordFrontendTransaction(final DOMDataReadWriteTransaction tx) {
59 if (frontendTransaction != null) {
60 frontendTransaction = tx;
65 public String toString() {
66 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
69 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
70 return toStringHelper.add("delegate", delegate);