diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-10-08 12:53:14 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-10-08 12:53:14 +0200 |
commit | 9d435e48c742b3efc94c68c02da835c5f5298255 (patch) | |
tree | d3b95fd76df8e1a53abb1e1e2e3b966d4a7225e6 /container-search/src/main/java/com | |
parent | 9794b7ddbdeaa980970c2c0b54721d7a6f27a22a (diff) |
Make executor never null
Diffstat (limited to 'container-search/src/main/java/com')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/searchchain/Execution.java | 16 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java | 3 |
2 files changed, 11 insertions, 8 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java b/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java index 331dd7ca165..86ba8664dee 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java @@ -122,7 +122,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { this.tokenRegistry = tokenRegistry; this.rendererRegistry = rendererRegistry; this.linguistics = linguistics; - this.executor = executor; + this.executor = executor != null ? executor : Runnable::run; // Run in same thread if no executor is provided } /** @deprecated pass an executor */ @@ -167,6 +167,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { * * @param sourceContext the context from which to get the parameters */ + // TODO: Deprecate public void populateFrom(Context sourceContext) { // breakdown and detailedDiagnostics has no unset state, so they are always copied detailedDiagnostics = sourceContext.detailedDiagnostics; @@ -181,9 +182,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { rendererRegistry = sourceContext.rendererRegistry; if (linguistics == null) linguistics = sourceContext.linguistics; - if (executor == null) - executor = sourceContext.executor; - + executor = sourceContext.executor; // executor will always either be the same, or we're in a test } /** @@ -361,8 +360,11 @@ public class Execution extends com.yahoo.processing.execution.Execution { this.linguistics = linguistics; } - /** Returns the executor that should be used to execute tasks as part of this execution, or null if none */ - public Executor getExecutor() { return executor; } + /** + * Returns the executor that should be used to execute tasks as part of this execution. + * This is never null but will be an executor that runs in the same thread if none is passed to this. + */ + public Executor executor() { return executor; } /** Creates a child trace if this has an owner, or a root trace otherwise */ private Trace createChildTrace() { @@ -474,7 +476,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { // "if any" because a context may, or may not, belong to an execution. // This is decided at the creation time of the Context - Context instances which do not belong // to an execution plays the role of data carriers between executions. - super(searchChain,searcherIndex,context.createChildTrace(),context.createChildEnvironment()); + super(searchChain, searcherIndex, context.createChildTrace(), context.createChildEnvironment()); this.context.fill(context); contextCache = new Context[searchChain.components().size()]; entryIndex=searcherIndex; diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java b/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java index 3ec29a77323..210a77ccf57 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java @@ -23,6 +23,7 @@ import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.vespa.configdefinition.SpecialtokensConfig; import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * Provides creation of fully configured query Execution instances. @@ -65,7 +66,7 @@ public class ExecutionFactory extends AbstractComponent { this.specialTokens = new SpecialTokenRegistry(specialTokens); this.linguistics = linguistics; this.rendererRegistry = new RendererRegistry(renderers.allComponents()); - this.executor = executor; + this.executor = executor != null ? executor : Runnable::run; } /** @deprecated pass the container threadpool */ |