X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FPingPongTransaction.java;fp=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FPingPongTransaction.java;h=fdb80ebcbef49bbaf17aa2981f3c322a6a2d47ab;hb=5764146d24df9d9450ebfbb0aec10cbbcdcc655c;hp=0000000000000000000000000000000000000000;hpb=152891151a8e7c7b0905b4b530837e2538b2ce7b;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransaction.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransaction.java new file mode 100644 index 0000000000..fdb80ebcbe --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransaction.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.dom.broker.impl; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.controller.md.sal.common.api.TransactionStatus; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.common.impl.service.AbstractDataTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; +import org.opendaylight.yangtools.yang.common.RpcResult; + +/** + * Transaction context. Tracks the relationship with the backend transaction. + * We never leak this class to the user and have it implement the {@link FutureCallback} + * interface so we have a simple way of propagating the result. + */ +final class PingPongTransaction implements FutureCallback { + private final CheckedFuture submitFuture; + private final ListenableFuture> commitFuture; + private final DOMDataReadWriteTransaction delegate; + private final SettableFuture future; + private DOMDataReadWriteTransaction frontendTransaction; + + PingPongTransaction(final DOMDataReadWriteTransaction delegate) { + this.delegate = Preconditions.checkNotNull(delegate); + future = SettableFuture.create(); + submitFuture = new PingPongFuture(future); + commitFuture = AbstractDataTransaction.convertToLegacyCommitFuture(submitFuture); + } + + DOMDataReadWriteTransaction getTransaction() { + return delegate; + } + + DOMDataReadWriteTransaction getFrontendTransaction() { + return frontendTransaction; + } + + CheckedFuture getSubmitFuture() { + return submitFuture; + } + + ListenableFuture> getCommitFuture() { + return commitFuture; + } + + @Override + public void onSuccess(final Void result) { + future.set(result); + } + + @Override + public void onFailure(final Throwable t) { + future.setException(t); + } + + void recordFrontendTransaction(final DOMDataReadWriteTransaction tx) { + if (frontendTransaction != null) { + frontendTransaction = tx; + } + } + + @Override + public String toString() { + return addToStringAttributes(Objects.toStringHelper(this)).toString(); + } + + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("delegate", delegate); + } +} \ No newline at end of file