diff --git a/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 6abdc309e21..c7d16d1979b 100644 --- a/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -58,6 +58,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import static java.util.Collections.unmodifiableMap; @@ -138,7 +139,9 @@ public class ThreadPool extends AbstractComponent implements Scheduler, Closeabl THREAD_POOL_TYPES = Collections.unmodifiableMap(map); } - private Map executors = new HashMap<>(); + private final Map executors; + + private final ThreadPoolInfo threadPoolInfo; private final CachedTimeThread cachedTimeThread; @@ -207,6 +210,15 @@ public class ThreadPool extends AbstractComponent implements Scheduler, Closeabl executors.put(Names.SAME, new ExecutorHolder(DIRECT_EXECUTOR, new Info(Names.SAME, ThreadPoolType.DIRECT))); this.executors = unmodifiableMap(executors); + + final List infos = + executors + .values() + .stream() + .filter(holder -> holder.info.getName().equals("same") == false) + .map(holder -> holder.info) + .collect(Collectors.toList()); + this.threadPoolInfo = new ThreadPoolInfo(infos); this.scheduler = Scheduler.initScheduler(settings); TimeValue estimatedTimeInterval = ESTIMATED_TIME_INTERVAL_SETTING.get(settings); this.cachedTimeThread = new CachedTimeThread(EsExecutors.threadName(settings, "[timer]"), estimatedTimeInterval.millis()); @@ -239,16 +251,7 @@ public class ThreadPool extends AbstractComponent implements Scheduler, Closeabl } public ThreadPoolInfo info() { - List infos = new ArrayList<>(); - for (ExecutorHolder holder : executors.values()) { - String name = holder.info.getName(); - // no need to have info on "same" thread pool - if ("same".equals(name)) { - continue; - } - infos.add(holder.info); - } - return new ThreadPoolInfo(infos); + return threadPoolInfo; } public Info info(String name) { @@ -655,32 +658,29 @@ public class ThreadPool extends AbstractComponent implements Scheduler, Closeabl @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(name); - builder.field(Fields.TYPE, type.getType()); - if (min != -1) { - builder.field(Fields.MIN, min); - } - if (max != -1) { - builder.field(Fields.MAX, max); + builder.field("type", type.getType()); + + if (type == ThreadPoolType.SCALING) { + assert min != -1; + builder.field("core", min); + assert max != -1; + builder.field("max", max); + } else { + assert max != -1; + builder.field("size", max); } if (keepAlive != null) { - builder.field(Fields.KEEP_ALIVE, keepAlive.toString()); + builder.field("keep_alive", keepAlive.toString()); } if (queueSize == null) { - builder.field(Fields.QUEUE_SIZE, -1); + builder.field("queue_size", -1); } else { - builder.field(Fields.QUEUE_SIZE, queueSize.singles()); + builder.field("queue_size", queueSize.singles()); } builder.endObject(); return builder; } - static final class Fields { - static final String TYPE = "type"; - static final String MIN = "min"; - static final String MAX = "max"; - static final String KEEP_ALIVE = "keep_alive"; - static final String QUEUE_SIZE = "queue_size"; - } } /**