diff --git a/core/src/main/java/org/elasticsearch/action/TaskOperationFailure.java b/core/src/main/java/org/elasticsearch/action/TaskOperationFailure.java index bf5051c1a19..b1b5bc52fcf 100644 --- a/core/src/main/java/org/elasticsearch/action/TaskOperationFailure.java +++ b/core/src/main/java/org/elasticsearch/action/TaskOperationFailure.java @@ -47,6 +47,16 @@ public final class TaskOperationFailure implements Writeable nodeToDecision, + Map nodeWeights, long remainingDelayNanos) { + this.shard = shard; + this.primary = primary; + this.assignedNodeId = assignedNodeId; + this.unassignedInfo = unassignedInfo; + this.nodeToDecision = nodeToDecision == null ? Collections.emptyMap() : nodeToDecision; + this.nodeWeights = nodeWeights == null ? Collections.emptyMap() : nodeWeights; + this.remainingDelayNanos = remainingDelayNanos; + } + public ClusterAllocationExplanation(StreamInput in) throws IOException { this.shard = ShardId.readShardId(in); this.primary = in.readBoolean(); @@ -78,18 +90,29 @@ public final class ClusterAllocationExplanation implements ToXContent, Writeable remainingDelayNanos = in.readVLong(); } - public ClusterAllocationExplanation(ShardId shard, boolean primary, @Nullable String assignedNodeId, - UnassignedInfo unassignedInfo, Map nodeToDecision, - Map nodeWeights, long remainingDelayNanos) { - this.shard = shard; - this.primary = primary; - this.assignedNodeId = assignedNodeId; - this.unassignedInfo = unassignedInfo; - this.nodeToDecision = nodeToDecision == null ? Collections.emptyMap() : nodeToDecision; - this.nodeWeights = nodeWeights == null ? Collections.emptyMap() : nodeWeights; - this.remainingDelayNanos = remainingDelayNanos; + @Override + public void writeTo(StreamOutput out) throws IOException { + this.getShard().writeTo(out); + out.writeBoolean(this.isPrimary()); + out.writeOptionalString(this.getAssignedNodeId()); + out.writeOptionalWriteable(this.getUnassignedInfo()); + + Map ntd = this.getNodeDecisions(); + out.writeVInt(ntd.size()); + for (Map.Entry entry : ntd.entrySet()) { + entry.getKey().writeTo(out); + Decision.writeTo(entry.getValue(), out); + } + Map ntw = this.getNodeWeights(); + out.writeVInt(ntw.size()); + for (Map.Entry entry : ntw.entrySet()) { + entry.getKey().writeTo(out); + out.writeFloat(entry.getValue()); + } + out.writeVLong(remainingDelayNanos); } + public ShardId getShard() { return this.shard; } @@ -183,31 +206,4 @@ public final class ClusterAllocationExplanation implements ToXContent, Writeable builder.endObject(); // end wrapping object return builder; } - - @Override - public ClusterAllocationExplanation readFrom(StreamInput in) throws IOException { - return new ClusterAllocationExplanation(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - this.getShard().writeTo(out); - out.writeBoolean(this.isPrimary()); - out.writeOptionalString(this.getAssignedNodeId()); - out.writeOptionalWriteable(this.getUnassignedInfo()); - - Map ntd = this.getNodeDecisions(); - out.writeVInt(ntd.size()); - for (Map.Entry entry : ntd.entrySet()) { - entry.getKey().writeTo(out); - Decision.writeTo(entry.getValue(), out); - } - Map ntw = this.getNodeWeights(); - out.writeVInt(ntw.size()); - for (Map.Entry entry : ntw.entrySet()) { - entry.getKey().writeTo(out); - out.writeFloat(entry.getValue()); - } - out.writeVLong(remainingDelayNanos); - } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java index 645489f31f4..5a155dca6db 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java @@ -75,6 +75,9 @@ public class TaskInfo implements Writeable, ToXContent { this.parentTaskId = parentTaskId; } + /** + * Read from a stream. + */ public TaskInfo(StreamInput in) throws IOException { node = new DiscoveryNode(in); taskId = new TaskId(node.getId(), in.readLong()); @@ -88,6 +91,20 @@ public class TaskInfo implements Writeable, ToXContent { parentTaskId = TaskId.readFromStream(in); } + @Override + public void writeTo(StreamOutput out) throws IOException { + node.writeTo(out); + out.writeLong(taskId.getId()); + out.writeString(type); + out.writeString(action); + out.writeOptionalString(description); + out.writeOptionalNamedWriteable(status); + out.writeLong(startTime); + out.writeLong(runningTimeNanos); + out.writeBoolean(cancellable); + parentTaskId.writeTo(out); + } + public TaskId getTaskId() { return taskId; } @@ -148,25 +165,6 @@ public class TaskInfo implements Writeable, ToXContent { return parentTaskId; } - @Override - public TaskInfo readFrom(StreamInput in) throws IOException { - return new TaskInfo(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - node.writeTo(out); - out.writeLong(taskId.getId()); - out.writeString(type); - out.writeString(action); - out.writeOptionalString(description); - out.writeOptionalNamedWriteable(status); - out.writeLong(startTime); - out.writeLong(runningTimeNanos); - out.writeBoolean(cancellable); - parentTaskId.writeTo(out); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("node", node.getId()); diff --git a/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java b/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java index a0700386e72..dd436f376c0 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java @@ -46,22 +46,16 @@ final class WriteableIngestDocument implements Writeable, ToXContent { private final Version version; private final Set roles; - /** - * Creates a new {@link DiscoveryNode} by reading from the stream provided as argument - * @param in the stream - * @throws IOException if there is an error while reading from the stream - */ - public DiscoveryNode(StreamInput in) throws IOException { - this.nodeName = in.readString().intern(); - this.nodeId = in.readString().intern(); - this.hostName = in.readString().intern(); - this.hostAddress = in.readString().intern(); - this.address = TransportAddressSerializers.addressFromStream(in); - int size = in.readVInt(); - this.attributes = new HashMap<>(size); - for (int i = 0; i < size; i++) { - this.attributes.put(in.readString(), in.readString()); - } - int rolesSize = in.readVInt(); - this.roles = EnumSet.noneOf(Role.class); - for (int i = 0; i < rolesSize; i++) { - int ordinal = in.readVInt(); - if (ordinal < 0 || ordinal >= Role.values().length) { - throw new IOException("Unknown Role ordinal [" + ordinal + "]"); - } - this.roles.add(Role.values()[ordinal]); - } - this.version = Version.readVersion(in); - } - /** * Creates a new {@link DiscoveryNode} *

@@ -204,6 +176,53 @@ public class DiscoveryNode implements Writeable, ToXContent { this.roles = Collections.unmodifiableSet(rolesSet); } + /** + * Creates a new {@link DiscoveryNode} by reading from the stream provided as argument + * @param in the stream + * @throws IOException if there is an error while reading from the stream + */ + public DiscoveryNode(StreamInput in) throws IOException { + this.nodeName = in.readString().intern(); + this.nodeId = in.readString().intern(); + this.hostName = in.readString().intern(); + this.hostAddress = in.readString().intern(); + this.address = TransportAddressSerializers.addressFromStream(in); + int size = in.readVInt(); + this.attributes = new HashMap<>(size); + for (int i = 0; i < size; i++) { + this.attributes.put(in.readString(), in.readString()); + } + int rolesSize = in.readVInt(); + this.roles = EnumSet.noneOf(Role.class); + for (int i = 0; i < rolesSize; i++) { + int ordinal = in.readVInt(); + if (ordinal < 0 || ordinal >= Role.values().length) { + throw new IOException("Unknown Role ordinal [" + ordinal + "]"); + } + this.roles.add(Role.values()[ordinal]); + } + this.version = Version.readVersion(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(nodeName); + out.writeString(nodeId); + out.writeString(hostName); + out.writeString(hostAddress); + addressToStream(out, address); + out.writeVInt(attributes.size()); + for (Map.Entry entry : attributes.entrySet()) { + out.writeString(entry.getKey()); + out.writeString(entry.getValue()); + } + out.writeVInt(roles.size()); + for (Role role : roles) { + out.writeVInt(role.ordinal()); + } + Version.writeVersion(version, out); + } + /** * The address that the node can be communicated with. */ @@ -273,30 +292,6 @@ public class DiscoveryNode implements Writeable, ToXContent { return this.hostAddress; } - @Override - public DiscoveryNode readFrom(StreamInput in) throws IOException { - return new DiscoveryNode(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(nodeName); - out.writeString(nodeId); - out.writeString(hostName); - out.writeString(hostAddress); - addressToStream(out, address); - out.writeVInt(attributes.size()); - for (Map.Entry entry : attributes.entrySet()) { - out.writeString(entry.getKey()); - out.writeString(entry.getValue()); - } - out.writeVInt(roles.size()); - for (Role role : roles) { - out.writeVInt(role.ordinal()); - } - Version.writeVersion(version, out); - } - @Override public boolean equals(Object obj) { if (!(obj instanceof DiscoveryNode)) { diff --git a/core/src/main/java/org/elasticsearch/common/geo/GeoDistance.java b/core/src/main/java/org/elasticsearch/common/geo/GeoDistance.java index b08ee06a0d1..317c5cad794 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/GeoDistance.java +++ b/core/src/main/java/org/elasticsearch/common/geo/GeoDistance.java @@ -126,9 +126,7 @@ public enum GeoDistance implements Writeable { } }; - /** Returns a GeoDistance object as read from the StreamInput. */ - @Override - public GeoDistance readFrom(StreamInput in) throws IOException { + public static GeoDistance readFromStream(StreamInput in) throws IOException { int ord = in.readVInt(); if (ord < 0 || ord >= values().length) { throw new IOException("Unknown GeoDistance ordinal [" + ord + "]"); @@ -136,10 +134,6 @@ public enum GeoDistance implements Writeable { return GeoDistance.values()[ord]; } - public static GeoDistance readFromStream(StreamInput in) throws IOException { - return DEFAULT.readFrom(in); - } - @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(this.ordinal()); diff --git a/core/src/main/java/org/elasticsearch/common/geo/ShapeRelation.java b/core/src/main/java/org/elasticsearch/common/geo/ShapeRelation.java index ada4f60e179..df70db54b1d 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/ShapeRelation.java +++ b/core/src/main/java/org/elasticsearch/common/geo/ShapeRelation.java @@ -43,8 +43,7 @@ public enum ShapeRelation implements Writeable{ this.relationName = relationName; } - @Override - public ShapeRelation readFrom(StreamInput in) throws IOException { + public static ShapeRelation readFromStream(StreamInput in) throws IOException { int ordinal = in.readVInt(); if (ordinal < 0 || ordinal >= values().length) { throw new IOException("Unknown ShapeRelation ordinal [" + ordinal + "]"); diff --git a/core/src/main/java/org/elasticsearch/common/geo/SpatialStrategy.java b/core/src/main/java/org/elasticsearch/common/geo/SpatialStrategy.java index 23c1dbb43f1..c5869f98918 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/SpatialStrategy.java +++ b/core/src/main/java/org/elasticsearch/common/geo/SpatialStrategy.java @@ -42,8 +42,7 @@ public enum SpatialStrategy implements Writeable { return strategyName; } - @Override - public SpatialStrategy readFrom(StreamInput in) throws IOException { + public static SpatialStrategy readFromStream(StreamInput in) throws IOException { int ordinal = in.readVInt(); if (ordinal < 0 || ordinal >= values().length) { throw new IOException("Unknown SpatialStrategy ordinal [" + ordinal + "]"); diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java b/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java index 1d98fcd6b3b..6cd934e6291 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java @@ -38,16 +38,6 @@ public interface Writeable { // TODO remove */ void writeTo(StreamOutput out) throws IOException; - /** - * Read this object from a stream. Use a {@link Writeable.Reader} instead. This lives on for backwards compatibility but should be - * removed before 5.0.0GA. It is not deprecated because Diffable extends this interface and it shouldn't be deprecated there. - */ - default T readFrom(StreamInput in) throws IOException { - // NORELEASE remove before 5.0.0GA - throw new UnsupportedOperationException( - "Prefer calling a constructor or static method that takes a StreamInput to calling readFrom."); - } - /** * Reference to a method that can read some object from a stream. By convention this is a constructor that takes * {@linkplain StreamInput} as an argument for most classes and a static method for things like enums. Returning null from one of these diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java index e39c89a1590..8ff2f697b45 100644 --- a/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java @@ -154,8 +154,8 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder, Writeable { - private static final ESLogger logger = Loggers.getLogger(MetadataSnapshot.class); - private final Map metadata; public static final MetadataSnapshot EMPTY = new MetadataSnapshot(); @@ -760,6 +758,9 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref assert metadata.isEmpty() || numSegmentFiles() == 1 : "numSegmentFiles: " + numSegmentFiles(); } + /** + * Read from a stream. + */ public MetadataSnapshot(StreamInput in) throws IOException { final int size = in.readVInt(); Map metadata = new HashMap<>(); @@ -779,6 +780,20 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref assert metadata.isEmpty() || numSegmentFiles() == 1 : "numSegmentFiles: " + numSegmentFiles(); } + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeVInt(this.metadata.size()); + for (StoreFileMetaData meta : this) { + meta.writeTo(out); + } + out.writeVInt(commitUserData.size()); + for (Map.Entry entry : commitUserData.entrySet()) { + out.writeString(entry.getKey()); + out.writeString(entry.getValue()); + } + out.writeLong(numDocs); + } + /** * Returns the number of documents in this store snapshot */ @@ -1020,20 +1035,6 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref return metadata.size(); } - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeVInt(this.metadata.size()); - for (StoreFileMetaData meta : this) { - meta.writeTo(out); - } - out.writeVInt(commitUserData.size()); - for (Map.Entry entry : commitUserData.entrySet()) { - out.writeString(entry.getKey()); - out.writeString(entry.getValue()); - } - out.writeLong(numDocs); - } - public Map getCommitUserData() { return commitUserData; } @@ -1076,11 +1077,6 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref public String getSyncId() { return commitUserData.get(Engine.SYNC_COMMIT_ID); } - - @Override - public MetadataSnapshot readFrom(StreamInput in) throws IOException { - return new MetadataSnapshot(in); - } } /** diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java index 72ea730f881..547eda836cb 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java @@ -329,17 +329,10 @@ public class TestTaskPlugin extends Plugin { } public UnblockTestTaskResponse(StreamInput in) { - } @Override public void writeTo(StreamOutput out) throws IOException { - - } - - @Override - public UnblockTestTaskResponse readFrom(StreamInput in) throws IOException { - return new UnblockTestTaskResponse(in); } } diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index 5676747f0d4..1dc62f85713 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -195,6 +195,11 @@ public class TransportTasksActionTests extends TaskManagerTestCase { status = in.readString(); } + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(status); + } + public TestTaskResponse(String status) { this.status = status; } @@ -202,19 +207,8 @@ public class TransportTasksActionTests extends TaskManagerTestCase { public String getStatus() { return status; } - - @Override - public TestTaskResponse readFrom(StreamInput in) throws IOException { - return new TestTaskResponse(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(status); - } } - static class TestTasksRequest extends BaseTasksRequest { } diff --git a/core/src/test/java/org/elasticsearch/common/geo/ShapeRelationTests.java b/core/src/test/java/org/elasticsearch/common/geo/ShapeRelationTests.java index bba56e38ec2..6ee6a4fff83 100644 --- a/core/src/test/java/org/elasticsearch/common/geo/ShapeRelationTests.java +++ b/core/src/test/java/org/elasticsearch/common/geo/ShapeRelationTests.java @@ -63,19 +63,19 @@ public class ShapeRelationTests extends ESTestCase { try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(0); try (StreamInput in = StreamInput.wrap(out.bytes())) { - assertThat(ShapeRelation.DISJOINT.readFrom(in), equalTo(ShapeRelation.INTERSECTS)); + assertThat(ShapeRelation.readFromStream(in), equalTo(ShapeRelation.INTERSECTS)); } } try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(1); try (StreamInput in = StreamInput.wrap(out.bytes())) { - assertThat(ShapeRelation.DISJOINT.readFrom(in), equalTo(ShapeRelation.DISJOINT)); + assertThat(ShapeRelation.readFromStream(in), equalTo(ShapeRelation.DISJOINT)); } } try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(2); try (StreamInput in = StreamInput.wrap(out.bytes())) { - assertThat(ShapeRelation.DISJOINT.readFrom(in), equalTo(ShapeRelation.WITHIN)); + assertThat(ShapeRelation.readFromStream(in), equalTo(ShapeRelation.WITHIN)); } } } @@ -84,7 +84,7 @@ public class ShapeRelationTests extends ESTestCase { try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(randomIntBetween(3, Integer.MAX_VALUE)); try (StreamInput in = StreamInput.wrap(out.bytes())) { - ShapeRelation.DISJOINT.readFrom(in); + ShapeRelation.readFromStream(in); fail("Expected IOException"); } catch(IOException e) { assertThat(e.getMessage(), containsString("Unknown ShapeRelation ordinal [")); diff --git a/core/src/test/java/org/elasticsearch/common/geo/SpatialStrategyTests.java b/core/src/test/java/org/elasticsearch/common/geo/SpatialStrategyTests.java index e3e99d0e2f0..c2f29e6ecd7 100644 --- a/core/src/test/java/org/elasticsearch/common/geo/SpatialStrategyTests.java +++ b/core/src/test/java/org/elasticsearch/common/geo/SpatialStrategyTests.java @@ -55,13 +55,13 @@ public class SpatialStrategyTests extends ESTestCase { try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(0); try (StreamInput in = StreamInput.wrap(out.bytes())) { - assertThat(SpatialStrategy.TERM.readFrom(in), equalTo(SpatialStrategy.TERM)); + assertThat(SpatialStrategy.readFromStream(in), equalTo(SpatialStrategy.TERM)); } } try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(1); try (StreamInput in = StreamInput.wrap(out.bytes())) { - assertThat(SpatialStrategy.TERM.readFrom(in), equalTo(SpatialStrategy.RECURSIVE)); + assertThat(SpatialStrategy.readFromStream(in), equalTo(SpatialStrategy.RECURSIVE)); } } } @@ -70,7 +70,7 @@ public class SpatialStrategyTests extends ESTestCase { try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeVInt(randomIntBetween(2, Integer.MAX_VALUE)); try (StreamInput in = StreamInput.wrap(out.bytes())) { - SpatialStrategy.TERM.readFrom(in); + SpatialStrategy.readFromStream(in); fail("Expected IOException"); } catch(IOException e) { assertThat(e.getMessage(), containsString("Unknown SpatialStrategy ordinal ["));