mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Isolate StreamableReader
Makes Writeable not depend on StreamableReader. Keeps the default readFrom implementation for backwards compatibility during the PROTOTYPE removal but that'll go when those are gone. Makes Diffable not extend StreamableReader. Instead Diffable has a readFrom method. The PROTOTYPE removal will not get to cluster state for a long time so that method will stay. Now only a few things implement StreamableReader. They will be addressed individually and then we'll remove StreamableReader.
This commit is contained in:
parent
7908759949
commit
d5d85e4350
@ -46,7 +46,7 @@ public abstract class AbstractDiffable<T extends Diffable<T>> implements Diffabl
|
||||
return new CompleteDiff<>(this, in);
|
||||
}
|
||||
|
||||
public static <T extends Diffable<T>> Diff<T> readDiffFrom(StreamableReader<T> reader, StreamInput in) throws IOException {
|
||||
public static <T extends Diffable<T>> Diff<T> readDiffFrom(T reader, StreamInput in) throws IOException {
|
||||
return new CompleteDiff<T>(reader, in);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public abstract class AbstractDiffable<T extends Diffable<T>> implements Diffabl
|
||||
/**
|
||||
* Read simple diff from the stream
|
||||
*/
|
||||
public CompleteDiff(StreamableReader<T> reader, StreamInput in) throws IOException {
|
||||
public CompleteDiff(Diffable<T> reader, StreamInput in) throws IOException {
|
||||
if (in.readBoolean()) {
|
||||
this.part = reader.readFrom(in);
|
||||
} else {
|
||||
|
@ -39,4 +39,8 @@ public interface Diffable<T> extends Writeable<T> {
|
||||
*/
|
||||
Diff<T> readDiffFrom(StreamInput in) throws IOException;
|
||||
|
||||
/**
|
||||
* Reads an object of this type from the provided {@linkplain StreamInput}. The receiving instance remains unchanged.
|
||||
*/
|
||||
T readFrom(StreamInput in) throws IOException;
|
||||
}
|
||||
|
@ -37,13 +37,12 @@ import java.io.IOException;
|
||||
* {@link StreamInput}. The reasoning behind this is that most "good" readFrom implementations just delegated to such a constructor anyway
|
||||
* and they required an unsightly PROTOTYPE object.
|
||||
*/
|
||||
public interface Writeable<T> extends StreamableReader<T> { // TODO remove extends StreamableReader<T> from this interface, and remove <T>
|
||||
public interface Writeable<T> { // TODO remove <T>
|
||||
/**
|
||||
* Write this into the {@linkplain StreamOutput}.
|
||||
*/
|
||||
void writeTo(StreamOutput out) throws IOException;
|
||||
|
||||
@Override
|
||||
default T readFrom(StreamInput in) throws IOException {
|
||||
// See class javadoc for reasoning
|
||||
throw new UnsupportedOperationException(
|
||||
|
@ -399,12 +399,7 @@ public class DiffableTests extends ESTestCase {
|
||||
|
||||
@Override
|
||||
public Diff<TestDiffable> readDiff(StreamInput in, K key) throws IOException {
|
||||
return AbstractDiffable.readDiffFrom(new StreamableReader<TestDiffable>() {
|
||||
@Override
|
||||
public TestDiffable readFrom(StreamInput in) throws IOException {
|
||||
return new TestDiffable(in.readString());
|
||||
}
|
||||
}, in);
|
||||
return AbstractDiffable.readDiffFrom(TestDiffable.PROTO, in);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user