|
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; |
62 | 61 |
|
63 | 62 | import static java.util.Collections.unmodifiableMap; |
64 | 63 |
|
@@ -139,9 +138,7 @@ public static ThreadPoolType fromType(String type) { |
139 | 138 | THREAD_POOL_TYPES = Collections.unmodifiableMap(map); |
140 | 139 | } |
141 | 140 |
|
142 | | - private final Map<String, ExecutorHolder> executors; |
143 | | - |
144 | | - private final ThreadPoolInfo threadPoolInfo; |
| 141 | + private Map<String, ExecutorHolder> executors = new HashMap<>(); |
145 | 142 |
|
146 | 143 | private final CachedTimeThread cachedTimeThread; |
147 | 144 |
|
@@ -210,15 +207,6 @@ public ThreadPool(final Settings settings, final ExecutorBuilder<?>... customBui |
210 | 207 |
|
211 | 208 | executors.put(Names.SAME, new ExecutorHolder(DIRECT_EXECUTOR, new Info(Names.SAME, ThreadPoolType.DIRECT))); |
212 | 209 | 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); |
222 | 210 | this.scheduler = Scheduler.initScheduler(settings); |
223 | 211 | TimeValue estimatedTimeInterval = ESTIMATED_TIME_INTERVAL_SETTING.get(settings); |
224 | 212 | this.cachedTimeThread = new CachedTimeThread(EsExecutors.threadName(settings, "[timer]"), estimatedTimeInterval.millis()); |
@@ -251,7 +239,16 @@ public Counter estimatedTimeInMillisCounter() { |
251 | 239 | } |
252 | 240 |
|
253 | 241 | public ThreadPoolInfo info() { |
254 | | - return threadPoolInfo; |
| 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); |
255 | 252 | } |
256 | 253 |
|
257 | 254 | public Info info(String name) { |
@@ -658,29 +655,32 @@ public SizeValue getQueueSize() { |
658 | 655 | @Override |
659 | 656 | public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
660 | 657 | builder.startObject(name); |
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); |
| 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); |
671 | 664 | } |
672 | 665 | if (keepAlive != null) { |
673 | | - builder.field("keep_alive", keepAlive.toString()); |
| 666 | + builder.field(Fields.KEEP_ALIVE, keepAlive.toString()); |
674 | 667 | } |
675 | 668 | if (queueSize == null) { |
676 | | - builder.field("queue_size", -1); |
| 669 | + builder.field(Fields.QUEUE_SIZE, -1); |
677 | 670 | } else { |
678 | | - builder.field("queue_size", queueSize.singles()); |
| 671 | + builder.field(Fields.QUEUE_SIZE, queueSize.singles()); |
679 | 672 | } |
680 | 673 | builder.endObject(); |
681 | 674 | return builder; |
682 | 675 | } |
683 | 676 |
|
| 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