From eb574425b7c1a78a13c7a8389cb6ca3a25e5ee63 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 5 Dec 2017 06:58:34 -0500 Subject: [PATCH] Simplify rejected execution exception This exception type has several unnecessary constructor overrides so this commit removes them. Relates #27664 --- .../common/util/concurrent/EsExecutors.java | 10 ++++++--- .../EsRejectedExecutionException.java | 22 ++++++------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java index 45d9a208284..057a970470b 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java @@ -246,13 +246,16 @@ public class EsExecutors { * waiting if necessary for space to become available. */ static class ForceQueuePolicy implements XRejectedExecutionHandler { + @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { + // force queue policy should only be used with a scaling queue + assert executor.getQueue() instanceof ExecutorScalingQueue; executor.getQueue().put(r); - } catch (InterruptedException e) { - //should never happen since we never wait - throw new EsRejectedExecutionException(e); + } catch (final InterruptedException e) { + // a scaling queue never blocks so a put to it can never be interrupted + throw new AssertionError(e); } } @@ -260,6 +263,7 @@ public class EsExecutors { public long rejected() { return 0; } + } } diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java index 01fbbac725b..f05b9d10926 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java @@ -27,29 +27,20 @@ import org.elasticsearch.rest.RestStatus; import java.io.IOException; public class EsRejectedExecutionException extends ElasticsearchException { + private final boolean isExecutorShutdown; - public EsRejectedExecutionException(String message, boolean isExecutorShutdown, Object... args) { - super(message, args); + public EsRejectedExecutionException(String message, boolean isExecutorShutdown) { + super(message, isExecutorShutdown); this.isExecutorShutdown = isExecutorShutdown; } - public EsRejectedExecutionException(String message, Object... args) { - this(message, false, args); - } - - public EsRejectedExecutionException(String message, boolean isExecutorShutdown) { - this(message, isExecutorShutdown, new Object[0]); + public EsRejectedExecutionException(String message) { + this(message, false); } public EsRejectedExecutionException() { - super((String)null); - this.isExecutorShutdown = false; - } - - public EsRejectedExecutionException(Throwable e) { - super(null, e); - this.isExecutorShutdown = false; + this(null, false); } @Override @@ -79,4 +70,5 @@ public class EsRejectedExecutionException extends ElasticsearchException { public boolean isExecutorShutdown() { return isExecutorShutdown; } + }