diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java index a21c99b68e2..fd3d0fa5c95 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java @@ -215,12 +215,8 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { process = in.readOptionalWriteable(ProcessStats::new); jvm = in.readOptionalWriteable(JvmStats::new); threadPool = in.readOptionalWriteable(ThreadPoolStats::new); - if (in.readBoolean()) { - fs = new FsInfo(in); - } - if (in.readBoolean()) { - transport = TransportStats.readTransportStats(in); - } + fs = in.readOptionalWriteable(FsInfo::new); + transport = in.readOptionalWriteable(TransportStats::new); if (in.readBoolean()) { http = HttpStats.readHttpStats(in); } @@ -244,18 +240,8 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { out.writeOptionalWriteable(process); out.writeOptionalWriteable(jvm); out.writeOptionalWriteable(threadPool); - if (fs == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - fs.writeTo(out); - } - if (transport == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - transport.writeTo(out); - } + out.writeOptionalWriteable(fs); + out.writeOptionalWriteable(transport); if (http == null) { out.writeBoolean(false); } else { diff --git a/core/src/main/java/org/elasticsearch/transport/TransportStats.java b/core/src/main/java/org/elasticsearch/transport/TransportStats.java index e34197fd738..78e692939b7 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportStats.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportStats.java @@ -21,24 +21,20 @@ package org.elasticsearch.transport; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; -public class TransportStats implements Streamable, ToXContent { +public class TransportStats implements Writeable, ToXContent { - private long serverOpen; - private long rxCount; - private long rxSize; - private long txCount; - private long txSize; - - TransportStats() { - - } + private final long serverOpen; + private final long rxCount; + private final long rxSize; + private final long txCount; + private final long txSize; public TransportStats(long serverOpen, long rxCount, long rxSize, long txCount, long txSize) { this.serverOpen = serverOpen; @@ -48,6 +44,23 @@ public class TransportStats implements Streamable, ToXContent { this.txSize = txSize; } + public TransportStats(StreamInput in) throws IOException { + serverOpen = in.readVLong(); + rxCount = in.readVLong(); + rxSize = in.readVLong(); + txCount = in.readVLong(); + txSize = in.readVLong(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeVLong(serverOpen); + out.writeVLong(rxCount); + out.writeVLong(rxSize); + out.writeVLong(txCount); + out.writeVLong(txSize); + } + public long serverOpen() { return this.serverOpen; } @@ -88,30 +101,6 @@ public class TransportStats implements Streamable, ToXContent { return txSize(); } - public static TransportStats readTransportStats(StreamInput in) throws IOException { - TransportStats stats = new TransportStats(); - stats.readFrom(in); - return stats; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - serverOpen = in.readVLong(); - rxCount = in.readVLong(); - rxSize = in.readVLong(); - txCount = in.readVLong(); - txSize = in.readVLong(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeVLong(serverOpen); - out.writeVLong(rxCount); - out.writeVLong(rxSize); - out.writeVLong(txCount); - out.writeVLong(txSize); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.TRANSPORT);