|
58 | 58 | import java.util.concurrent.ScheduledThreadPoolExecutor; |
59 | 59 | import java.util.concurrent.ThreadPoolExecutor; |
60 | 60 | import java.util.concurrent.TimeUnit; |
| 61 | +import java.util.stream.Collectors; |
61 | 62 |
|
62 | 63 | import static java.util.Collections.unmodifiableMap; |
63 | 64 |
|
@@ -138,7 +139,9 @@ public static ThreadPoolType fromType(String type) { |
138 | 139 | THREAD_POOL_TYPES = Collections.unmodifiableMap(map); |
139 | 140 | } |
140 | 141 |
|
141 | | - private Map<String, ExecutorHolder> executors = new HashMap<>(); |
| 142 | + private final Map<String, ExecutorHolder> executors; |
| 143 | + |
| 144 | + private final ThreadPoolInfo threadPoolInfo; |
142 | 145 |
|
143 | 146 | private final CachedTimeThread cachedTimeThread; |
144 | 147 |
|
@@ -207,6 +210,15 @@ public ThreadPool(final Settings settings, final ExecutorBuilder<?>... customBui |
207 | 210 |
|
208 | 211 | executors.put(Names.SAME, new ExecutorHolder(DIRECT_EXECUTOR, new Info(Names.SAME, ThreadPoolType.DIRECT))); |
209 | 212 | this.executors = unmodifiableMap(executors); |
| 213 | + |
| 214 | + final List<Info> infos = |
| 215 | + executors |
| 216 | + .values() |
| 217 | + .stream() |
| 218 | + .filter(holder -> holder.info.getName().equals("same") == false) |
| 219 | + .map(holder -> holder.info) |
| 220 | + .collect(Collectors.toList()); |
| 221 | + this.threadPoolInfo = new ThreadPoolInfo(infos); |
210 | 222 | this.scheduler = Scheduler.initScheduler(settings); |
211 | 223 | TimeValue estimatedTimeInterval = ESTIMATED_TIME_INTERVAL_SETTING.get(settings); |
212 | 224 | this.cachedTimeThread = new CachedTimeThread(EsExecutors.threadName(settings, "[timer]"), estimatedTimeInterval.millis()); |
@@ -239,16 +251,7 @@ public Counter estimatedTimeInMillisCounter() { |
239 | 251 | } |
240 | 252 |
|
241 | 253 | public ThreadPoolInfo info() { |
242 | | - List<Info> infos = new ArrayList<>(); |
243 | | - for (ExecutorHolder holder : executors.values()) { |
244 | | - String name = holder.info.getName(); |
245 | | - // no need to have info on "same" thread pool |
246 | | - if ("same".equals(name)) { |
247 | | - continue; |
248 | | - } |
249 | | - infos.add(holder.info); |
250 | | - } |
251 | | - return new ThreadPoolInfo(infos); |
| 254 | + return threadPoolInfo; |
252 | 255 | } |
253 | 256 |
|
254 | 257 | public Info info(String name) { |
@@ -655,32 +658,29 @@ public SizeValue getQueueSize() { |
655 | 658 | @Override |
656 | 659 | public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
657 | 660 | builder.startObject(name); |
658 | | - builder.field(Fields.TYPE, type.getType()); |
659 | | - if (min != -1) { |
660 | | - builder.field(Fields.MIN, min); |
661 | | - } |
662 | | - if (max != -1) { |
663 | | - builder.field(Fields.MAX, max); |
| 661 | + builder.field("type", type.getType()); |
| 662 | + |
| 663 | + if (type == ThreadPoolType.SCALING) { |
| 664 | + assert min != -1; |
| 665 | + builder.field("core", min); |
| 666 | + assert max != -1; |
| 667 | + builder.field("max", max); |
| 668 | + } else { |
| 669 | + assert max != -1; |
| 670 | + builder.field("size", max); |
664 | 671 | } |
665 | 672 | if (keepAlive != null) { |
666 | | - builder.field(Fields.KEEP_ALIVE, keepAlive.toString()); |
| 673 | + builder.field("keep_alive", keepAlive.toString()); |
667 | 674 | } |
668 | 675 | if (queueSize == null) { |
669 | | - builder.field(Fields.QUEUE_SIZE, -1); |
| 676 | + builder.field("queue_size", -1); |
670 | 677 | } else { |
671 | | - builder.field(Fields.QUEUE_SIZE, queueSize.singles()); |
| 678 | + builder.field("queue_size", queueSize.singles()); |
672 | 679 | } |
673 | 680 | builder.endObject(); |
674 | 681 | return builder; |
675 | 682 | } |
676 | 683 |
|
677 | | - static final class Fields { |
678 | | - static final String TYPE = "type"; |
679 | | - static final String MIN = "min"; |
680 | | - static final String MAX = "max"; |
681 | | - static final String KEEP_ALIVE = "keep_alive"; |
682 | | - static final String QUEUE_SIZE = "queue_size"; |
683 | | - } |
684 | 684 | } |
685 | 685 |
|
686 | 686 | /** |
|
0 commit comments