import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+/**
+ * Class encapsulation of set of modifications to a base tree. This tree is backed
+ * by a read-only snapshot and tracks modifications on top of that. The modification
+ * has the ability to rebase itself on a new snapshot.
+ */
/*
* FIXME: the thread safety of concurrent write/delete/read/seal operations
* needs to be evaluated.
*/
-class MutableDataTree {
- private static final Logger LOG = LoggerFactory.getLogger(MutableDataTree.class);
+class DataTreeModification {
+ private static final Logger LOG = LoggerFactory.getLogger(DataTreeModification.class);
private final AtomicBoolean sealed = new AtomicBoolean();
private final ModificationApplyOperation strategyTree;
private final NodeModification rootModification;
private final DataTree.Snapshot snapshot;
- private MutableDataTree(final DataTree.Snapshot snapshot, final ModificationApplyOperation strategyTree) {
+ private DataTreeModification(final DataTree.Snapshot snapshot, final ModificationApplyOperation strategyTree) {
this.snapshot = Preconditions.checkNotNull(snapshot);
this.strategyTree = Preconditions.checkNotNull(strategyTree);
this.rootModification = NodeModification.createUnmodified(snapshot.getRootNode());
return OperationWithModification.from(operation, modification);
}
- public static MutableDataTree from(final DataTree.Snapshot snapshot, final ModificationApplyOperation resolver) {
- return new MutableDataTree(snapshot, resolver);
+ public static DataTreeModification from(final DataTree.Snapshot snapshot, final ModificationApplyOperation resolver) {
+ return new DataTreeModification(snapshot, resolver);
}
public void seal() {
private static class SnapshotBackedWriteTransaction extends AbstractDOMStoreTransaction implements
DOMStoreWriteTransaction {
- private MutableDataTree mutableTree;
+ private DataTreeModification mutableTree;
private InMemoryDOMDataStore store;
private boolean ready = false;
public SnapshotBackedWriteTransaction(final Object identifier, final DataTree.Snapshot snapshot,
final InMemoryDOMDataStore store, final ModificationApplyOperation applyOper) {
super(identifier);
- mutableTree = MutableDataTree.from(snapshot, applyOper);
+ mutableTree = DataTreeModification.from(snapshot, applyOper);
this.store = store;
LOG.debug("Write Tx: {} allocated with snapshot {}", identifier, snapshot);
}
return store.submit(this);
}
- protected MutableDataTree getMutatedView() {
+ protected DataTreeModification getMutatedView() {
return mutableTree;
}
@Test
public void basicReadWrites() {
- MutableDataTree modificationTree = MutableDataTree.from(new DataTree.Snapshot(schemaContext,
+ DataTreeModification modificationTree = DataTreeModification.from(new DataTree.Snapshot(schemaContext,
StoreMetadataNode.createRecursively(createDocumentOne(), UnsignedLong.valueOf(5))),
new SchemaAwareApplyOperationRoot(schemaContext));
Optional<NormalizedNode<?, ?>> originalBarNode = modificationTree.read(OUTER_LIST_2_PATH);
}
- public MutableDataTree createEmptyModificationTree() {
+ public DataTreeModification createEmptyModificationTree() {
/**
* Creates empty Snapshot with associated schema context.
*/
* context.
*
*/
- MutableDataTree modificationTree = MutableDataTree.from(t.takeSnapshot(), new SchemaAwareApplyOperationRoot(
+ DataTreeModification modificationTree = DataTreeModification.from(t.takeSnapshot(), new SchemaAwareApplyOperationRoot(
schemaContext));
return modificationTree;
}
@Test
public void createFromEmptyState() {
- MutableDataTree modificationTree = createEmptyModificationTree();
+ DataTreeModification modificationTree = createEmptyModificationTree();
/**
* Writes empty container node to /test
*
@Test
public void writeSubtreeReadChildren() {
- MutableDataTree modificationTree = createEmptyModificationTree();
+ DataTreeModification modificationTree = createEmptyModificationTree();
modificationTree.write(TEST_PATH, createTestContainer());
Optional<NormalizedNode<?, ?>> potential = modificationTree.read(TWO_TWO_PATH);
MapEntryNode node = assertPresentAndType(potential, MapEntryNode.class);
@Test
public void writeSubtreeDeleteChildren() {
- MutableDataTree modificationTree = createEmptyModificationTree();
+ DataTreeModification modificationTree = createEmptyModificationTree();
modificationTree.write(TEST_PATH, createTestContainer());
// We verify data are present