AllCircuitBreakerStats and CircuitBreakerStats to implement Writeable rather than Streamable
This commit is contained in:
parent
38a7427c51
commit
b36bad6cc2
|
@ -218,7 +218,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
|
|||
fs = in.readOptionalWriteable(FsInfo::new);
|
||||
transport = in.readOptionalWriteable(TransportStats::new);
|
||||
http = in.readOptionalWriteable(HttpStats::new);
|
||||
breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in);
|
||||
breaker = in.readOptionalWriteable(AllCircuitBreakerStats::new);
|
||||
scriptStats = in.readOptionalWriteable(ScriptStats::new);
|
||||
discoveryStats = in.readOptionalWriteable(DiscoveryStats::new);
|
||||
ingestStats = in.readOptionalWriteable(IngestStats::new);
|
||||
|
@ -241,7 +241,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
|
|||
out.writeOptionalWriteable(fs);
|
||||
out.writeOptionalWriteable(transport);
|
||||
out.writeOptionalWriteable(http);
|
||||
out.writeOptionalStreamable(breaker);
|
||||
out.writeOptionalWriteable(breaker);
|
||||
out.writeOptionalWriteable(scriptStats);
|
||||
out.writeOptionalWriteable(discoveryStats);
|
||||
out.writeOptionalWriteable(ingestStats);
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.indices.breaker;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -30,18 +30,23 @@ import java.io.IOException;
|
|||
/**
|
||||
* Stats class encapsulating all of the different circuit breaker stats
|
||||
*/
|
||||
public class AllCircuitBreakerStats implements Streamable, ToXContent {
|
||||
public class AllCircuitBreakerStats implements Writeable, ToXContent {
|
||||
|
||||
private CircuitBreakerStats[] allStats = new CircuitBreakerStats[0];
|
||||
|
||||
public AllCircuitBreakerStats() {
|
||||
|
||||
}
|
||||
private final CircuitBreakerStats[] allStats;
|
||||
|
||||
public AllCircuitBreakerStats(CircuitBreakerStats[] allStats) {
|
||||
this.allStats = allStats;
|
||||
}
|
||||
|
||||
public AllCircuitBreakerStats(StreamInput in) throws IOException {
|
||||
allStats = in.readArray(CircuitBreakerStats::new, CircuitBreakerStats[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeArray(allStats);
|
||||
}
|
||||
|
||||
public CircuitBreakerStats[] getAllStats() {
|
||||
return this.allStats;
|
||||
}
|
||||
|
@ -55,33 +60,6 @@ public class AllCircuitBreakerStats implements Streamable, ToXContent {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static AllCircuitBreakerStats readOptionalAllCircuitBreakerStats(StreamInput in) throws IOException {
|
||||
AllCircuitBreakerStats stats = in.readOptionalStreamable(AllCircuitBreakerStats::new);
|
||||
return stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
int statCount = in.readVInt();
|
||||
CircuitBreakerStats[] newStats = new CircuitBreakerStats[statCount];
|
||||
for (int i = 0; i < statCount; i++) {
|
||||
CircuitBreakerStats stats = new CircuitBreakerStats();
|
||||
stats.readFrom(in);
|
||||
newStats[i] = stats;
|
||||
}
|
||||
allStats = newStats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(allStats.length);
|
||||
for (CircuitBreakerStats stats : allStats) {
|
||||
if (stats != null) {
|
||||
stats.writeTo(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(Fields.BREAKERS);
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.indices.breaker;
|
|||
|
||||
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;
|
||||
|
@ -32,17 +32,13 @@ import java.util.Locale;
|
|||
/**
|
||||
* Class encapsulating stats about the circuit breaker
|
||||
*/
|
||||
public class CircuitBreakerStats implements Streamable, ToXContent {
|
||||
public class CircuitBreakerStats implements Writeable, ToXContent {
|
||||
|
||||
private String name;
|
||||
private long limit;
|
||||
private long estimated;
|
||||
private long trippedCount;
|
||||
private double overhead;
|
||||
|
||||
CircuitBreakerStats() {
|
||||
|
||||
}
|
||||
private final String name;
|
||||
private final long limit;
|
||||
private final long estimated;
|
||||
private final long trippedCount;
|
||||
private final double overhead;
|
||||
|
||||
public CircuitBreakerStats(String name, long limit, long estimated, double overhead, long trippedCount) {
|
||||
this.name = name;
|
||||
|
@ -52,6 +48,24 @@ public class CircuitBreakerStats implements Streamable, ToXContent {
|
|||
this.overhead = overhead;
|
||||
}
|
||||
|
||||
public CircuitBreakerStats(StreamInput in) throws IOException {
|
||||
// limit is the maximum from the old circuit breaker stats for backwards compatibility
|
||||
limit = in.readLong();
|
||||
estimated = in.readLong();
|
||||
overhead = in.readDouble();
|
||||
this.trippedCount = in.readLong();
|
||||
this.name = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeLong(limit);
|
||||
out.writeLong(estimated);
|
||||
out.writeDouble(overhead);
|
||||
out.writeLong(trippedCount);
|
||||
out.writeString(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
@ -72,30 +86,6 @@ public class CircuitBreakerStats implements Streamable, ToXContent {
|
|||
return this.overhead;
|
||||
}
|
||||
|
||||
public static CircuitBreakerStats readOptionalCircuitBreakerStats(StreamInput in) throws IOException {
|
||||
CircuitBreakerStats stats = in.readOptionalStreamable(CircuitBreakerStats::new);
|
||||
return stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
// limit is the maximum from the old circuit breaker stats for backwards compatibility
|
||||
limit = in.readLong();
|
||||
estimated = in.readLong();
|
||||
overhead = in.readDouble();
|
||||
this.trippedCount = in.readLong();
|
||||
this.name = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeLong(limit);
|
||||
out.writeLong(estimated);
|
||||
out.writeDouble(overhead);
|
||||
out.writeLong(trippedCount);
|
||||
out.writeString(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(name.toLowerCase(Locale.ROOT));
|
||||
|
|
Loading…
Reference in New Issue