atomic-storage: remove type dependency at segment level I/O
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / NormalizedNodeDataInput.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
9
10 import com.google.common.annotations.Beta;
11 import java.io.DataInput;
12 import java.io.IOException;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.ReusableStreamReceiver;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ReusableImmutableNormalizedNodeStreamWriter;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23
24 /**
25  * Interface for reading {@link NormalizedNode}s, {@link YangInstanceIdentifier}s, {@link PathArgument}s
26  * and {@link SchemaPath}s.
27  *
28  * @deprecated Use {@link org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput} instead.
29  */
30 @Deprecated(forRemoval = true)
31 @Beta
32 public interface NormalizedNodeDataInput extends DataInput {
33     /**
34      * Interpret current stream position as a NormalizedNode, stream its events into a NormalizedNodeStreamWriter.
35      *
36      * @param writer Writer to emit events to
37      * @throws IOException if an error occurs
38      * @throws IllegalStateException if the dictionary has been detached
39      * @throws NullPointerException if {@code writer} is null
40      */
41     void streamNormalizedNode(NormalizedNodeStreamWriter writer) throws IOException;
42
43     /**
44      * Read a normalized node from the reader.
45      *
46      * @return Next node from the stream, or null if end of stream has been reached.
47      * @throws IOException if an error occurs
48      * @throws IllegalStateException if the dictionary has been detached
49      */
50     default NormalizedNode<?, ?> readNormalizedNode() throws IOException {
51         return readNormalizedNode(ReusableImmutableNormalizedNodeStreamWriter.create());
52     }
53
54     /**
55      * Read a normalized node from the reader, using specified writer to construct the result.
56      *
57      * @param receiver Reusable receiver to, expected to be reset
58      * @return Next node from the stream, or null if end of stream has been reached.
59      * @throws IOException if an error occurs
60      * @throws IllegalStateException if the dictionary has been detached
61      */
62     default NormalizedNode<?, ?> readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
63         try {
64             streamNormalizedNode(receiver);
65             return receiver.getResult();
66         } finally {
67             receiver.reset();
68         }
69     }
70
71     YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
72
73     @NonNull QName readQName() throws IOException;
74
75     PathArgument readPathArgument() throws IOException;
76
77     SchemaPath readSchemaPath() throws IOException;
78
79     /**
80      * Return the version of the underlying input stream.
81      *
82      * @return Stream version
83      * @throws IOException if the version cannot be ascertained
84      */
85     NormalizedNodeStreamVersion getVersion() throws IOException;
86
87     default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
88         return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();
89     }
90 }