Search in sources :

Example 1 with XRejectedExecutionHandler

use of org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler in project crate by crate.

the class NodeThreadPoolExpression method addChildImplementations.

private void addChildImplementations() {
    childImplementations.put(POOL_NAME, new LiteralReferenceImplementation<>(name));
    childImplementations.put(ACTIVE, threadPoolExecutor::getActiveCount);
    childImplementations.put(REJECTED, () -> {
        long rejected = -1;
        RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler();
        if (rejectedExecutionHandler instanceof XRejectedExecutionHandler) {
            rejected = ((XRejectedExecutionHandler) rejectedExecutionHandler).rejected();
        }
        return rejected;
    });
    childImplementations.put(LARGEST, threadPoolExecutor::getLargestPoolSize);
    childImplementations.put(COMPLETED, threadPoolExecutor::getCompletedTaskCount);
    childImplementations.put(THREADS, threadPoolExecutor::getPoolSize);
    childImplementations.put(QUEUE, () -> threadPoolExecutor.getQueue().size());
}
Also used : RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) XRejectedExecutionHandler(org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler) XRejectedExecutionHandler(org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler)

Example 2 with XRejectedExecutionHandler

use of org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler in project elasticsearch by elastic.

the class ThreadPool method stats.

public ThreadPoolStats stats() {
    List<ThreadPoolStats.Stats> stats = 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;
        }
        int threads = -1;
        int queue = -1;
        int active = -1;
        long rejected = -1;
        int largest = -1;
        long completed = -1;
        if (holder.executor() instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) holder.executor();
            threads = threadPoolExecutor.getPoolSize();
            queue = threadPoolExecutor.getQueue().size();
            active = threadPoolExecutor.getActiveCount();
            largest = threadPoolExecutor.getLargestPoolSize();
            completed = threadPoolExecutor.getCompletedTaskCount();
            RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler();
            if (rejectedExecutionHandler instanceof XRejectedExecutionHandler) {
                rejected = ((XRejectedExecutionHandler) rejectedExecutionHandler).rejected();
            }
        }
        stats.add(new ThreadPoolStats.Stats(name, threads, queue, active, rejected, largest, completed));
    }
    return new ThreadPoolStats(stats);
}
Also used : RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) XRejectedExecutionHandler(org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler) XRejectedExecutionHandler(org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler) ArrayList(java.util.ArrayList) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) EsThreadPoolExecutor(org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Aggregations

RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)2 XRejectedExecutionHandler (org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler)2 ArrayList (java.util.ArrayList)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 EsThreadPoolExecutor (org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor)1