/** * Create a new {@link DataTreeModificationCursor} 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 empty if the path does not exist. * @throws IllegalStateException if there is another cursor currently open, * or the modification is already {@link #ready()}. */ @Override default Optional<? extends DataTreeModificationCursor> openCursor(@Nonnull final YangInstanceIdentifier path) { return Optional.ofNullable(createCursor(path)); }
/** * Create a new {@link DataTreeModificationCursor} 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 empty if the path does not exist. * @throws IllegalStateException if there is another cursor currently open, * or the modification is already {@link #ready()}. */ @Override default Optional<? extends DataTreeModificationCursor> openCursor(@Nonnull final YangInstanceIdentifier path) { return Optional.ofNullable(createCursor(path)); }
DataTreeModificationCursorAdaptor cursor() { if (cursor == null) { if (modification == null) { modification = snapshot.newModification(); } // FIXME: Should there be non-root path? DataTreeModificationCursor dataTreeCursor = modification.createCursor(YangInstanceIdentifier.EMPTY); cursor = DataTreeModificationCursorAdaptor.of(dataTreeCursor); } return cursor; }
@Override public final void validate() throws ValidationFailedException { // Modification requires to be sealed before validation. // Sealed modification cannot be altered, so create copy. final CursorAwareDataTreeModification modificationCopy = (CursorAwareDataTreeModification) snapshot.newModification(); final DataTreeModificationCursor cursor = modificationCopy.createCursor(dataTree.getRootPath()); checkState(cursor != null, "DataTreeModificationCursor for root path should not be null"); modification.applyToCursor(cursor); // Then validate it. validateCandidate(prepareCandidateContext(modificationCopy)); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @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)) { for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) { cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]); } } commit(modification); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @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)) { for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) { cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]); } } commit(modification); }
@Benchmark @Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS) @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)) { for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) { cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]); } } commit(modification); }