@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write100KSingleNodeWithOneInnerItemInOneCommitCursorBenchmark() throws DataValidationFailedException {
final CursorAwareDataTreeModification modification = begin();
- try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+ try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
}
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write50KSingleNodeWithTwoInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
final CursorAwareDataTreeModification modification = begin();
- try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+ try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
}
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write10KSingleNodeWithTenInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
final CursorAwareDataTreeModification modification = begin();
- try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+ try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
}
*/
@Beta
public interface CursorAwareDataTreeModification extends DataTreeModification, CursorAwareDataTreeSnapshot {
- /**
- * Create a new {@link DataTreeModificationCursor} at specified path. May fail
- * if specified path does not exist. It is a programming error to use normal
- *
- * @param path Path at which the cursor is to be anchored
- * @return A new cursor, or null if the path does not exist.
- * @throws IllegalStateException if there is another cursor currently open,
- * or the modification is already {@link #ready()}.
- * @deprecated Use {@link #openCursor(YangInstanceIdentifier)} instead.
- */
- @Deprecated
- @Override
- DataTreeModificationCursor createCursor(YangInstanceIdentifier path);
-
/**
* Create a new {@link DataTreeModificationCursor} at specified path. May fail
* if specified path does not exist.
* or the modification is already {@link #ready()}.
*/
@Override
- default Optional<? extends DataTreeModificationCursor> openCursor(final YangInstanceIdentifier path) {
- return Optional.ofNullable(createCursor(path));
- }
+ Optional<? extends DataTreeModificationCursor> openCursor(YangInstanceIdentifier path);
/**
* Create a new {@link DataTreeModificationCursor} at the root of the modification.
import com.google.common.annotations.Beta;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
/**
*/
@Beta
public interface CursorAwareDataTreeSnapshot extends DataTreeSnapshot {
- /**
- * Create a new {@link DataTreeSnapshotCursor} at specified path. May fail
- * if specified path does not exist.
- *
- * @param path Path at which the cursor is to be anchored
- * @return A new cursor, or null if the path does not exist.
- * @throws IllegalStateException if there is another cursor currently open.
- * @deprecated Use {@link #openCursor(YangInstanceIdentifier)} instead.
- */
- @Deprecated
- @Nullable DataTreeSnapshotCursor createCursor(@NonNull YangInstanceIdentifier path);
-
/**
* Create a new {@link DataTreeSnapshotCursor} at specified path. May fail
* if specified path does not exist.
* @return A new cursor, or empty if the path does not exist.
* @throws IllegalStateException if there is another cursor currently open.
*/
- default Optional<? extends DataTreeSnapshotCursor> openCursor(@NonNull final YangInstanceIdentifier path) {
- return Optional.ofNullable(createCursor(path));
- }
+ Optional<? extends DataTreeSnapshotCursor> openCursor(@NonNull YangInstanceIdentifier path);
/**
* Create a new {@link DataTreeSnapshotCursor} at the root of the modification.
}
@Override
- public DataTreeModificationCursor createCursor(final YangInstanceIdentifier path) {
+ public Optional<DataTreeModificationCursor> openCursor(final YangInstanceIdentifier path) {
final OperationWithModification op = resolveModificationFor(path);
- return openCursor(new InMemoryDataTreeModificationCursor(this, path, op));
+ return Optional.of(openCursor(new InMemoryDataTreeModificationCursor(this, path, op)));
}
@Override
}
@Override
- public DataTreeSnapshotCursor createCursor(final YangInstanceIdentifier path) {
- final Optional<NormalizedNode<?, ?>> maybeRoot = NormalizedNodes.findNode(rootNode.getData(), path);
- if (!maybeRoot.isPresent()) {
- return null;
- }
-
- final NormalizedNode<?, ?> root = maybeRoot.get();
- checkArgument(root instanceof NormalizedNodeContainer, "Child %s is not a container", path);
- return openCursor(new InMemoryDataTreeSnapshotCursor(this, path, (NormalizedNodeContainer<?, ?, ?>)root));
+ public Optional<DataTreeSnapshotCursor> openCursor(final YangInstanceIdentifier path) {
+ return NormalizedNodes.findNode(rootNode.getData(), path).map(root -> {
+ checkArgument(root instanceof NormalizedNodeContainer, "Child %s is not a container", path);
+ return openCursor(new InMemoryDataTreeSnapshotCursor(this, path, (NormalizedNodeContainer<?, ?, ?>)root));
+ });
}
@Override