diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index 68ec0f39e6d..d697236472f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -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); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java index 729c6cb7364..5b9dadc85ec 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java @@ -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, ToXContent { - - private List infos; - - ThreadPoolInfo() { - } +public class ThreadPoolInfo implements Writeable, Iterable, ToXContent { + private final List infos; public ThreadPoolInfo(List infos) { - this.infos = infos; + this.infos = Collections.unmodifiableList(infos); } - @Override - public Iterator 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 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, To } } + @Override + public Iterator iterator() { + return infos.iterator(); + } + static final class Fields { static final String THREAD_POOL = "thread_pool"; }