From d7ad748be75a3669eab1919eabd5b417b0b3a051 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 2 Sep 2016 16:48:44 +0200 Subject: [PATCH] ScriptStats to implement Writeable rather than Streamable Also removed ScriptStats#add method which was unused --- .../admin/cluster/node/stats/NodeStats.java | 4 +-- .../org/elasticsearch/script/ScriptStats.java | 35 +++++++------------ 2 files changed, 15 insertions(+), 24 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 73a921c263f..a73dd4122da 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 @@ -219,7 +219,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { transport = in.readOptionalWriteable(TransportStats::new); http = in.readOptionalWriteable(HttpStats::new); breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in); - scriptStats = in.readOptionalStreamable(ScriptStats::new); + scriptStats = in.readOptionalWriteable(ScriptStats::new); discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null)); ingestStats = in.readOptionalWriteable(IngestStats::new); } @@ -242,7 +242,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { out.writeOptionalWriteable(transport); out.writeOptionalWriteable(http); out.writeOptionalStreamable(breaker); - out.writeOptionalStreamable(scriptStats); + out.writeOptionalWriteable(scriptStats); out.writeOptionalStreamable(discoveryStats); out.writeOptionalWriteable(ingestStats); } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptStats.java b/core/src/main/java/org/elasticsearch/script/ScriptStats.java index c08d220d572..33f5dc21874 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptStats.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptStats.java @@ -21,39 +21,22 @@ package org.elasticsearch.script; 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 ScriptStats implements Streamable, ToXContent { - private long compilations; - private long cacheEvictions; - - public ScriptStats() { - } +public class ScriptStats implements Writeable, ToXContent { + private final long compilations; + private final long cacheEvictions; public ScriptStats(long compilations, long cacheEvictions) { this.compilations = compilations; this.cacheEvictions = cacheEvictions; } - public void add(ScriptStats stats) { - this.compilations += stats.compilations; - this.cacheEvictions += stats.cacheEvictions; - } - - public long getCompilations() { - return compilations; - } - - public long getCacheEvictions() { - return cacheEvictions; - } - - @Override - public void readFrom(StreamInput in) throws IOException { + public ScriptStats(StreamInput in) throws IOException { compilations = in.readVLong(); cacheEvictions = in.readVLong(); } @@ -64,6 +47,14 @@ public class ScriptStats implements Streamable, ToXContent { out.writeVLong(cacheEvictions); } + public long getCompilations() { + return compilations; + } + + public long getCacheEvictions() { + return cacheEvictions; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.SCRIPT_STATS);