Search in sources :

Example 1 with NormalizedNodeDataOutput

use of org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput in project controller by opendaylight.

the class ModifyTransactionRequestProxyV1 method writeExternal.

@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    super.writeExternal(out);
    out.writeByte(PersistenceProtocol.byteValue(protocol.orElse(null)));
    out.writeInt(modifications.size());
    if (!modifications.isEmpty()) {
        try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
            for (TransactionModification op : modifications) {
                op.writeTo(nnout);
            }
        }
    }
}
Also used : NormalizedNodeDataOutput(org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput)

Example 2 with NormalizedNodeDataOutput

use of org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput in project controller by opendaylight.

the class DataTreeCandidateInputOutput method writeDataTreeCandidate.

public static void writeDataTreeCandidate(final DataOutput out, DataTreeCandidate candidate) throws IOException {
    try (NormalizedNodeDataOutput writer = NormalizedNodeInputOutput.newDataOutput(out)) {
        writer.writeYangInstanceIdentifier(candidate.getRootPath());
        final DataTreeCandidateNode node = candidate.getRootNode();
        switch(node.getModificationType()) {
            case APPEARED:
                writer.writeByte(APPEARED);
                writeChildren(writer, node.getChildNodes());
                break;
            case DELETE:
                writer.writeByte(DELETE);
                break;
            case DISAPPEARED:
                writer.writeByte(DISAPPEARED);
                writeChildren(writer, node.getChildNodes());
                break;
            case SUBTREE_MODIFIED:
                writer.writeByte(SUBTREE_MODIFIED);
                writeChildren(writer, node.getChildNodes());
                break;
            case UNMODIFIED:
                writer.writeByte(UNMODIFIED);
                break;
            case WRITE:
                writer.writeByte(WRITE);
                writer.writeNormalizedNode(node.getDataAfter().get());
                break;
            default:
                throwUnhandledNodeType(node);
        }
    }
}
Also used : NormalizedNodeDataOutput(org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)

Example 3 with NormalizedNodeDataOutput

use of org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput in project controller by opendaylight.

the class DataChanged method writeExternal.

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeShort(DataStoreVersions.CURRENT_VERSION);
    NormalizedNodeDataOutput streamWriter = NormalizedNodeInputOutput.newDataOutput(out);
    // Write created data
    Map<YangInstanceIdentifier, NormalizedNode<?, ?>> createdData = change.getCreatedData();
    out.writeInt(createdData.size());
    for (Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> e : createdData.entrySet()) {
        streamWriter.writeYangInstanceIdentifier(e.getKey());
        streamWriter.writeNormalizedNode(e.getValue());
    }
    // Write updated data
    Map<YangInstanceIdentifier, NormalizedNode<?, ?>> originalData = change.getOriginalData();
    Map<YangInstanceIdentifier, NormalizedNode<?, ?>> updatedData = change.getUpdatedData();
    out.writeInt(updatedData.size());
    for (Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> e : updatedData.entrySet()) {
        streamWriter.writeYangInstanceIdentifier(e.getKey());
        streamWriter.writeNormalizedNode(originalData.get(e.getKey()));
        streamWriter.writeNormalizedNode(e.getValue());
    }
    // Write removed data
    Set<YangInstanceIdentifier> removed = change.getRemovedPaths();
    out.writeInt(removed.size());
    for (YangInstanceIdentifier path : removed) {
        streamWriter.writeYangInstanceIdentifier(path);
        streamWriter.writeNormalizedNode(originalData.get(path));
    }
    // Write original subtree
    NormalizedNode<?, ?> originalSubtree = change.getOriginalSubtree();
    out.writeBoolean(originalSubtree != null);
    if (originalSubtree != null) {
        streamWriter.writeNormalizedNode(originalSubtree);
    }
    // Write original subtree
    NormalizedNode<?, ?> updatedSubtree = change.getUpdatedSubtree();
    out.writeBoolean(updatedSubtree != null);
    if (updatedSubtree != null) {
        streamWriter.writeNormalizedNode(updatedSubtree);
    }
}
Also used : NormalizedNodeDataOutput(org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Map(java.util.Map)

Aggregations

NormalizedNodeDataOutput (org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput)3 Map (java.util.Map)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)1