Removal Streamable (#44647) (#44655)

This commit ends the grand adventure that was the
refactoring effort to migrate all usages of
Streamable to Writeable.

Closes #34389.
This commit is contained in:
Tal Levy 2019-07-20 19:10:49 -07:00 committed by GitHub
parent cdd06d40d2
commit 1a9cfe9110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 77 deletions

View File

@ -41,7 +41,7 @@ import static org.apache.lucene.util.TestUtil.randomSimpleString;
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
/**
* Round trip tests for all Streamable things declared in this plugin.
* Round trip tests for all {@link Writeable} things declared in this plugin.
*/
public class RoundTripTests extends ESTestCase {
public void testReindexRequest() throws IOException {

View File

@ -1,57 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.io.stream;
import java.io.IOException;
import java.util.function.Supplier;
/**
* Implementers can be written to a {@linkplain StreamOutput} and read from a {@linkplain StreamInput}. This allows them to be "thrown
* across the wire" using Elasticsearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by
* serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged.
*
* Prefer implementing {@link Writeable} over implementing this interface where possible. Lots of code depends on this interface so this
* isn't always possible.
*
* Implementers of this interface almost always declare a no arg constructor that is exclusively used for creating "empty" objects on which
* you then call {@link #readFrom(StreamInput)}. Because {@linkplain #readFrom(StreamInput)} isn't part of the constructor the fields
* on implementers cannot be final. It is these reasons that this interface has fallen out of favor compared to {@linkplain Writeable}.
*/
public interface Streamable {
/**
* Set this object's fields from a {@linkplain StreamInput}.
*/
default void readFrom(StreamInput in) throws IOException {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}
/**
* Write this object's fields to a {@linkplain StreamOutput}.
*/
void writeTo(StreamOutput out) throws IOException;
static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) {
return (StreamInput in) -> {
T request = supplier.get();
request.readFrom(in);
return request;
};
}
}

View File

@ -25,9 +25,6 @@ import java.io.IOException;
* Implementers can be written to a {@linkplain StreamOutput} and read from a {@linkplain StreamInput}. This allows them to be "thrown
* across the wire" using Elasticsearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by
* serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged.
* <p>
* Prefer implementing this interface over implementing {@link Streamable} where possible. Lots of code depends on {@linkplain Streamable}
* so this isn't always possible.
*/
public interface Writeable {

View File

@ -48,7 +48,7 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optiona
* <p>
* Tasks are used for communication with transport actions. As a result, they can contain callback
* references as well as mutable state. That makes it impractical to send tasks over transport channels
* and use in APIs. Instead, immutable and streamable TaskInfo objects are used to represent
* and use in APIs. Instead, immutable and writeable TaskInfo objects are used to represent
* snapshot information about currently running tasks.
*/
public final class TaskInfo implements Writeable, ToXContentFragment {

View File

@ -20,13 +20,10 @@
package org.elasticsearch.transport;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.transport.TransportAddress;
import java.io.IOException;
public abstract class TransportMessage implements Streamable, Writeable {
public abstract class TransportMessage implements Writeable {
private TransportAddress remoteAddress;
@ -41,18 +38,11 @@ public abstract class TransportMessage implements Streamable, Writeable {
/**
* Constructs a new empty transport message
*/
public TransportMessage() {
}
public TransportMessage() {}
/**
* Constructs a new transport message with the data from the {@link StreamInput}. This is
* currently a no-op
*/
public TransportMessage(StreamInput in) throws IOException {
}
@Override
public final void readFrom(StreamInput in) throws IOException {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}
public TransportMessage(StreamInput in) {}
}

View File

@ -72,7 +72,7 @@ public class UpdateSettingsRequestTests extends AbstractXContentTestCase<UpdateS
@Override
protected void assertEqualInstances(UpdateSettingsRequest expectedInstance, UpdateSettingsRequest newInstance) {
// here only the settings should be tested, as this test covers explicitly only the XContent parsing
// the rest of the request fields are tested by the StreamableTests
// the rest of the request fields are tested by the SerializingTests
super.assertEqualInstances(new UpdateSettingsRequest(expectedInstance.settings()),
new UpdateSettingsRequest(newInstance.settings()));
}

View File

@ -430,7 +430,7 @@ public class BytesStreamsTests extends ESTestCase {
}
}
public void testWriteStreamableList() throws IOException {
public void testWriteWriteableList() throws IOException {
final int size = randomIntBetween(0, 5);
final List<TestWriteable> expected = new ArrayList<>(size);