ThreadPoolInfo to implement Writeable rather than Streamable

This commit is contained in:
javanna 2016-09-01 18:28:49 +02:00 committed by Luca Cavanna
parent 27e7fc734c
commit 2370c25fa4
2 changed files with 14 additions and 25 deletions

View File

@ -211,7 +211,7 @@ public class NodeInfo extends BaseNodeResponse {
jvm = new JvmInfo(in);
}
if (in.readBoolean()) {
threadPool = ThreadPoolInfo.readThreadPoolInfo(in);
threadPool = new ThreadPoolInfo(in);
}
if (in.readBoolean()) {
transport = TransportInfo.readTransportInfo(in);

View File

@ -21,49 +21,33 @@ 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 ThreadPoolInfo implements Streamable, Iterable<ThreadPool.Info>, ToXContent {
private List<ThreadPool.Info> infos;
ThreadPoolInfo() {
}
public class ThreadPoolInfo implements Writeable, Iterable<ThreadPool.Info>, ToXContent {
private final List<ThreadPool.Info> infos;
public ThreadPoolInfo(List<ThreadPool.Info> infos) {
this.infos = infos;
this.infos = Collections.unmodifiableList(infos);
}
@Override
public Iterator<ThreadPool.Info> iterator() {
return infos.iterator();
}
public static ThreadPoolInfo readThreadPoolInfo(StreamInput in) throws IOException {
ThreadPoolInfo info = new ThreadPoolInfo();
info.readFrom(in);
return info;
}
@Override
public void readFrom(StreamInput in) throws IOException {
public ThreadPoolInfo(StreamInput in) throws IOException {
int size = in.readVInt();
infos = new ArrayList<>(size);
List<ThreadPool.Info> infos = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ThreadPool.Info info = new ThreadPool.Info();
info.readFrom(in);
infos.add(info);
}
this.infos = Collections.unmodifiableList(infos);
}
@Override
@ -74,6 +58,11 @@ public class ThreadPoolInfo implements Streamable, Iterable<ThreadPool.Info>, To
}
}
@Override
public Iterator<ThreadPool.Info> iterator() {
return infos.iterator();
}
static final class Fields {
static final String THREAD_POOL = "thread_pool";
}