X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fdom%2Fbroker%2FShardedDOMTransactionChainAdapter.java;h=ca1ab8c8c513cb3bd9ea53c8aa887ae41cc8e63f;hb=c918566080795a6f03e354c5bf1cc66c2f2ba364;hp=4ac02aad07c0a223f288c02c167b0bc32f673333;hpb=f2910f31928b7f29c7e3593065ba35460052c38f;p=mdsal.git diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMTransactionChainAdapter.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMTransactionChainAdapter.java index 4ac02aad07..ca1ab8c8c5 100644 --- a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMTransactionChainAdapter.java +++ b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMTransactionChainAdapter.java @@ -5,23 +5,23 @@ * 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.mdsal.dom.broker; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +import com.google.common.collect.ClassToInstanceMap; +import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; import java.util.Collection; import java.util.Collections; import java.util.EnumMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.mdsal.common.api.AsyncTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.mdsal.common.api.TransactionChainListener; import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMDataTreeListener; @@ -29,9 +29,13 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException; import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer; import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException; import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMDataTreeService; +import org.opendaylight.mdsal.dom.api.DOMDataTreeServiceExtension; +import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener; import org.opendaylight.yangtools.concepts.ListenerRegistration; public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { @@ -39,20 +43,17 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { private final DOMDataTreeService dataTreeService; private final Object txChainIdentifier; private final AtomicLong txNum = new AtomicLong(); - private final TransactionChainListener txChainListener; + private final DOMTransactionChainListener txChainListener; private final CachedDataTreeService cachedDataTreeService; private TransactionChainWriteTransaction writeTx; private TransactionChainReadTransaction readTx; - private ListenableFuture writeTxSubmitFuture; + private FluentFuture writeTxCommitFuture; private boolean finished = false; public ShardedDOMTransactionChainAdapter(final Object txChainIdentifier, - final DOMDataTreeService dataTreeService, - final TransactionChainListener txChainListener) { - Preconditions.checkNotNull(dataTreeService); - Preconditions.checkNotNull(txChainIdentifier); - this.dataTreeService = dataTreeService; - this.txChainIdentifier = txChainIdentifier; + final DOMDataTreeService dataTreeService, final DOMTransactionChainListener txChainListener) { + this.dataTreeService = requireNonNull(dataTreeService); + this.txChainIdentifier = requireNonNull(txChainIdentifier); this.txChainListener = txChainListener; this.cachedDataTreeService = new CachedDataTreeService(dataTreeService); } @@ -64,7 +65,7 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { checkWriteTxClosed(); readTx = new TransactionChainReadTransaction(newTransactionIdentifier(), new ShardedDOMReadTransactionAdapter(newTransactionIdentifier(), dataTreeService), - writeTxSubmitFuture, this); + writeTxCommitFuture, this); return readTx; } @@ -81,18 +82,32 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { return writeTx; } + @Override + public DOMDataTreeReadWriteTransaction newReadWriteTransaction() { + checkRunning(); + checkWriteTxClosed(); + checkReadTxClosed(); + ShardedDOMReadWriteTransactionAdapter adapter = new ShardedDOMReadWriteTransactionAdapter( + newTransactionIdentifier(), cachedDataTreeService); + TransactionChainReadWriteTransaction readWriteTx = new TransactionChainReadWriteTransaction( + newTransactionIdentifier(), adapter, adapter.getReadAdapter(), writeTxCommitFuture, this); + + writeTx = readWriteTx; + return readWriteTx; + } + @Override public void close() { - if (finished = true) { + if (finished) { // already closed, do nothing return; } checkReadTxClosed(); checkWriteTxClosed(); - Futures.addCallback(writeTxSubmitFuture, new FutureCallback() { + writeTxCommitFuture.addCallback(new FutureCallback() { @Override - public void onSuccess(@Nullable final Void result) { + public void onSuccess(final CommitInfo result) { txChainListener.onTransactionChainSuccessful(ShardedDOMTransactionChainAdapter.this); } @@ -101,7 +116,7 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { // We don't have to do nothing here, // tx should take car of it } - }); + }, MoreExecutors.directExecutor()); cachedDataTreeService.closeProducers(); finished = true; @@ -111,8 +126,8 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { readTx = null; } - public void closeWriteTransaction(final ListenableFuture submitFuture) { - writeTxSubmitFuture = submitFuture; + public void closeWriteTransaction(final FluentFuture commitFuture) { + writeTxCommitFuture = commitFuture; writeTx = null; } @@ -121,18 +136,18 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { } private void checkWriteTxClosed() { - Preconditions.checkState(writeTx == null); + checkState(writeTx == null); } private void checkReadTxClosed() { - Preconditions.checkState(readTx == null); + checkState(readTx == null); } private void checkRunning() { - Preconditions.checkState(finished == false); + checkState(!finished); } - public void transactionFailed(final AsyncTransaction tx, final Throwable cause) { + public void transactionFailed(final DOMDataTreeTransaction tx, final Throwable cause) { txChainListener.onTransactionChainFailed(this, tx, cause); if (writeTx != null) { writeTx.cancel(); @@ -158,26 +173,28 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { producersMap.values().forEach(NoopCloseDataProducer::closeDelegate); } - @Nonnull @Override - public ListenerRegistration registerListener( - @Nonnull final T listener, @Nonnull final Collection subtrees, - final boolean allowRxMerges, @Nonnull final Collection producers) - throws DOMDataTreeLoopException { + public ListenerRegistration registerListener(final T listener, + final Collection subtrees, final boolean allowRxMerges, + final Collection producers) throws DOMDataTreeLoopException { return delegateTreeService.registerListener(listener, subtrees, allowRxMerges, producers); } @Override - public DOMDataTreeProducer createProducer(@Nonnull final Collection subtrees) { - Preconditions.checkState(subtrees.size() == 1); + public ClassToInstanceMap getExtensions() { + return delegateTreeService.getExtensions(); + } + + @Override + public DOMDataTreeProducer createProducer(final Collection subtrees) { + checkState(subtrees.size() == 1); NoopCloseDataProducer producer = null; for (final DOMDataTreeIdentifier treeId : subtrees) { - producer = - new NoopCloseDataProducer(delegateTreeService.createProducer(Collections.singleton(treeId))); + producer = new NoopCloseDataProducer(delegateTreeService.createProducer(Collections.singleton(treeId))); producersMap.putIfAbsent(treeId.getDatastoreType(), producer); } - return producer; + return verifyNotNull(producer); } static class NoopCloseDataProducer implements DOMDataTreeProducer { @@ -188,15 +205,13 @@ public class ShardedDOMTransactionChainAdapter implements DOMTransactionChain { this.delegateTreeProducer = delegateTreeProducer; } - @Nonnull @Override public DOMDataTreeCursorAwareTransaction createTransaction(final boolean isolated) { return delegateTreeProducer.createTransaction(isolated); } - @Nonnull @Override - public DOMDataTreeProducer createProducer(@Nonnull final Collection subtrees) { + public DOMDataTreeProducer createProducer(final Collection subtrees) { return delegateTreeProducer.createProducer(subtrees); }