+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import java.net.URI;
-import java.util.Objects;
-import java.util.concurrent.ExecutionException;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-
-@Deprecated(forRemoval = true)
-public final class QNameFactory {
- private static final class StringQName implements Immutable {
- private final @NonNull String localName;
- private final @NonNull String namespace;
- private final @Nullable String revision;
-
- StringQName(final String localName, final String namespace, final String revision) {
- this.localName = requireNonNull(localName);
- this.namespace = requireNonNull(namespace);
- this.revision = revision;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(localName, namespace, revision);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof StringQName)) {
- return false;
- }
- final StringQName other = (StringQName) obj;
- return localName.equals(other.localName) && namespace.equals(other.namespace)
- && Objects.equals(revision, other.revision);
- }
-
- QName toQName() {
- return revision != null ? QName.create(namespace, revision, localName) : QName.create(namespace, localName);
- }
- }
-
- private static final class ModuleQName implements Immutable {
- private final @NonNull QNameModule module;
- private final @NonNull String localName;
-
- ModuleQName(final QNameModule module, final String localName) {
- this.module = requireNonNull(module);
- this.localName = requireNonNull(localName);
- }
-
- @Override
- public int hashCode() {
- return 31 * module.hashCode() + localName.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof ModuleQName)) {
- return false;
- }
- final ModuleQName other = (ModuleQName) obj;
- return localName.equals(other.localName) && module.equals(other.module);
- }
-
- QName toQName() {
- return QName.create(module, localName);
- }
- }
-
- private static final class StringModule implements Immutable {
- private final @NonNull String namespace;
- private final @Nullable String revision;
-
- StringModule(final String namespace, final String revision) {
- this.namespace = requireNonNull(namespace);
- this.revision = revision;
- }
-
- @Override
- public int hashCode() {
- return 31 * namespace.hashCode() + Objects.hashCode(revision);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof StringModule)) {
- return false;
- }
- final StringModule other = (StringModule) obj;
- return namespace.equals(other.namespace) && Objects.equals(revision, other.revision);
- }
-
- QNameModule toQNameModule() {
- return QNameModule.create(URI.create(namespace), Revision.ofNullable(revision));
- }
- }
-
- private static final int MAX_QNAME_CACHE_SIZE = Integer.getInteger(
- "org.opendaylight.controller.cluster.datastore.node.utils.qname-cache.max-size", 10000);
- private static final int MAX_MODULE_CACHE_SIZE = Integer.getInteger(
- "org.opendaylight.controller.cluster.datastore.node.utils.module-cache.max-size", 2000);
-
- private static final LoadingCache<String, QName> LEGACY_CACHE = CacheBuilder.newBuilder()
- .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<String, QName>() {
- @Override
- public QName load(final String key) {
- return QName.create(key).intern();
- }
- });
- private static final LoadingCache<StringQName, QName> STRING_CACHE = CacheBuilder.newBuilder()
- .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<StringQName, QName>() {
- @Override
- public QName load(final StringQName key) {
- return key.toQName().intern();
- }
- });
- private static final LoadingCache<ModuleQName, QName> QNAME_CACHE = CacheBuilder.newBuilder()
- .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<ModuleQName, QName>() {
- @Override
- public QName load(final ModuleQName key) {
- return key.toQName().intern();
- }
- });
- private static final LoadingCache<StringModule, QNameModule> MODULE_CACHE = CacheBuilder.newBuilder()
- .maximumSize(MAX_MODULE_CACHE_SIZE).weakValues().build(new CacheLoader<StringModule, QNameModule>() {
- @Override
- public QNameModule load(final StringModule key) {
- return key.toQNameModule().intern();
- }
- });
- private static final LoadingCache<ModuleQName, NodeIdentifier> NODEID_CACHE = CacheBuilder.newBuilder()
- .maximumSize(MAX_QNAME_CACHE_SIZE).weakValues().build(new CacheLoader<ModuleQName, NodeIdentifier>() {
- @Override
- public NodeIdentifier load(final ModuleQName key) throws ExecutionException {
- return NodeIdentifier.create(QNAME_CACHE.get(key));
- }
- });
-
- private QNameFactory() {
-
- }
-
- @Deprecated
- public static QName create(final String name) {
- return LEGACY_CACHE.getUnchecked(name);
- }
-
- public static QName create(final String localName, final String namespace, final @Nullable String revision) {
- return STRING_CACHE.getUnchecked(new StringQName(localName, namespace, revision));
- }
-
- public static QName create(final QNameModule module, final String localName) {
- return QNAME_CACHE.getUnchecked(new ModuleQName(module, localName));
- }
-
- public static QNameModule createModule(final String namespace, final @Nullable String revision) {
- return MODULE_CACHE.getUnchecked(new StringModule(namespace, revision));
- }
-
- public static @NonNull NodeIdentifier getNodeIdentifier(final QNameModule module, final String localName)
- throws ExecutionException {
- return NODEID_CACHE.get(new ModuleQName(module, localName));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, 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.controller.cluster.datastore.node.utils.stream;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ForwardingObject;
-import java.io.IOException;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-@Deprecated
-final class CompatNormalizedNodeDataInput extends ForwardingObject implements NormalizedNodeDataInput {
- private final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput delegate;
-
- CompatNormalizedNodeDataInput(
- final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput delegate) {
- this.delegate = requireNonNull(delegate);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void readFully(final byte[] b) throws IOException {
- try {
- delegate.readFully(b);
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void readFully(final byte[] b, final int off, final int len) throws IOException {
- try {
- delegate.readFully(b, off, len);
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public int skipBytes(final int n) throws IOException {
- try {
- return delegate.skipBytes(n);
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public boolean readBoolean() throws IOException {
- try {
- return delegate.readBoolean();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public byte readByte() throws IOException {
- try {
- return delegate.readByte();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public int readUnsignedByte() throws IOException {
- try {
- return delegate.readUnsignedByte();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public short readShort() throws IOException {
- try {
- return delegate.readShort();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public int readUnsignedShort() throws IOException {
- try {
- return delegate.readUnsignedShort();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public char readChar() throws IOException {
- try {
- return delegate.readChar();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public int readInt() throws IOException {
- try {
- return delegate.readInt();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public long readLong() throws IOException {
- try {
- return delegate.readLong();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public float readFloat() throws IOException {
- try {
- return delegate.readFloat();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public double readDouble() throws IOException {
- try {
- return delegate.readDouble();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public String readLine() throws IOException {
- try {
- return delegate.readLine();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public String readUTF() throws IOException {
- try {
- return delegate.readUTF();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public void streamNormalizedNode(final NormalizedNodeStreamWriter writer) throws IOException {
- try {
- delegate.streamNormalizedNode(writer);
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
- try {
- return delegate.readYangInstanceIdentifier();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public QName readQName() throws IOException {
- try {
- return delegate.readQName();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public PathArgument readPathArgument() throws IOException {
- try {
- return delegate.readPathArgument();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public SchemaPath readSchemaPath() throws IOException {
- try {
- return delegate.readSchemaPath();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- @Override
- public NormalizedNodeStreamVersion getVersion() throws IOException {
- final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion version;
- try {
- version = delegate.getVersion();
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
-
- switch (version) {
- case LITHIUM:
- return NormalizedNodeStreamVersion.LITHIUM;
- case MAGNESIUM:
- return NormalizedNodeStreamVersion.MAGNESIUM;
- case NEON_SR2:
- return NormalizedNodeStreamVersion.NEON_SR2;
- case SODIUM_SR1:
- return NormalizedNodeStreamVersion.SODIUM_SR1;
- default:
- throw new IOException("Unhandled version " + delegate.getVersion());
- }
- }
-
- @Override
- protected org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput delegate() {
- return delegate;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, 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.controller.cluster.datastore.node.utils.stream;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ForwardingObject;
-import java.io.IOException;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-@Deprecated
-final class CompatNormalizedNodeDataOutput extends ForwardingObject implements NormalizedNodeDataOutput {
- private final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput delegate;
-
- CompatNormalizedNodeDataOutput(
- final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput delegate) {
- this.delegate = requireNonNull(delegate);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void write(final int b) throws IOException {
- delegate.write(b);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void write(final byte[] b) throws IOException {
- delegate.write(b);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void write(final byte[] b, final int off, final int len) throws IOException {
- delegate.write(b, off, len);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeBoolean(final boolean v) throws IOException {
- delegate.writeBoolean(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeByte(final int v) throws IOException {
- delegate.writeByte(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeShort(final int v) throws IOException {
- delegate.writeShort(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeChar(final int v) throws IOException {
- delegate.writeChar(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeInt(final int v) throws IOException {
- delegate.writeInt(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeLong(final long v) throws IOException {
- delegate.writeLong(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeFloat(final float v) throws IOException {
- delegate.writeFloat(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeDouble(final double v) throws IOException {
- delegate.writeDouble(v);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeBytes(final String s) throws IOException {
- delegate.writeBytes(s);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeChars(final String s) throws IOException {
- delegate.writeChars(s);
- }
-
- @Override
- @SuppressWarnings("checkstyle:parameterName")
- public void writeUTF(final String s) throws IOException {
- delegate.writeUTF(s);
- }
-
- @Override
- public void writeQName(final QName qname) throws IOException {
- delegate.writeQName(qname);
- }
-
- @Override
- public void writeNormalizedNode(final NormalizedNode<?, ?> normalizedNode) throws IOException {
- delegate.writeNormalizedNode(normalizedNode);
- }
-
- @Override
- public void writePathArgument(final PathArgument pathArgument) throws IOException {
- delegate.writePathArgument(pathArgument);
- }
-
- @Override
- public void writeYangInstanceIdentifier(final YangInstanceIdentifier identifier) throws IOException {
- delegate.writeYangInstanceIdentifier(identifier);
- }
-
- @Override
- public void writeSchemaPath(final SchemaPath path) throws IOException {
- delegate.writeSchemaPath(path);
- }
-
- @Override
- public void close() throws IOException {
- delegate.close();
- }
-
- @Override
- protected Object delegate() {
- return delegate;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. 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.controller.cluster.datastore.node.utils.stream;
-
-import java.io.IOException;
-
-/**
- * Exception thrown from NormalizedNodeInputStreamReader when the input stream does not contain
- * valid serialized data.
- *
- * @author Thomas Pantelis
- * @deprecated Use {@link org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException}
- * instead.
- */
-@Deprecated(forRemoval = true)
-public class InvalidNormalizedNodeStreamException extends IOException {
- private static final long serialVersionUID = 1L;
-
- public InvalidNormalizedNodeStreamException(final String message) {
- super(message);
- }
-
- public InvalidNormalizedNodeStreamException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils.stream;
-
-import com.google.common.annotations.Beta;
-import java.io.DataInput;
-import java.io.IOException;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.api.schema.stream.ReusableStreamReceiver;
-import org.opendaylight.yangtools.yang.data.impl.schema.ReusableImmutableNormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-/**
- * Interface for reading {@link NormalizedNode}s, {@link YangInstanceIdentifier}s, {@link PathArgument}s
- * and {@link SchemaPath}s.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput} instead.
- */
-@Deprecated(forRemoval = true)
-@Beta
-public interface NormalizedNodeDataInput extends DataInput {
- /**
- * Interpret current stream position as a NormalizedNode, stream its events into a NormalizedNodeStreamWriter.
- *
- * @param writer Writer to emit events to
- * @throws IOException if an error occurs
- * @throws IllegalStateException if the dictionary has been detached
- * @throws NullPointerException if {@code writer} is null
- */
- void streamNormalizedNode(NormalizedNodeStreamWriter writer) throws IOException;
-
- /**
- * Read a normalized node from the reader.
- *
- * @return Next node from the stream, or null if end of stream has been reached.
- * @throws IOException if an error occurs
- * @throws IllegalStateException if the dictionary has been detached
- */
- default NormalizedNode<?, ?> readNormalizedNode() throws IOException {
- return readNormalizedNode(ReusableImmutableNormalizedNodeStreamWriter.create());
- }
-
- /**
- * Read a normalized node from the reader, using specified writer to construct the result.
- *
- * @param receiver Reusable receiver to, expected to be reset
- * @return Next node from the stream, or null if end of stream has been reached.
- * @throws IOException if an error occurs
- * @throws IllegalStateException if the dictionary has been detached
- */
- default NormalizedNode<?, ?> readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
- try {
- streamNormalizedNode(receiver);
- return receiver.getResult();
- } finally {
- receiver.reset();
- }
- }
-
- YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
-
- @NonNull QName readQName() throws IOException;
-
- PathArgument readPathArgument() throws IOException;
-
- SchemaPath readSchemaPath() throws IOException;
-
- /**
- * Return the version of the underlying input stream.
- *
- * @return Stream version
- * @throws IOException if the version cannot be ascertained
- */
- NormalizedNodeStreamVersion getVersion() throws IOException;
-
- default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
- return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils.stream;
-
-import com.google.common.annotations.Beta;
-import java.io.DataOutput;
-import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-/**
- * Interface for emitting {@link NormalizedNode}s, {@link YangInstanceIdentifier}s, {@link PathArgument}s
- * and {@link SchemaPath}s.
- *
- * @deprecated Used {@link org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput} instead.
- */
-@Deprecated(forRemoval = true)
-@Beta
-public interface NormalizedNodeDataOutput extends AutoCloseable, DataOutput {
- void writeQName(@NonNull QName qname) throws IOException;
-
- void writeNormalizedNode(@NonNull NormalizedNode<?, ?> normalizedNode) throws IOException;
-
- void writePathArgument(PathArgument pathArgument) throws IOException;
-
- void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException;
-
- void writeSchemaPath(SchemaPath path) throws IOException;
-
- @Override
- void close() throws IOException;
-
- default void writeOptionalNormalizedNode(final @Nullable NormalizedNode<?, ?> normalizedNode) throws IOException {
- if (normalizedNode != null) {
- writeBoolean(true);
- writeNormalizedNode(normalizedNode);
- } else {
- writeBoolean(false);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils.stream;
-
-import com.google.common.annotations.Beta;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
-
-@Beta
-@Deprecated(forRemoval = true)
-public final class NormalizedNodeInputOutput {
- private NormalizedNodeInputOutput() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
- * and validates that the input contains a valid NormalizedNode stream.
- *
- * @param input the DataInput to read from
- * @return a new {@link NormalizedNodeDataInput} instance
- * @throws IOException if an error occurs reading from the input
- */
- public static NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
- try {
- return new CompatNormalizedNodeDataInput(org.opendaylight.yangtools.yang.data.codec.binfmt
- .NormalizedNodeDataInput.newDataInput(input));
- } catch (org.opendaylight.yangtools.yang.data.codec.binfmt.InvalidNormalizedNodeStreamException e) {
- throw new InvalidNormalizedNodeStreamException(e.getMessage(), e);
- }
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
- * perform any initial validation of the input stream.
- *
- * @param input the DataInput to read from
- * @return a new {@link NormalizedNodeDataInput} instance
- */
- public static NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
- return new CompatNormalizedNodeDataInput(org.opendaylight.yangtools.yang.data.codec.binfmt
- .NormalizedNodeDataInput.newDataInputWithoutValidation(input));
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output and latest current
- * stream version.
- *
- * @param output the DataOutput to write to
- * @return a new {@link NormalizedNodeDataOutput} instance
- */
- public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) {
- return newDataOutput(output, NormalizedNodeStreamVersion.MAGNESIUM);
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
- *
- * @param output the DataOutput to write to
- * @param version Streaming version to use
- * @return a new {@link NormalizedNodeDataOutput} instance
- */
- public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output,
- final @NonNull NormalizedNodeStreamVersion version) {
- return new CompatNormalizedNodeDataOutput(version.toYangtools().newDataOutput(output));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, 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.controller.cluster.datastore.node.utils.stream;
-
-import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * Enumeration of all stream versions this implementation supports on both input and output.
- */
-@Beta
-@Deprecated(forRemoval = true)
-@NonNullByDefault
-public enum NormalizedNodeStreamVersion {
- LITHIUM {
- @Override
- public org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion toYangtools() {
- return org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion.LITHIUM;
- }
- },
- NEON_SR2 {
- @Override
- public org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion toYangtools() {
- return org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion.NEON_SR2;
- }
- },
- SODIUM_SR1 {
- @Override
- public org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion toYangtools() {
- return org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion.SODIUM_SR1;
- }
- },
- MAGNESIUM {
- @Override
- public org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion toYangtools() {
- return org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion.MAGNESIUM;
- }
- };
-
- public abstract org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion toYangtools();
-}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
/**
* Provides various utility methods for serialization and de-serialization.
}
}
- @Deprecated(forRemoval = true)
- public static void writeNormalizedNode(final DataOutput out, final NormalizedNodeStreamVersion version,
- final @Nullable NormalizedNode<?, ?> node) throws IOException {
- writeNormalizedNode(out, version.toYangtools(), node);
- }
-
public static YangInstanceIdentifier readPath(final DataInput in) throws IOException {
return NormalizedNodeDataInput.newDataInput(in).readYangInstanceIdentifier();
}
writePath(out, MAGNESIUM, path);
}
- public static void writePath(final DataOutput out,
- final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion version,
+ public static void writePath(final DataOutput out, final NormalizedNodeStreamVersion version,
final @NonNull YangInstanceIdentifier path) throws IOException {
try (NormalizedNodeDataOutput stream = version.newDataOutput(out)) {
stream.writeYangInstanceIdentifier(path);
}
}
- @Deprecated(forRemoval = true)
- public static void writePath(final DataOutput out, final NormalizedNodeStreamVersion version,
- final @NonNull YangInstanceIdentifier path) throws IOException {
- writePath(out, version.toYangtools(), path);
- }
-
public static <T> void readNodeAndPath(final DataInput in, final T instance, final Applier<T> applier)
throws IOException {
final NormalizedNodeDataInput stream = NormalizedNodeDataInput.newDataInput(in);
applier.apply(instance, path, node);
}
- public static void writeNodeAndPath(final DataOutput out,
- final org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion version,
+ public static void writeNodeAndPath(final DataOutput out, final NormalizedNodeStreamVersion version,
final YangInstanceIdentifier path, final NormalizedNode<?, ?> node) throws IOException {
try (NormalizedNodeDataOutput stream = version.newDataOutput(out)) {
stream.writeNormalizedNode(node);
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.util.TestModel;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.Revision;
-
-@Deprecated(forRemoval = true)
-public class QNameFactoryTest {
-
- @Test
- @Deprecated
- public void testBasicString() {
- QName expected = TestModel.AUG_NAME_QNAME;
- QName created = QNameFactory.create(expected.toString());
- assertNotSame(expected, created);
- assertEquals(expected, created);
-
- QName cached = QNameFactory.create(expected.toString());
- assertSame(created, cached);
- }
-
- @Test
- public void testBasic() {
- QName expected = TestModel.AUG_NAME_QNAME;
- QName created = lookup(expected);
- assertNotSame(expected, created);
- assertEquals(expected, created);
-
- QName cached = lookup(expected);
- assertSame(created, cached);
- }
-
- private static QName lookup(final QName qname) {
- return QNameFactory.create(qname.getLocalName(), qname.getNamespace().toString(),
- qname.getRevision().map(Revision::toString).orElse(null));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils.stream;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.ByteStreams;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.util.TestModel;
-import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-@Deprecated(forRemoval = true)
-public class NormalizedNodeStreamReaderWriterTest {
-
- @Test
- public void testNormalizedNodeStreaming() throws IOException {
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
-
- NormalizedNode<?, ?> testContainer = createTestContainer();
- nnout.writeNormalizedNode(testContainer);
-
- QName toaster = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","toaster");
- QName darknessFactor = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","darknessFactor");
- QName description = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","description");
- ContainerNode toasterNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(toaster))
- .withChild(ImmutableNodes.leafNode(darknessFactor, "1000"))
- .withChild(ImmutableNodes.leafNode(description, largeString(20))).build();
-
- ContainerNode toasterContainer = Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).withChild(toasterNode).build();
- nnout.writeNormalizedNode(toasterContainer);
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(1049618, bytes.length);
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
-
- NormalizedNode<?, ?> node = nnin.readNormalizedNode();
- Assert.assertEquals(testContainer, node);
-
- node = nnin.readNormalizedNode();
- Assert.assertEquals(toasterContainer, node);
- }
-
- private static NormalizedNode<?, ?> createTestContainer() {
- byte[] bytes1 = {1, 2, 3};
- LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
- new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build();
-
- byte[] bytes2 = {};
- LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
- new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build();
-
- return TestModel.createBaseTestContainerBuilder()
- .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
- new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME))
- .withChild(entry1).withChild(entry2).build())
- .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4}))
- .withChild(ImmutableNodes.leafNode(TestModel.EMPTY_QNAME, Empty.getInstance()))
- .withChild(Builders.orderedMapBuilder()
- .withNodeIdentifier(new NodeIdentifier(TestModel.ORDERED_LIST_QNAME))
- .withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME,
- TestModel.ID_QNAME, 11)).build()).build();
- }
-
- @Test
- public void testYangInstanceIdentifierStreaming() throws IOException {
- YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH)
- .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(
- TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build();
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
-
- nnout.writeYangInstanceIdentifier(path);
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(139, bytes.length);
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
-
- YangInstanceIdentifier newPath = nnin.readYangInstanceIdentifier();
- Assert.assertEquals(path, newPath);
- }
-
- @Test
- public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException {
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- NormalizedNodeDataOutput writer = NormalizedNodeInputOutput.newDataOutput(
- ByteStreams.newDataOutput(bos));
-
- NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder().build();
- writer.writeNormalizedNode(testContainer);
-
- YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH)
- .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(
- TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build();
-
- writer.writeYangInstanceIdentifier(path);
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(825, bytes.length);
-
- NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
-
- NormalizedNode<?,?> node = reader.readNormalizedNode();
- Assert.assertEquals(testContainer, node);
-
- YangInstanceIdentifier newPath = reader.readYangInstanceIdentifier();
- Assert.assertEquals(path, newPath);
-
- writer.close();
- }
-
- @Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
- public void testInvalidNormalizedNodeStream() throws IOException {
- byte[] invalidBytes = {1, 2, 3};
- NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
- ByteStreams.newDataInput(invalidBytes));
-
- reader.readNormalizedNode();
- }
-
- @Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
- public void testInvalidYangInstanceIdentifierStream() throws IOException {
- byte[] invalidBytes = {1,2,3};
- NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
- ByteStreams.newDataInput(invalidBytes));
-
- reader.readYangInstanceIdentifier();
- }
-
- @Test
- public void testWithSerializable() {
- NormalizedNode<?, ?> input = TestModel.createTestContainer();
- SampleNormalizedNodeSerializable serializable = new SampleNormalizedNodeSerializable(input);
- SampleNormalizedNodeSerializable clone =
- (SampleNormalizedNodeSerializable)SerializationUtils.clone(serializable);
-
- Assert.assertEquals(input, clone.getInput());
- }
-
- @Test
- public void testAnyXmlStreaming() throws Exception {
- String xml = "<foo xmlns=\"http://www.w3.org/TR/html4/\" x=\"123\"><bar>one</bar><bar>two</bar></foo>";
- final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
-
- Node xmlNode = factory.newDocumentBuilder().parse(
- new InputSource(new StringReader(xml))).getDocumentElement();
-
- assertEquals("http://www.w3.org/TR/html4/", xmlNode.getNamespaceURI());
-
- NormalizedNode<?, ?> anyXmlContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(
- Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME))
- .withValue(new DOMSource(xmlNode)).build()).build();
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
-
- nnout.writeNormalizedNode(anyXmlContainer);
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(229, bytes.length);
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
-
- ContainerNode deserialized = (ContainerNode)nnin.readNormalizedNode();
-
- Optional<DataContainerChild<? extends PathArgument, ?>> child =
- deserialized.getChild(new NodeIdentifier(TestModel.ANY_XML_QNAME));
- assertEquals("AnyXml child present", true, child.isPresent());
-
- StreamResult xmlOutput = new StreamResult(new StringWriter());
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.transform(((DOMSourceAnyxmlNode)child.get()).getValue(), xmlOutput);
-
- assertEquals("XML", xml, xmlOutput.getWriter().toString());
- assertEquals("http://www.w3.org/TR/html4/",
- ((DOMSourceAnyxmlNode)child.get()).getValue().getNode().getNamespaceURI());
- }
-
- @Test
- public void testSchemaPathSerialization() throws IOException {
- final SchemaPath expected = SchemaPath.create(true, TestModel.ANY_XML_QNAME);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos))) {
- nnout.writeSchemaPath(expected);
- }
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(99, bytes.length);
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
- assertEquals(expected, nnin.readSchemaPath());
- }
-
- @Test
- public void testWritePathArgument() throws IOException {
- final NodeIdentifier expected = new NodeIdentifier(TestModel.BOOLEAN_LEAF_QNAME);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos))) {
- nnout.writePathArgument(expected);
- }
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(103, bytes.length);
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
- assertEquals(expected, nnin.readPathArgument());
- }
-
- /*
- * This tests the encoding of a MapNode with a lot of entries, each of them having the key leaf (a string)
- * and an integer.
- */
- @Test
- public void testHugeEntries() throws IOException {
- final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders.mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME));
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entryBuilder =
- Builders.mapEntryBuilder().withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, (byte) 42));
-
- for (int i = 0; i < 100_000; ++i) {
- final String key = "xyzzy" + i;
- mapBuilder.addChild(entryBuilder
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.TEST_QNAME,
- TestModel.CHILD_NAME_QNAME, key))
- .withChild(ImmutableNodes.leafNode(TestModel.CHILD_NAME_QNAME, key))
- .build());
- }
-
- final MapNode expected = mapBuilder.build();
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos))) {
- nnout.writeNormalizedNode(expected);
- }
-
- final byte[] bytes = bos.toByteArray();
- assertEquals(2_289_103, bytes.length);
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
- assertEquals(expected, nnin.readNormalizedNode());
- }
-
- @Test
- public void testAugmentationIdentifier() throws IOException {
- final List<QName> qnames = new ArrayList<>();
- for (int i = 0; i < 257; ++i) {
- qnames.add(QName.create(TestModel.TEST_QNAME, "a" + i));
- }
-
- for (int i = 0; i < qnames.size(); ++i) {
- final AugmentationIdentifier expected = AugmentationIdentifier.create(
- ImmutableSet.copyOf(qnames.subList(0, i)));
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- try (NormalizedNodeDataOutput nnout =
- NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos),
- NormalizedNodeStreamVersion.SODIUM_SR1)) {
- nnout.writePathArgument(expected);
- }
-
- final byte[] bytes = bos.toByteArray();
-
- NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
- PathArgument arg = nnin.readPathArgument();
- assertEquals(expected, arg);
- }
- }
-
- private static String largeString(final int pow) {
- StringBuilder sb = new StringBuilder("X");
- for (int i = 0; i < pow; i++) {
- sb.append(sb);
- }
- return sb.toString();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.cluster.datastore.node.utils.stream;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-public class SampleNormalizedNodeSerializable implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private NormalizedNode<?, ?> input;
-
- public SampleNormalizedNodeSerializable(final NormalizedNode<?, ?> input) {
- this.input = input;
- }
-
- public NormalizedNode<?, ?> getInput() {
- return input;
- }
-
- private void readObject(final ObjectInputStream stream) throws IOException {
- this.input = NormalizedNodeInputOutput.newDataInput(stream).readNormalizedNode();
- }
-
- private void writeObject(final ObjectOutputStream stream) throws IOException {
- NormalizedNodeInputOutput.newDataOutput(stream).writeNormalizedNode(input);
- }
-
-}
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public final class ExecuteAction extends AbstractExecute<@NonNull ContainerNode> {
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
- try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) {
+ try (NormalizedNodeDataOutput stream = NormalizedNodeStreamVersion.current().newDataOutput(out)) {
stream.writeSchemaPath(executeAction.getType());
executeAction.getPath().getDatastoreType().writeTo(out);
stream.writeYangInstanceIdentifier(executeAction.getPath().getRootIdentifier());
import java.io.ObjectOutput;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public final class ExecuteRpc extends AbstractExecute<@Nullable NormalizedNode<?, ?>> {
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
- try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) {
+ try (NormalizedNodeDataOutput stream = NormalizedNodeStreamVersion.current().newDataOutput(out)) {
stream.writeQName(executeRpc.getType().getLastComponent());
stream.writeOptionalNormalizedNode(executeRpc.getInput());
}
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionInstance;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
LOG.debug("serializing ActionRoutingTable.");
out.writeObject(Serialization.serializedActorPath(opsInvoker));
- final NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out);
+ final NormalizedNodeDataOutput nnout = NormalizedNodeStreamVersion.current().newDataOutput(out);
nnout.writeInt(actions.size());
for (DOMActionInstance id : actions) {
nnout.writeSchemaPath(id.getType());
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
public final class RoutingTable extends AbstractRoutingTable<RoutingTable, DOMRpcIdentifier> {
private static final class Proxy implements Externalizable {
public void writeExternal(final ObjectOutput out) throws IOException {
out.writeObject(Serialization.serializedActorPath(opsInvoker));
- final NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out);
- nnout.writeInt(rpcs.size());
- for (DOMRpcIdentifier id : rpcs) {
- nnout.writeSchemaPath(id.getType());
- nnout.writeYangInstanceIdentifier(id.getContextReference());
+ try (NormalizedNodeDataOutput nnout = NormalizedNodeStreamVersion.current().newDataOutput(out)) {
+ nnout.writeInt(rpcs.size());
+ for (DOMRpcIdentifier id : rpcs) {
+ nnout.writeSchemaPath(id.getType());
+ nnout.writeYangInstanceIdentifier(id.getContextReference());
+ }
}
}