diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-10-07 11:03:29 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-10-07 11:03:29 +0200 |
commit | 35a58a4c72c325eb7d2a2f9e217c9ffb042ca6d4 (patch) | |
tree | 0d3977ae27bb608c738145cbd90c76b62fd004dc | |
parent | c9335e0efde84cafdbc878fc4c4504e3ce12b93c (diff) |
Use Optional
5 files changed, 11 insertions, 10 deletions
diff --git a/container-core/abi-spec.json b/container-core/abi-spec.json index 45d6a9bcc03..458320c87df 100644 --- a/container-core/abi-spec.json +++ b/container-core/abi-spec.json @@ -630,6 +630,7 @@ "protected void <init>(java.util.concurrent.Executor, com.yahoo.jdisc.Metric)", "protected void <init>(java.util.concurrent.Executor, com.yahoo.jdisc.Metric, boolean)", "public final com.yahoo.jdisc.handler.ContentChannel handleRequest(com.yahoo.jdisc.Request, com.yahoo.jdisc.handler.ResponseHandler)", + "protected java.util.Optional getRequestType()", "public java.time.Duration getTimeout()", "public java.util.concurrent.Executor executor()", "protected abstract void handleRequest(com.yahoo.jdisc.Request, com.yahoo.jdisc.handler.BufferedContentChannel, com.yahoo.jdisc.handler.ResponseHandler)", diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedRequestHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedRequestHandler.java index 691675dfec9..5864ecf4b91 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedRequestHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedRequestHandler.java @@ -18,6 +18,7 @@ import com.yahoo.container.core.HandlerMetricContextUtil; import java.time.Duration; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; @@ -112,11 +113,11 @@ public abstract class ThreadedRequestHandler extends AbstractRequestHandler { * be overridden by setting a request type on individual responses in handleRequest * whenever it is invoked (i.e not for requests that are rejected early e.g due to overload).</p> * - * <p>This default implementation returns null.</p> + * <p>This default implementation returns empty.</p> * - * @return the request type to set, or null to not override the default classification based on request method + * @return the request type to set, or empty to not override the default classification based on request method */ - protected Request.RequestType getRequestType() { return null; } + protected Optional<Request.RequestType> getRequestType() { return Optional.empty(); } public Duration getTimeout() { return TIMEOUT; @@ -158,7 +159,7 @@ public abstract class ThreadedRequestHandler extends AbstractRequestHandler { */ protected void writeErrorResponseOnOverload(Request request, ResponseHandler responseHandler) { Response response = new Response(Response.Status.SERVICE_UNAVAILABLE); - response.setRequestType(getRequestType()); + getRequestType().ifPresent(type -> response.setRequestType(type)); ResponseDispatch.newInstance(response).dispatch(responseHandler); } @@ -202,8 +203,7 @@ public abstract class ThreadedRequestHandler extends AbstractRequestHandler { @Override public ContentChannel handleResponse(Response response) { if ( tryHasResponded()) throw new IllegalStateException("Response already handled"); - if (response.getRequestType() == null) - response.setRequestType(getRequestType()); + getRequestType().ifPresent(type -> response.setRequestType(type)); ContentChannel cc = responseHandler.handleResponse(response); HandlerMetricContextUtil.onHandled(request, metric, getClass()); return cc; diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index f8d5fb4e9a6..86e7ddc7e52 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -4225,6 +4225,7 @@ "public void <init>(com.yahoo.statistics.Statistics, com.yahoo.jdisc.Metric, java.util.concurrent.Executor, com.yahoo.container.logging.AccessLog, com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry, com.yahoo.search.searchchain.ExecutionFactory, java.util.Optional)", "public void <init>(com.yahoo.container.core.ChainsConfig, com.yahoo.search.config.IndexInfoConfig, com.yahoo.container.QrSearchersConfig, com.yahoo.vespa.configdefinition.SpecialtokensConfig, com.yahoo.statistics.Statistics, com.yahoo.language.Linguistics, com.yahoo.jdisc.Metric, com.yahoo.component.provider.ComponentRegistry, java.util.concurrent.Executor, com.yahoo.container.logging.AccessLog, com.yahoo.search.query.profile.config.QueryProfilesConfig, com.yahoo.component.provider.ComponentRegistry, com.yahoo.container.core.ContainerHttpConfig)", "public final com.yahoo.container.jdisc.HttpResponse handle(com.yahoo.container.jdisc.HttpRequest)", + "public java.util.Optional getRequestType()", "public com.yahoo.search.Result searchAndFill(com.yahoo.search.Query, com.yahoo.component.chain.Chain)", "public com.yahoo.processing.rendering.Renderer getRendererCopy(com.yahoo.component.ComponentSpecification)", "public com.yahoo.search.searchchain.SearchChainRegistry getSearchChainRegistry()", diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java index 80dc7a7b489..d4ebec6677a 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java @@ -252,7 +252,7 @@ public class SearchHandler extends LoggingRequestHandler { } @Override - public Request.RequestType getRequestType() { return Request.RequestType.READ; } + public Optional<Request.RequestType> getRequestType() { return Optional.of(Request.RequestType.READ); } private int getHttpResponseStatus(com.yahoo.container.jdisc.HttpRequest httpRequest, Result result) { boolean benchmarkOutput = VespaHeaders.benchmarkOutput(httpRequest); diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java index cdb9a624f22..98bbb029ea8 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java @@ -122,9 +122,8 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler { ClusterListConfig clusterListConfig, AllClustersBucketSpacesConfig bucketSpacesConfig, DocumentOperationExecutorConfig executorConfig) { - this(Clock.systemU - TC(), - new DocumentOperationExecutorImpl(clusterListConfig, bucketSpacesConfig, executorConfig, documentAccess, clock), + this(Clock.systemUTC(), + new DocumentOperationExecutorImpl(clusterListConfig, bucketSpacesConfig, executorConfig, documentAccess, Clock.systemUTC()), new DocumentOperationParser(documentManagerConfig), metric, metricReceiver); |