import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNodes;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final byte SUBTREE_MODIFIED = 1;
private static final byte UNMODIFIED = 2;
private static final byte WRITE = 3;
+ private static final byte APPEARED = 4;
+ private static final byte DISAPPEARED = 5;
private transient byte[] serialized;
private static void writeNode(final NormalizedNodeOutputStreamWriter writer, final DataOutput out,
final DataTreeCandidateNode node) throws IOException {
switch (node.getModificationType()) {
+ case APPEARED:
+ out.writeByte(APPEARED);
+ writer.writePathArgument(node.getIdentifier());
+ writeChildren(writer, out, node.getChildNodes());
+ break;
case DELETE:
out.writeByte(DELETE);
writer.writePathArgument(node.getIdentifier());
break;
+ case DISAPPEARED:
+ out.writeByte(DISAPPEARED);
+ writer.writePathArgument(node.getIdentifier());
+ writeChildren(writer, out, node.getChildNodes());
+ break;
case SUBTREE_MODIFIED:
out.writeByte(SUBTREE_MODIFIED);
writer.writePathArgument(node.getIdentifier());
final DataTreeCandidateNode node = candidate.getRootNode();
switch (node.getModificationType()) {
+ case APPEARED:
+ out.writeByte(APPEARED);
+ writeChildren(writer, out, node.getChildNodes());
+ break;
case DELETE:
out.writeByte(DELETE);
break;
+ case DISAPPEARED:
+ out.writeByte(DISAPPEARED);
+ writeChildren(writer, out, node.getChildNodes());
+ break;
case SUBTREE_MODIFIED:
out.writeByte(SUBTREE_MODIFIED);
writeChildren(writer, out, node.getChildNodes());
}
}
+ private static DataTreeCandidateNode readModifiedNode(final ModificationType type,
+ final NormalizedNodeInputStreamReader reader, final DataInput in) throws IOException {
+
+ final PathArgument identifier = reader.readPathArgument();
+ final Collection<DataTreeCandidateNode> children = readChildren(reader, in);
+ if (children.isEmpty()) {
+ LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
+ return null;
+ } else {
+ return ModifiedDataTreeCandidateNode.create(identifier, type, children);
+ }
+ }
+
private static DataTreeCandidateNode readNode(final NormalizedNodeInputStreamReader reader,
final DataInput in) throws IOException {
final byte type = in.readByte();
switch (type) {
+ case APPEARED:
+ return readModifiedNode(ModificationType.APPEARED, reader, in);
case DELETE:
return DeletedDataTreeCandidateNode.create(reader.readPathArgument());
+ case DISAPPEARED:
+ return readModifiedNode(ModificationType.DISAPPEARED, reader, in);
case SUBTREE_MODIFIED:
- final PathArgument identifier = reader.readPathArgument();
- final Collection<DataTreeCandidateNode> children = readChildren(reader, in);
- if (children.isEmpty()) {
- LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
- return null;
- } else {
- return ModifiedDataTreeCandidateNode.create(identifier, children);
- }
+ return readModifiedNode(ModificationType.SUBTREE_MODIFIED, reader, in);
case UNMODIFIED:
return null;
case WRITE:
abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode {
private final Collection<DataTreeCandidateNode> children;
- private ModifiedDataTreeCandidateNode(final Collection<DataTreeCandidateNode> children) {
- super(ModificationType.SUBTREE_MODIFIED);
+ private ModifiedDataTreeCandidateNode(final ModificationType type, final Collection<DataTreeCandidateNode> children) {
+ super(type);
this.children = Preconditions.checkNotNull(children);
}
static DataTreeCandidateNode create(final Collection<DataTreeCandidateNode> children) {
- return new ModifiedDataTreeCandidateNode(children) {
+ return new ModifiedDataTreeCandidateNode(ModificationType.SUBTREE_MODIFIED, children) {
@Override
public PathArgument getIdentifier() {
throw new UnsupportedOperationException("Root node does not have an identifier");
};
}
- static DataTreeCandidateNode create(final PathArgument identifier, final Collection<DataTreeCandidateNode> children) {
- return new ModifiedDataTreeCandidateNode(children) {
+ static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type, final Collection<DataTreeCandidateNode> children) {
+ return new ModifiedDataTreeCandidateNode(type, children) {
@Override
public final PathArgument getIdentifier() {
return identifier;
public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
for(DataTreeCandidate change: changes) {
DataTreeCandidateNode changeRoot = change.getRootNode();
+ ModificationType type = changeRoot.getModificationType();
- LOG.debug("{}: Candidate node changed: {}, {}", logId, changeRoot.getModificationType(), change.getRootPath());
+ LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath());
NodeIdentifierWithPredicates candidateKey =
(NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument();
YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath());
- if(changeRoot.getModificationType() == ModificationType.WRITE) {
+ if(type == ModificationType.WRITE || type == ModificationType.APPEARED) {
LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId);
Collection<String> currentCandidates = addToCurrentCandidates(entityId, candidate);
shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(currentCandidates)), shard);
- } else if(changeRoot.getModificationType() == ModificationType.DELETE) {
+ } else if(type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) {
LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId);
Collection<String> currentCandidates = removeFromCurrentCandidates(entityId, candidate);
return YangInstanceIdentifier.create(newPathArgs);
}
-}
\ No newline at end of file
+}