From 3521e2e1a9e3472a836a5a27d62d40e4465a0d37 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 2 Sep 2016 16:46:48 +0200 Subject: [PATCH] HttpStats to implement Writeable rather than Streamable --- .../admin/cluster/node/stats/NodeStats.java | 11 +----- .../org/elasticsearch/http/HttpStats.java | 37 +++++++------------ 2 files changed, 15 insertions(+), 33 deletions(-) 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 fd3d0fa5c95..73a921c263f 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 @@ -217,9 +217,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { threadPool = in.readOptionalWriteable(ThreadPoolStats::new); fs = in.readOptionalWriteable(FsInfo::new); transport = in.readOptionalWriteable(TransportStats::new); - if (in.readBoolean()) { - http = HttpStats.readHttpStats(in); - } + http = in.readOptionalWriteable(HttpStats::new); breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in); scriptStats = in.readOptionalStreamable(ScriptStats::new); discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null)); @@ -242,12 +240,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { out.writeOptionalWriteable(threadPool); out.writeOptionalWriteable(fs); out.writeOptionalWriteable(transport); - if (http == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - http.writeTo(out); - } + out.writeOptionalWriteable(http); out.writeOptionalStreamable(breaker); out.writeOptionalStreamable(scriptStats); out.writeOptionalStreamable(discoveryStats); diff --git a/core/src/main/java/org/elasticsearch/http/HttpStats.java b/core/src/main/java/org/elasticsearch/http/HttpStats.java index 973821f4a5e..d019a65f03b 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpStats.java +++ b/core/src/main/java/org/elasticsearch/http/HttpStats.java @@ -21,42 +21,23 @@ package org.elasticsearch.http; 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.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; -public class HttpStats implements Streamable, ToXContent { +public class HttpStats implements Writeable, ToXContent { - private long serverOpen; - private long totalOpen; - - HttpStats() { - - } + private final long serverOpen; + private final long totalOpen; public HttpStats(long serverOpen, long totalOpen) { this.serverOpen = serverOpen; this.totalOpen = totalOpen; } - public long getServerOpen() { - return this.serverOpen; - } - - public long getTotalOpen() { - return this.totalOpen; - } - - public static HttpStats readHttpStats(StreamInput in) throws IOException { - HttpStats stats = new HttpStats(); - stats.readFrom(in); - return stats; - } - - @Override - public void readFrom(StreamInput in) throws IOException { + public HttpStats(StreamInput in) throws IOException { serverOpen = in.readVLong(); totalOpen = in.readVLong(); } @@ -67,6 +48,14 @@ public class HttpStats implements Streamable, ToXContent { out.writeVLong(totalOpen); } + public long getServerOpen() { + return this.serverOpen; + } + + public long getTotalOpen() { + return this.totalOpen; + } + static final class Fields { static final String HTTP = "http"; static final String CURRENT_OPEN = "current_open";