ScriptStats to implement Writeable rather than Streamable

Also removed ScriptStats#add method which was unused
This commit is contained in:
javanna 2016-09-02 16:48:44 +02:00 committed by Luca Cavanna
parent 3521e2e1a9
commit d7ad748be7
2 changed files with 15 additions and 24 deletions

View File

@ -219,7 +219,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
transport = in.readOptionalWriteable(TransportStats::new); transport = in.readOptionalWriteable(TransportStats::new);
http = in.readOptionalWriteable(HttpStats::new); http = in.readOptionalWriteable(HttpStats::new);
breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in); breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in);
scriptStats = in.readOptionalStreamable(ScriptStats::new); scriptStats = in.readOptionalWriteable(ScriptStats::new);
discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null)); discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null));
ingestStats = in.readOptionalWriteable(IngestStats::new); ingestStats = in.readOptionalWriteable(IngestStats::new);
} }
@ -242,7 +242,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
out.writeOptionalWriteable(transport); out.writeOptionalWriteable(transport);
out.writeOptionalWriteable(http); out.writeOptionalWriteable(http);
out.writeOptionalStreamable(breaker); out.writeOptionalStreamable(breaker);
out.writeOptionalStreamable(scriptStats); out.writeOptionalWriteable(scriptStats);
out.writeOptionalStreamable(discoveryStats); out.writeOptionalStreamable(discoveryStats);
out.writeOptionalWriteable(ingestStats); out.writeOptionalWriteable(ingestStats);
} }

View File

@ -21,39 +21,22 @@ package org.elasticsearch.script;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; 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.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class ScriptStats implements Streamable, ToXContent { public class ScriptStats implements Writeable, ToXContent {
private long compilations; private final long compilations;
private long cacheEvictions; private final long cacheEvictions;
public ScriptStats() {
}
public ScriptStats(long compilations, long cacheEvictions) { public ScriptStats(long compilations, long cacheEvictions) {
this.compilations = compilations; this.compilations = compilations;
this.cacheEvictions = cacheEvictions; this.cacheEvictions = cacheEvictions;
} }
public void add(ScriptStats stats) { public ScriptStats(StreamInput in) throws IOException {
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 {
compilations = in.readVLong(); compilations = in.readVLong();
cacheEvictions = in.readVLong(); cacheEvictions = in.readVLong();
} }
@ -64,6 +47,14 @@ public class ScriptStats implements Streamable, ToXContent {
out.writeVLong(cacheEvictions); out.writeVLong(cacheEvictions);
} }
public long getCompilations() {
return compilations;
}
public long getCacheEvictions() {
return cacheEvictions;
}
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.SCRIPT_STATS); builder.startObject(Fields.SCRIPT_STATS);