TransportStats to implement Writeable rather than Streamable

This commit is contained in:
javanna 2016-09-02 16:45:16 +02:00 committed by Luca Cavanna
parent 9c62a12fee
commit e263c64072
2 changed files with 28 additions and 53 deletions

View File

@ -215,12 +215,8 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
process = in.readOptionalWriteable(ProcessStats::new); process = in.readOptionalWriteable(ProcessStats::new);
jvm = in.readOptionalWriteable(JvmStats::new); jvm = in.readOptionalWriteable(JvmStats::new);
threadPool = in.readOptionalWriteable(ThreadPoolStats::new); threadPool = in.readOptionalWriteable(ThreadPoolStats::new);
if (in.readBoolean()) { fs = in.readOptionalWriteable(FsInfo::new);
fs = new FsInfo(in); transport = in.readOptionalWriteable(TransportStats::new);
}
if (in.readBoolean()) {
transport = TransportStats.readTransportStats(in);
}
if (in.readBoolean()) { if (in.readBoolean()) {
http = HttpStats.readHttpStats(in); http = HttpStats.readHttpStats(in);
} }
@ -244,18 +240,8 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
out.writeOptionalWriteable(process); out.writeOptionalWriteable(process);
out.writeOptionalWriteable(jvm); out.writeOptionalWriteable(jvm);
out.writeOptionalWriteable(threadPool); out.writeOptionalWriteable(threadPool);
if (fs == null) { out.writeOptionalWriteable(fs);
out.writeBoolean(false); out.writeOptionalWriteable(transport);
} else {
out.writeBoolean(true);
fs.writeTo(out);
}
if (transport == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
transport.writeTo(out);
}
if (http == null) { if (http == null) {
out.writeBoolean(false); out.writeBoolean(false);
} else { } else {

View File

@ -21,24 +21,20 @@ package org.elasticsearch.transport;
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.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
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 TransportStats implements Streamable, ToXContent { public class TransportStats implements Writeable, ToXContent {
private long serverOpen; private final long serverOpen;
private long rxCount; private final long rxCount;
private long rxSize; private final long rxSize;
private long txCount; private final long txCount;
private long txSize; private final long txSize;
TransportStats() {
}
public TransportStats(long serverOpen, long rxCount, long rxSize, long txCount, long txSize) { public TransportStats(long serverOpen, long rxCount, long rxSize, long txCount, long txSize) {
this.serverOpen = serverOpen; this.serverOpen = serverOpen;
@ -48,6 +44,23 @@ public class TransportStats implements Streamable, ToXContent {
this.txSize = txSize; this.txSize = txSize;
} }
public TransportStats(StreamInput in) throws IOException {
serverOpen = in.readVLong();
rxCount = in.readVLong();
rxSize = in.readVLong();
txCount = in.readVLong();
txSize = in.readVLong();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(serverOpen);
out.writeVLong(rxCount);
out.writeVLong(rxSize);
out.writeVLong(txCount);
out.writeVLong(txSize);
}
public long serverOpen() { public long serverOpen() {
return this.serverOpen; return this.serverOpen;
} }
@ -88,30 +101,6 @@ public class TransportStats implements Streamable, ToXContent {
return txSize(); return txSize();
} }
public static TransportStats readTransportStats(StreamInput in) throws IOException {
TransportStats stats = new TransportStats();
stats.readFrom(in);
return stats;
}
@Override
public void readFrom(StreamInput in) throws IOException {
serverOpen = in.readVLong();
rxCount = in.readVLong();
rxSize = in.readVLong();
txCount = in.readVLong();
txSize = in.readVLong();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(serverOpen);
out.writeVLong(rxCount);
out.writeVLong(rxSize);
out.writeVLong(txCount);
out.writeVLong(txSize);
}
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.TRANSPORT); builder.startObject(Fields.TRANSPORT);