DiscoveryStats and PendingClusterStateStats to implement Writeable rather than Streamable

This commit is contained in:
javanna 2016-09-02 16:52:55 +02:00 committed by Luca Cavanna
parent d7ad748be7
commit 38a7427c51
4 changed files with 34 additions and 48 deletions

View File

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

View File

@ -22,26 +22,34 @@ package org.elasticsearch.discovery;
import org.elasticsearch.common.Nullable;
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 org.elasticsearch.discovery.zen.publish.PendingClusterStateStats;
import java.io.IOException;
public class DiscoveryStats implements Streamable, ToXContent {
public class DiscoveryStats implements Writeable, ToXContent {
@Nullable
private PendingClusterStateStats queueStats;
private final PendingClusterStateStats queueStats;
public DiscoveryStats(PendingClusterStateStats queueStats) {
this.queueStats = queueStats;
}
public DiscoveryStats(StreamInput in) throws IOException {
queueStats = in.readOptionalWriteable(PendingClusterStateStats::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(queueStats);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.DISCOVERY);
if (queueStats != null ){
queueStats.toXContent(builder, params);
}
@ -49,24 +57,6 @@ public class DiscoveryStats implements Streamable, ToXContent {
return builder;
}
@Override
public void readFrom(StreamInput in) throws IOException {
if (in.readBoolean()) {
queueStats = new PendingClusterStateStats();
queueStats.readFrom(in);
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
if (queueStats != null ) {
out.writeBoolean(true);
queueStats.writeTo(out);
}else{
out.writeBoolean(false);
}
}
static final class Fields {
static final String DISCOVERY = "discovery";
}

View File

@ -47,6 +47,7 @@ import org.elasticsearch.discovery.BlockingClusterStatePublishResponseHandler;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.DiscoverySettings;
import org.elasticsearch.discovery.DiscoveryStats;
import org.elasticsearch.discovery.zen.publish.PendingClusterStateStats;
import java.util.HashSet;
import java.util.Optional;
@ -281,7 +282,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implements Discov
@Override
public DiscoveryStats stats() {
return new DiscoveryStats(null);
return new DiscoveryStats((PendingClusterStateStats)null);
}
@Override

View File

@ -21,7 +21,7 @@ package org.elasticsearch.discovery.zen.publish;
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,15 +30,11 @@ import java.io.IOException;
/**
* Class encapsulating stats about the PendingClusterStatsQueue
*/
public class PendingClusterStateStats implements Streamable, ToXContent {
public class PendingClusterStateStats implements Writeable, ToXContent {
private int total;
private int pending;
private int committed;
public PendingClusterStateStats() {
}
private final int total;
private final int pending;
private final int committed;
public PendingClusterStateStats(int total, int pending, int committed) {
this.total = total;
@ -46,6 +42,19 @@ public class PendingClusterStateStats implements Streamable, ToXContent {
this.committed = committed;
}
public PendingClusterStateStats(StreamInput in) throws IOException {
total = in.readVInt();
pending = in.readVInt();
committed = in.readVInt();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(total);
out.writeVInt(pending);
out.writeVInt(committed);
}
public int getCommitted() {
return committed;
}
@ -68,20 +77,6 @@ public class PendingClusterStateStats implements Streamable, ToXContent {
return builder;
}
@Override
public void readFrom(StreamInput in) throws IOException {
total = in.readVInt();
pending = in.readVInt();
committed = in.readVInt();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(total);
out.writeVInt(pending);
out.writeVInt(committed);
}
static final class Fields {
static final String QUEUE = "cluster_state_queue";
static final String TOTAL = "total";