*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+import java.util.Optional;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
+
/**
* An implementation of apply operation which fails to do anything, consistently. An instance of this class is used by
* the data tree if it does not have a SchemaContext attached and hence cannot perform anything meaningful.
*/
-final class AlwaysFailOperation extends FullyDelegatedModificationApplyOperation {
+final class AlwaysFailOperation extends NonApplyDelegatedModificationApplyOperation {
static final ModificationApplyOperation INSTANCE = new AlwaysFailOperation();
private AlwaysFailOperation() {
@Override
ModificationApplyOperation delegate() {
- throw new IllegalStateException("Schema Context is not available.");
+ throw ise();
+ }
+
+ @Override
+ Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
+ final Version version) {
+ throw ise();
+ }
+
+ @Override
+ void checkApplicable(final ModificationPath path, final NodeModification modification,
+ final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
+ throw ise();
+ }
+
+ private static IllegalStateException ise() {
+ return new IllegalStateException("Schema Context is not available.");
}
}
+++ /dev/null
-/*
- * Copyright (c) 2019 Pantheon Technologies, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.yangtools.yang.data.impl.schema.tree;
-
-import java.util.Optional;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
-
-/**
- * A {@link ModificationApplyOperation} which delegates all invocations to a backing instance.
- */
-abstract class FullyDelegatedModificationApplyOperation extends DelegatingModificationApplyOperation {
- @Override
- final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
- final Version version) {
- return delegate().apply(modification, currentMeta, version);
- }
-
- @Override
- final void checkApplicable(final ModificationPath path, final NodeModification modification,
- final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
- delegate().checkApplicable(path, modification, current, version);
- }
-
- @Override
- final void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) {
- delegate().verifyStructure(modification, verifyChildren);
- }
-}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import java.util.Collection;
import java.util.Map.Entry;
import java.util.Optional;
AtomicIntegerFieldUpdater.newUpdater(InMemoryDataTreeModification.class, "sealed");
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTreeModification.class);
- private final RootModificationApplyOperation strategyTree;
+ private final RootApplyStrategy strategyTree;
private final InMemoryDataTreeSnapshot snapshot;
private final ModifiedNode rootNode;
private final Version version;
private volatile int sealed = 0;
InMemoryDataTreeModification(final InMemoryDataTreeSnapshot snapshot,
- final RootModificationApplyOperation resolver) {
- this.snapshot = Preconditions.checkNotNull(snapshot);
- this.strategyTree = Preconditions.checkNotNull(resolver).snapshot();
- this.rootNode = ModifiedNode.createUnmodified(snapshot.getRootNode(), strategyTree.getChildPolicy());
+ final RootApplyStrategy resolver) {
+ this.snapshot = requireNonNull(snapshot);
+ this.strategyTree = requireNonNull(resolver).snapshot();
+ this.rootNode = ModifiedNode.createUnmodified(snapshot.getRootNode(), getStrategy().getChildPolicy());
/*
* We could allocate version beforehand, since Version contract
}
ModificationApplyOperation getStrategy() {
- return strategyTree;
+ return strategyTree.delegate();
}
@Override
LOG.trace("Resolving modification apply strategy for {}", path);
upgradeIfPossible();
- return StoreTreeNodes.findNodeChecked(strategyTree, path);
+ return StoreTreeNodes.findNodeChecked(getStrategy(), path);
}
private OperationWithModification resolveModificationFor(final YangInstanceIdentifier path) {
* That is fine, as we will prune any empty TOUCH nodes in the last phase of the ready
* process.
*/
- ModificationApplyOperation operation = strategyTree;
+ ModificationApplyOperation operation = getStrategy();
ModifiedNode modification = rootNode;
int depth = 1;
}
private void checkSealed() {
- Preconditions.checkState(sealed == 0, "Data Tree is sealed. No further modifications allowed.");
+ checkState(sealed == 0, "Data Tree is sealed. No further modifications allowed.");
}
@Override
@Override
public InMemoryDataTreeModification newModification() {
- Preconditions.checkState(sealed == 1, "Attempted to chain on an unsealed modification");
+ checkState(sealed == 1, "Attempted to chain on an unsealed modification");
if (rootNode.getOperation() == LogicalOperation.NONE) {
// Simple fast case: just use the underlying modification
* have same version each time this method is called.
*/
final TreeNode originalSnapshotRoot = snapshot.getRootNode();
- final Optional<TreeNode> tempRoot = strategyTree.apply(rootNode, Optional.of(originalSnapshotRoot), version);
- Preconditions.checkState(tempRoot.isPresent(),
- "Data tree root is not present, possibly removed by previous modification");
+ final Optional<TreeNode> tempRoot = getStrategy().apply(rootNode, Optional.of(originalSnapshotRoot), version);
+ checkState(tempRoot.isPresent(), "Data tree root is not present, possibly removed by previous modification");
final InMemoryDataTreeSnapshot tempTree = new InMemoryDataTreeSnapshot(snapshot.getSchemaContext(),
tempRoot.get(), strategyTree);
}
static void checkIdentifierReferencesData(final PathArgument arg, final NormalizedNode<?, ?> data) {
- Preconditions.checkArgument(arg.equals(data.getIdentifier()),
+ checkArgument(arg.equals(data.getIdentifier()),
"Instance identifier references %s but data identifier is %s", arg, data.getIdentifier());
}
if (!path.isEmpty()) {
arg = path.getLastPathArgument();
- Preconditions.checkArgument(arg != null, "Instance identifier %s has invalid null path argument", path);
+ checkArgument(arg != null, "Instance identifier %s has invalid null path argument", path);
} else {
arg = rootNode.getIdentifier();
}
@Override
public void ready() {
final boolean wasRunning = SEALED_UPDATER.compareAndSet(this, 0, 1);
- Preconditions.checkState(wasRunning, "Attempted to seal an already-sealed Data Tree.");
+ checkState(wasRunning, "Attempted to seal an already-sealed Data Tree.");
- AbstractReadyIterator current = AbstractReadyIterator.create(rootNode, strategyTree);
+ AbstractReadyIterator current = AbstractReadyIterator.create(rootNode, getStrategy());
do {
current = current.process(version);
} while (current != null);
final class InMemoryDataTreeSnapshot extends AbstractCursorAware implements CursorAwareDataTreeSnapshot,
SchemaContextProvider {
- private final @NonNull RootModificationApplyOperation applyOper;
+ private final @NonNull RootApplyStrategy applyOper;
private final @NonNull SchemaContext schemaContext;
private final @NonNull TreeNode rootNode;
InMemoryDataTreeSnapshot(final SchemaContext schemaContext, final TreeNode rootNode,
- final RootModificationApplyOperation applyOper) {
+ final RootApplyStrategy applyOper) {
this.schemaContext = requireNonNull(schemaContext);
this.rootNode = requireNonNull(rootNode);
this.applyOper = requireNonNull(applyOper);
}
/**
- * Sets latest backing implementation of associated {@link RootModificationApplyOperation}.
+ * Sets latest backing implementation of associated {@link RootApplyStrategy}.
*
* <p>
* Note: This does not result in upgrading implementation of already existing
- * {@link RootModificationApplyOperation}. Users, who obtained instances using {@link #newSnapshot()}, deriving
- * {@link RootModificationApplyOperation} from this modification must explicitly invoke
- * {@link RootModificationApplyOperation#upgradeIfPossible()} on their instance to be updated to latest backing
+ * {@link RootApplyStrategy}. Users, who obtained instances using {@link #newSnapshot()}, deriving
+ * {@link RootApplyStrategy} from this modification must explicitly invoke
+ * {@link RootApplyStrategy#upgradeIfPossible()} on their instance to be updated to latest backing
* implementation.
*
* @param newApplyOper New backing implementation
}
/**
- * Creates new upgradable {@link RootModificationApplyOperation} associated with holder.
+ * Creates new upgradable {@link RootApplyStrategy} associated with holder.
*
- * @return New upgradable {@link RootModificationApplyOperation} with {@link #getCurrent()} used
+ * @return New upgradable {@link RootApplyStrategy} with {@link #getCurrent()} used
* as the backing implementation.
*/
- RootModificationApplyOperation newSnapshot() {
- return new UpgradableModificationApplyOperation(this, current);
+ RootApplyStrategy newSnapshot() {
+ return new UpgradableRootApplyStrategy(this, current);
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.yangtools.yang.data.impl.schema.tree;
+
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+/**
+ * A {@link ModificationApplyOperation} which delegates all invocations except checkApplicable()/apply() to a delegate
+ * instance.
+ */
+abstract class NonApplyDelegatedModificationApplyOperation extends DelegatingModificationApplyOperation {
+ @Override
+ final void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) {
+ delegate().verifyStructure(modification, verifyChildren);
+ }
+}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-final class NotUpgradableModificationApplyOperation extends RootModificationApplyOperation {
+final class NotUpgradableRootApplyStrategy extends RootApplyStrategy {
private final ModificationApplyOperation delegate;
- NotUpgradableModificationApplyOperation(final ModificationApplyOperation delegate) {
+ NotUpgradableRootApplyStrategy(final ModificationApplyOperation delegate) {
this.delegate = delegate;
}
@Override
- ModificationApplyOperation delegate() {
+ protected ModificationApplyOperation delegate() {
return delegate;
}
}
@Override
- RootModificationApplyOperation snapshot() {
+ RootApplyStrategy snapshot() {
return this;
}
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+import com.google.common.collect.ForwardingObject;
+
/**
* Represents a {@link ModificationApplyOperation} which is rooted at conceptual
* top of data tree.
* This implementation differs from other implementations in this package that
* is not immutable, but may be upgraded to newer state if available by
* explicitly invoking {@link #upgradeIfPossible()} and also serves as factory
- * for deriving snapshot {@link RootModificationApplyOperation} which will not
+ * for deriving snapshot {@link RootApplyStrategy} which will not
* be affected by upgrade of original one.
*
* <p>
* update of schema and user actually writes data after schema update. During
* update user did not invoked any operation.
*/
-abstract class RootModificationApplyOperation extends FullyDelegatedModificationApplyOperation {
+abstract class RootApplyStrategy extends ForwardingObject {
- static RootModificationApplyOperation from(final ModificationApplyOperation resolver) {
- if (resolver instanceof RootModificationApplyOperation) {
- return ((RootModificationApplyOperation) resolver).snapshot();
- }
- return new NotUpgradableModificationApplyOperation(resolver);
+ static RootApplyStrategy from(final ModificationApplyOperation resolver) {
+ return new NotUpgradableRootApplyStrategy(resolver);
}
+ @Override
+ protected abstract ModificationApplyOperation delegate();
+
@Override
public final boolean equals(final Object obj) {
return delegate().equals(obj);
* <p>
* Newly created snapshot uses backing implementation of this modification.
*
- * @return Derived {@link RootModificationApplyOperation} with separate
+ * @return Derived {@link RootApplyStrategy} with separate
* upgrade lifecycle.
*/
- abstract RootModificationApplyOperation snapshot();
+ abstract RootApplyStrategy snapshot();
/**
* Upgrades backing implementation to latest available, if possible.
*
* <p>
- * Latest implementation of {@link RootModificationApplyOperation} is
+ * Latest implementation of {@link RootApplyStrategy} is
* managed by {@link LatestOperationHolder} which was used to construct this
* operation and latest operation is updated by
* {@link LatestOperationHolder#setCurrent(ModificationApplyOperation)}.
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
/**
- * Implementation of Upgradable {@link RootModificationApplyOperation}
+ * Implementation of Upgradable {@link RootApplyStrategy}
*
* <p>
* This implementation is associated with {@link LatestOperationHolder}
* unless client invoked {@link #upgradeIfPossible()} which will result in
* changing delegate to the latest one.
*/
-final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
+final class UpgradableRootApplyStrategy extends RootApplyStrategy {
private final LatestOperationHolder holder;
private ModificationApplyOperation delegate;
- UpgradableModificationApplyOperation(final LatestOperationHolder holder,
+ UpgradableRootApplyStrategy(final LatestOperationHolder holder,
final ModificationApplyOperation delegate) {
this.holder = holder;
this.delegate = delegate;
}
@Override
- ModificationApplyOperation delegate() {
+ protected ModificationApplyOperation delegate() {
return delegate;
}
@Override
- RootModificationApplyOperation snapshot() {
- return new UpgradableModificationApplyOperation(holder, delegate);
+ RootApplyStrategy snapshot() {
+ return new UpgradableRootApplyStrategy(holder, delegate);
}
}
\ No newline at end of file
.build())
.build();
- private RootModificationApplyOperation rootOper;
+ private RootApplyStrategy rootOper;
@Before
public void prepare() {
- rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
+ rootOper = RootApplyStrategy.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
.build())
.build();
- private RootModificationApplyOperation rootOper;
+ private RootApplyStrategy rootOper;
@Before
public void prepare() {
- rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
+ rootOper = RootApplyStrategy.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}