package org.opendaylight.mdsal.binding.api;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.yangtools.yang.binding.DataObject;
* Cancels the transaction.
*
* <p>
- * Transactions can only be cancelled if it was not yet submited.
+ * A transaction can only be cancelled if it has not yet been committed.
*
* <p>
* Invoking cancel() on failed or already canceled will have no effect, and transaction is
* considered cancelled.
*
* <p>
- * Invoking cancel() on finished transaction (future returned by {@link #submit()} already
+ * Invoking cancel() on finished transaction (future returned by {@link #commit()} already
* successfully completed) will always fail (return false).
*
* @return <tt>false</tt> if the task could not be cancelled, typically because it has already
boolean cancel();
/**
- * Submits this transaction to be asynchronously applied to update the logical data tree. The
+ * Commits this transaction to be asynchronously applied to update the logical data tree. The
* returned CheckedFuture conveys the result of applying the data changes.
*
* <p>
- * <b>Note:</b> It is strongly recommended to process the CheckedFuture result in an
+ * <b>Note:</b> It is strongly recommended to process the FluentFuture result in an
* asynchronous manner rather than using the blocking get() method.
*
* <p>
* <p>
* The transaction is marked as submitted and enqueued into the shard back-end for
* processing.
+ *
+ * @return a FluentFuture containing the result of the commit information. The Future blocks until the commit
+ * operation is complete. A successful commit returns nothing. On failure, the Future will fail with a
+ * {@link TransactionCommitFailedException} or an exception derived from TransactionCommitFailedException.
*/
- CheckedFuture<Void,TransactionCommitFailedException> submit();
+ FluentFuture<? extends @NonNull CommitInfo> commit();
}
*/
package org.opendaylight.mdsal.binding.dom.adapter;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.api.CursorAwareWriteTransaction;
import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeWriteCursor;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
}
@Override
- public CheckedFuture<Void, TransactionCommitFailedException> submit() {
- return getDelegate().submit();
+ public FluentFuture<? extends @NonNull CommitInfo> commit() {
+ return getDelegate().commit();
}
}
assertNotNull(adapter.createCursor(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
InstanceIdentifier.create(DataObject.class))));
- doReturn(null).when(delegate).submit();
- adapter.submit();
- verify(delegate).submit();
+ doReturn(null).when(delegate).commit();
+ adapter.commit();
+ verify(delegate).commit();
doReturn(true).when(delegate).cancel();
assertTrue(adapter.cancel());
verify(delegate).cancel();
}
-}
\ No newline at end of file
+}
@Override
public <V extends TreeNode> void submit(final BiConsumer<TransactionCommitFailedException, V> callback) {
- delegate.submit();
+ delegate.commit();
}
}
final DataTreeWriteCursor cursor = adapter.createCursor(dti);
assertNotNull(cursor);
- doReturn(null).when(delegate).submit();
+ doReturn(null).when(delegate).commit();
final BiConsumer callback = mock(BiConsumer.class);
adapter.submit(callback);
- verify(delegate).submit();
+ verify(delegate).commit();
doReturn(true).when(delegate).cancel();
assertTrue(adapter.cancel());
verify(delegate).cancel();
}
-}
\ No newline at end of file
+}
*/
package org.opendaylight.mdsal.dom.api;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.yangtools.concepts.Identifiable;
/**
* Cancels the transaction.
- * Transactions can only be cancelled if it was not yet submited.
- * Invoking cancel() on failed or already canceled will have no effect, and transaction is
+ * A transaction can only be cancelled if it was not yet committed.
+ * Invoking cancel() on a failed or already canceled will have no effect, and transaction is
* considered cancelled.
- * Invoking cancel() on finished transaction (future returned by {@link #submit()} already
- * successfully completed) will always fail (return false).
+ * Invoking cancel() on a finished transaction (future returned by {@link #commit()} already
+ * successfully completed will always fail (return false).
*
* @return <tt>false</tt> if the task could not be cancelled, typically because it has already
* completed normally; <tt>true</tt> otherwise
* The transaction is marked as submitted and enqueued into the shard back-end for
* processing.
*
- * @return Checked future informing of success/failure
+ * @return a FluentFuture containing the result of the commit information. The Future blocks until the commit
+ * operation is complete. A successful commit returns nothing. On failure, the Future will fail with a
+ * {@link TransactionCommitFailedException} or an exception derived from TransactionCommitFailedException.
*/
- CheckedFuture<Void, TransactionCommitFailedException> submit();
+ FluentFuture<? extends @NonNull CommitInfo> commit();
}
*/
package org.opendaylight.mdsal.dom.api;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
* Read a particular node from the snapshot.
*
* @param child Child identifier
- * @return Optional result encapsulating the presence and value of the node
+ * @return a FluentFuture containing the result of the read. Once complete:
+ * <ul>
+ * <li>If the data at the supplied path exists, the Future returns an Optional object
+ * containing the data.</li>
+ * <li>If the data at the supplied path does not exist, the Future returns
+ * Optional#empty().</li>
+ * <li>If the read of the data fails, the Future will fail with a
+ * {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
+ * </ul>
* @throws IllegalArgumentException when specified path does not identify a valid child.
*/
- CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readNode(@Nonnull PathArgument child);
+ FluentFuture<Optional<NormalizedNode<?, ?>>> readNode(@Nonnull PathArgument child);
/**
* Checks if data is available in the logical data store located at provided path.
* <code>readNode</code>
*
* @param child Child identifier
- * @return a CheckFuture containing the result of the check.
+ * @return a FluentFuture containing the result of the read. Once complete:
* <ul>
* <li>If the data at the supplied path exists, the Future returns a Boolean whose value
- * is true, false otherwise</li> <li>If checking for the data fails, the Future will
+ * is true, false otherwise</li>
+ * <li>If checking for the data fails, the Future will
* fail with a {@link ReadFailedException} or an exception derived from
* ReadFailedException.</li>
* </ul>
*/
- CheckedFuture<Boolean, ReadFailedException> exists(@Nonnull PathArgument child);
+ FluentFuture<Boolean> exists(@Nonnull PathArgument child);
}
cursor.write(UNORDERED_CONTAINER_IID.getLastPathArgument(), ImmutableContainerNodeBuilder.create().build());
cursor.close();
- final ListenableFuture<Void> f = tx.submit();
+ final ListenableFuture<?> f = tx.commit();
assertNotNull(f);
f.get();
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
private void transactionSuccessful(final ShardedDOMDataTreeWriteTransaction tx) {
LOG.debug("Transaction {} completed successfully", tx.getIdentifier());
- tx.onTransactionSuccess(null);
+ tx.onTransactionSuccess(CommitInfo.empty());
transactionCompleted(tx);
}
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import com.google.common.util.concurrent.CheckedFuture;
+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 javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
@NotThreadSafe
final class ShardedDOMDataTreeWriteTransaction implements DOMDataTreeCursorAwareTransaction {
private static final Logger LOG = LoggerFactory.getLogger(ShardedDOMDataTreeWriteTransaction.class);
- private static final TransactionCommitFailedExceptionMapper SUBMIT_FAILED_MAPPER =
- TransactionCommitFailedExceptionMapper.create("submit");
private static final AtomicLong COUNTER = new AtomicLong();
private final Map<DOMDataTreeIdentifier, DOMDataTreeShardWriteTransaction> transactions;
private final ProducerLayout layout;
private final String identifier;
- private final SettableFuture<Void> future = SettableFuture.create();
- private final CheckedFuture<Void, TransactionCommitFailedException> submitFuture =
- Futures.makeChecked(future, SUBMIT_FAILED_MAPPER);
+ private final SettableFuture<CommitInfo> future = SettableFuture.create();
@GuardedBy("this")
private boolean closed = false;
}
@Override
- public synchronized CheckedFuture<Void, TransactionCommitFailedException> submit() {
+ public synchronized FluentFuture<? extends @NonNull CommitInfo> commit() {
Preconditions.checkState(!closed, "Transaction %s is already closed", identifier);
Preconditions.checkState(openCursor == null, "Cannot submit transaction while there is a cursor open");
producer.transactionSubmitted(this);
- return submitFuture;
+ return future;
}
void doSubmit(final Consumer<ShardedDOMDataTreeWriteTransaction> success,
}, MoreExecutors.directExecutor());
}
- void onTransactionSuccess(final Void result) {
- future.set(result);
+ void onTransactionSuccess(final CommitInfo commitInfo) {
+ future.set(commitInfo);
}
void onTransactionFailure(final Throwable throwable) {
}
// First we need to close cursors
cursorMap.values().forEach(DOMDataTreeWriteCursor::close);
- final FluentFuture<List<Void>> aggregatedSubmit = FluentFuture.from(Futures.allAsList(
- transactionMap.get(LogicalDatastoreType.CONFIGURATION).submit(),
- transactionMap.get(LogicalDatastoreType.OPERATIONAL).submit()));
+ final FluentFuture<List<CommitInfo>> aggregatedSubmit = FluentFuture.from(Futures.allAsList(
+ transactionMap.get(LogicalDatastoreType.CONFIGURATION).commit(),
+ transactionMap.get(LogicalDatastoreType.OPERATIONAL).commit()));
// Now we can close producers and mark transaction as finished
closeProducers();
@Test
public void closeWithTxSubmitted() throws DOMDataTreeProducerException {
final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false);
- tx.submit();
+ tx.commit();
producer.close();
}
@Test
public void allocateChildProducerWithTxSubmmited() {
- producer.createTransaction(false).submit();
+ producer.createTransaction(false).commit();
final DOMDataTreeProducer childProducer = producer.createProducer(SUBTREES_TEST);
assertNotNull(childProducer);
}
@Test
public void allocateTxWithTxSubmitted() {
- producer.createTransaction(false).submit();
+ producer.createTransaction(false).commit();
producer.createTransaction(false);
}
cursor.write(TEST_ID.getRootIdentifier().getLastPathArgument(), crossShardContainer);
try {
- tx.submit().checkedGet();
+ tx.commit().get();
fail("There's still an open cursor");
} catch (final IllegalStateException e) {
assertTrue(e.getMessage().contains("cursor open"));
}
cursor.close();
- tx.submit().get();
+ tx.commit().get();
tx = producer.createTransaction(false);
cursor = tx.createCursor(TEST_ID);
cursor.delete(TestModel.INNER_CONTAINER_PATH.getLastPathArgument());
cursor.close();
- tx.submit().get();
+ tx.commit().get();
verify(mockedDataTreeListener, timeout(1000).times(3)).onDataTreeChanged(captorForChanges.capture(),
captorForSubtrees.capture());
cursor.write(TEST_ID.getRootIdentifier().getLastPathArgument(), crossShardContainer);
cursor.close();
- tx.submit().get();
+ tx.commit().get();
tx = producer.createTransaction(false);
cursor = tx.createCursor(TEST_ID);
cursor.delete(TestModel.INNER_CONTAINER_PATH.getLastPathArgument());
cursor.close();
- tx.submit().get();
+ tx.commit().get();
verify(mockedDataTreeListener, timeout(5000).times(3)).onDataTreeChanged(captorForChanges.capture(),
captorForSubtrees.capture());
cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
cursor.close();
- tx.submit().get();
+ tx.commit().get();
- final ArrayList<ListenableFuture<Void>> futures = new ArrayList<>();
+ final ArrayList<ListenableFuture<?>> futures = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
cursor1.close();
- futures.add(tx1.submit());
+ futures.add(tx1.commit());
}
}
cursor.write(TestModel.TEST_PATH.getLastPathArgument(), createCrossShardContainer2());
cursor.close();
- tx.submit().get();
+ tx.commit().get();
final DOMDataTreeListener listener = mock(DOMDataTreeListener.class);
doNothing().when(listener).onDataTreeChanged(any(), any());
verify(cursor).delete(any());
doNothing().when(cursor).close();
- doReturn(Futures.immediateCheckedFuture(null)).when(transaction).submit();
+ doReturn(Futures.immediateCheckedFuture(null)).when(transaction).commit();
doReturn(true).when(transaction).cancel();
assertTrue(writeTransaction.cancel());
transactionChainAdapter.closeWriteTransaction(FluentFutures.immediateNullFluentFuture());
package org.opendaylight.mdsal.dom.store.inmemory;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
-import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardWriteTransaction;
return relative.get();
}
- public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
- public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
@Override
public void close() {
Preconditions.checkState(!finished, "Attempting to close an already finished transaction.");