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);
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);
}

View File

@ -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);