ThreadPoolStats to implement Writeable rather than Streamable
This commit is contained in:
parent
102dac2cd9
commit
9c62a12fee
|
@ -211,18 +211,10 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
|
|||
if (in.readBoolean()) {
|
||||
indices = NodeIndicesStats.readIndicesStats(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
os = new OsStats(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
process = new ProcessStats(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
jvm = new JvmStats(in);
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
threadPool = ThreadPoolStats.readThreadPoolStats(in);
|
||||
}
|
||||
os = in.readOptionalWriteable(OsStats::new);
|
||||
process = in.readOptionalWriteable(ProcessStats::new);
|
||||
jvm = in.readOptionalWriteable(JvmStats::new);
|
||||
threadPool = in.readOptionalWriteable(ThreadPoolStats::new);
|
||||
if (in.readBoolean()) {
|
||||
fs = new FsInfo(in);
|
||||
}
|
||||
|
@ -248,30 +240,10 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
|
|||
out.writeBoolean(true);
|
||||
indices.writeTo(out);
|
||||
}
|
||||
if (os == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
os.writeTo(out);
|
||||
}
|
||||
if (process == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
process.writeTo(out);
|
||||
}
|
||||
if (jvm == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
jvm.writeTo(out);
|
||||
}
|
||||
if (threadPool == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
threadPool.writeTo(out);
|
||||
}
|
||||
out.writeOptionalWriteable(os);
|
||||
out.writeOptionalWriteable(process);
|
||||
out.writeOptionalWriteable(jvm);
|
||||
out.writeOptionalWriteable(threadPool);
|
||||
if (fs == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
|
|
|
@ -21,33 +21,26 @@ package org.elasticsearch.threadpool;
|
|||
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ThreadPoolStats implements Streamable, ToXContent, Iterable<ThreadPoolStats.Stats> {
|
||||
public class ThreadPoolStats implements Writeable, ToXContent, Iterable<ThreadPoolStats.Stats> {
|
||||
|
||||
public static class Stats implements Streamable, ToXContent, Comparable<Stats> {
|
||||
public static class Stats implements Writeable, ToXContent, Comparable<Stats> {
|
||||
|
||||
private String name;
|
||||
private int threads;
|
||||
private int queue;
|
||||
private int active;
|
||||
private long rejected;
|
||||
private int largest;
|
||||
private long completed;
|
||||
|
||||
Stats() {
|
||||
|
||||
}
|
||||
private final String name;
|
||||
private final int threads;
|
||||
private final int queue;
|
||||
private final int active;
|
||||
private final long rejected;
|
||||
private final int largest;
|
||||
private final long completed;
|
||||
|
||||
public Stats(String name, int threads, int queue, int active, long rejected, int largest, long completed) {
|
||||
this.name = name;
|
||||
|
@ -59,6 +52,27 @@ public class ThreadPoolStats implements Streamable, ToXContent, Iterable<ThreadP
|
|||
this.completed = completed;
|
||||
}
|
||||
|
||||
public Stats(StreamInput in) throws IOException {
|
||||
name = in.readString();
|
||||
threads = in.readInt();
|
||||
queue = in.readInt();
|
||||
active = in.readInt();
|
||||
rejected = in.readLong();
|
||||
largest = in.readInt();
|
||||
completed = in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(name);
|
||||
out.writeInt(threads);
|
||||
out.writeInt(queue);
|
||||
out.writeInt(active);
|
||||
out.writeLong(rejected);
|
||||
out.writeInt(largest);
|
||||
out.writeLong(completed);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
@ -87,28 +101,6 @@ public class ThreadPoolStats implements Streamable, ToXContent, Iterable<ThreadP
|
|||
return this.completed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
name = in.readString();
|
||||
threads = in.readInt();
|
||||
queue = in.readInt();
|
||||
active = in.readInt();
|
||||
rejected = in.readLong();
|
||||
largest = in.readInt();
|
||||
completed = in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(name);
|
||||
out.writeInt(threads);
|
||||
out.writeInt(queue);
|
||||
out.writeInt(active);
|
||||
out.writeLong(rejected);
|
||||
out.writeInt(largest);
|
||||
out.writeLong(completed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(name);
|
||||
|
@ -154,43 +146,23 @@ public class ThreadPoolStats implements Streamable, ToXContent, Iterable<ThreadP
|
|||
|
||||
private List<Stats> stats;
|
||||
|
||||
ThreadPoolStats() {
|
||||
|
||||
}
|
||||
|
||||
public ThreadPoolStats(List<Stats> stats) {
|
||||
Collections.sort(stats);
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Stats> iterator() {
|
||||
return stats.iterator();
|
||||
}
|
||||
|
||||
public static ThreadPoolStats readThreadPoolStats(StreamInput in) throws IOException {
|
||||
ThreadPoolStats stats = new ThreadPoolStats();
|
||||
stats.readFrom(in);
|
||||
return stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
int size = in.readVInt();
|
||||
stats = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Stats stats1 = new Stats();
|
||||
stats1.readFrom(in);
|
||||
stats.add(stats1);
|
||||
}
|
||||
public ThreadPoolStats(StreamInput in) throws IOException {
|
||||
stats = in.readList(Stats::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVInt(stats.size());
|
||||
for (Stats stat : stats) {
|
||||
stat.writeTo(out);
|
||||
}
|
||||
out.writeList(stats);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Stats> iterator() {
|
||||
return stats.iterator();
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
|
|
Loading…
Reference in New Issue