diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-09 23:14:07 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-09 23:14:07 +0200 |
commit | ef539860356ebcfe316ac8adc75aa183ab764ab4 (patch) | |
tree | 5ed3403cb6350177ab59243cfb13948a6bd493d2 /application/src/main | |
parent | 20513f2cb1f9c65406c32dd717e738d394fc1d1b (diff) |
Deliver search chains config to ExecutionFactory
Diffstat (limited to 'application/src/main')
3 files changed, 26 insertions, 29 deletions
diff --git a/application/src/main/java/com/yahoo/application/Application.java b/application/src/main/java/com/yahoo/application/Application.java index 64ced48edd3..f7b5174b0e5 100644 --- a/application/src/main/java/com/yahoo/application/Application.java +++ b/application/src/main/java/com/yahoo/application/Application.java @@ -46,7 +46,7 @@ public final class Application implements AutoCloseable { /** * This system property is set to "true" upon creation of an Application. - * This is useful for components which are created by dependendy injection which needs to modify + * This is useful for components which are created by dependendcy injection which needs to modify * their behavior to function without reliance on any processes outside the JVM. */ public static final String vespaLocalProperty = "vespa.local"; @@ -142,6 +142,7 @@ public final class Application implements AutoCloseable { */ @Beta public static class Builder { + private static final ThreadLocal<Random> random = new ThreadLocal<>(); private static final String DEFAULT_CHAIN = "default"; @@ -217,7 +218,7 @@ public final class Application implements AutoCloseable { } // copy from com.yahoo.application.ApplicationBuilder - private void createFile(final Path path, final String content) throws IOException { + private void createFile(Path path, String content) throws IOException { Files.createDirectories(path.getParent()); Files.write(path, Utf8.toBytes(content)); } @@ -237,16 +238,15 @@ public final class Application implements AutoCloseable { /** * @param name name of document type (search definition) * @param searchDefinition add this search definition to the application - * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder documentType(final String name, final String searchDefinition) throws IOException { + public Builder documentType(String name, String searchDefinition) throws IOException { Path path = nestedResource(ApplicationPackage.SEARCH_DEFINITIONS_DIR, name, ApplicationPackage.SD_NAME_SUFFIX); createFile(path, searchDefinition); return this; } - public Builder expressionInclude(final String name, final String searchDefinition) throws IOException { + public Builder expressionInclude(String name, String searchDefinition) throws IOException { Path path = nestedResource(ApplicationPackage.SEARCH_DEFINITIONS_DIR, name, ApplicationPackage.RANKEXPRESSION_NAME_SUFFIX); createFile(path, searchDefinition); return this; @@ -255,10 +255,9 @@ public final class Application implements AutoCloseable { /** * @param name name of rank expression * @param rankExpressionContent add this rank expression to the application - * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder rankExpression(final String name, final String rankExpressionContent) throws IOException { + public Builder rankExpression(String name, String rankExpressionContent) throws IOException { Path path = nestedResource(ApplicationPackage.SEARCH_DEFINITIONS_DIR, name, ApplicationPackage.RANKEXPRESSION_NAME_SUFFIX); createFile(path, rankExpressionContent); return this; @@ -270,7 +269,7 @@ public final class Application implements AutoCloseable { * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder queryProfile(final String name, final String queryProfile) throws IOException { + public Builder queryProfile(String name, String queryProfile) throws IOException { Path path = nestedResource(ApplicationPackage.QUERY_PROFILES_DIR, name, ".xml"); createFile(path, queryProfile); return this; @@ -282,14 +281,14 @@ public final class Application implements AutoCloseable { * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder queryProfileType(final String name, final String queryProfileType) throws IOException { + public Builder queryProfileType(String name, String queryProfileType) throws IOException { Path path = nestedResource(ApplicationPackage.QUERY_PROFILE_TYPES_DIR, name, ".xml"); createFile(path, queryProfileType); return this; } // copy from com.yahoo.application.ApplicationBuilder - private Path nestedResource(final com.yahoo.path.Path nestedPath, final String name, final String fileType) { + private Path nestedResource(com.yahoo.path.Path nestedPath, String name, String fileType) { String nameWithoutSuffix = StringUtilities.stripSuffix(name, fileType); return path.resolve(nestedPath.getRelative()).resolve(nameWithoutSuffix + fileType); } @@ -298,7 +297,7 @@ public final class Application implements AutoCloseable { * @param networking enable or disable networking (disabled by default) * @return builder */ - public Builder networking(final Networking networking) { + public Builder networking(Networking networking) { this.networking = networking; return this; } @@ -335,15 +334,14 @@ public final class Application implements AutoCloseable { private void generateXml() throws Exception { try (PrintWriter xml = new PrintWriter(Files.newOutputStream(path.resolve("services.xml")))) { xml.println("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); - //xml.println("<services version=\"1.0\">"); for (Map.Entry<String, Container> entry : containers.entrySet()) { entry.getValue().build(xml, entry.getKey(), (networking == Networking.enable ? getRandomPort() : -1)); } - //xml.println("</services>"); } } public static class Container { + private final Map<String, List<ComponentItem<? extends DocumentProcessor>>> docprocs = new LinkedHashMap<>(); private final Map<String, List<ComponentItem<? extends Searcher>>> searchers = new LinkedHashMap<>(); private final List<ComponentItem<? extends Renderer>> renderers = new ArrayList<>(); @@ -372,7 +370,7 @@ public final class Application implements AutoCloseable { * @param docproc add this docproc to the default document processing chain * @return builder */ - public Container documentProcessor(final Class<? extends DocumentProcessor> docproc) { + public Container documentProcessor(Class<? extends DocumentProcessor> docproc) { return documentProcessor(DEFAULT_CHAIN, docproc); } @@ -382,7 +380,7 @@ public final class Application implements AutoCloseable { * @param configs local docproc configs * @return builder */ - public Container documentProcessor(final String chainName, final Class<? extends DocumentProcessor> docproc, ConfigInstance... configs) { + public Container documentProcessor(String chainName, Class<? extends DocumentProcessor> docproc, ConfigInstance... configs) { return documentProcessor(docproc.getName(), chainName, docproc, configs); } @@ -393,7 +391,7 @@ public final class Application implements AutoCloseable { * @param configs local docproc configs * @return builder */ - public Container documentProcessor(String id, final String chainName, final Class<? extends DocumentProcessor> docproc, ConfigInstance... configs) { + public Container documentProcessor(String id, String chainName, Class<? extends DocumentProcessor> docproc, ConfigInstance... configs) { List<ComponentItem<? extends DocumentProcessor>> chain = docprocs.get(chainName); if (chain == null) { chain = new ArrayList<>(); @@ -416,7 +414,7 @@ public final class Application implements AutoCloseable { * @param searcher add this searcher to the default search chain * @return builder */ - public Container searcher(final Class<? extends Searcher> searcher) { + public Container searcher(Class<? extends Searcher> searcher) { return searcher(DEFAULT_CHAIN, searcher); } @@ -426,7 +424,7 @@ public final class Application implements AutoCloseable { * @param configs local searcher configs * @return builder */ - public Container searcher(final String chainName, final Class<? extends Searcher> searcher, ConfigInstance... configs) { + public Container searcher(String chainName, Class<? extends Searcher> searcher, ConfigInstance... configs) { return searcher(searcher.getName(), chainName, searcher, configs); } @@ -437,7 +435,7 @@ public final class Application implements AutoCloseable { * @param configs local searcher configs * @return builder */ - public Container searcher(String id, final String chainName, final Class<? extends Searcher> searcher, ConfigInstance... configs) { + public Container searcher(String id, String chainName, Class<? extends Searcher> searcher, ConfigInstance... configs) { List<ComponentItem<? extends Searcher>> chain = searchers.get(chainName); if (chain == null) { chain = new ArrayList<>(); @@ -453,7 +451,7 @@ public final class Application implements AutoCloseable { * @param configs local renderer configs * @return builder */ - public Container renderer(String id, final Class<? extends Renderer> renderer, ConfigInstance... configs) { + public Container renderer(String id, Class<? extends Renderer> renderer, ConfigInstance... configs) { renderers.add(new ComponentItem<>(id, renderer, configs)); return this; } @@ -463,7 +461,7 @@ public final class Application implements AutoCloseable { * @param handler the handler class * @return builder */ - public Container handler(final String binding, final Class<? extends RequestHandler> handler) { + public Container handler(String binding, Class<? extends RequestHandler> handler) { handlers.add(new ComponentItem<>(binding, handler)); return this; } @@ -473,7 +471,7 @@ public final class Application implements AutoCloseable { * @param client the client class * @return builder */ - public Container client(final String binding, final Class<? extends ClientProvider> client) { + public Container client(String binding, Class<? extends ClientProvider> client) { clients.add(new ComponentItem<>(binding, client)); return this; } @@ -483,7 +481,7 @@ public final class Application implements AutoCloseable { * @param server the server class * @return builder */ - public Container server(final String id, final Class<? extends ServerProvider> server) { + public Container server(String id, Class<? extends ServerProvider> server) { servers.add(new ComponentItem<>(id, server)); return this; } @@ -492,7 +490,7 @@ public final class Application implements AutoCloseable { * @param component make this component available to the container * @return builder */ - public Container component(final Class<?> component) { + public Container component(Class<?> component) { return component(component.getName(), component, (ConfigInstance) null); } @@ -500,7 +498,7 @@ public final class Application implements AutoCloseable { * @param component make this component available to the container * @return builder */ - public Container component(String id, final Class<?> component, ConfigInstance... configs) { + public Container component(String id, Class<?> component, ConfigInstance... configs) { components.add(new ComponentItem<>(id, component, configs)); return this; } diff --git a/application/src/main/java/com/yahoo/application/container/JDisc.java b/application/src/main/java/com/yahoo/application/container/JDisc.java index 45c7b66ac5e..10ff84d3ede 100644 --- a/application/src/main/java/com/yahoo/application/container/JDisc.java +++ b/application/src/main/java/com/yahoo/application/container/JDisc.java @@ -21,6 +21,7 @@ import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.test.TestDriver; import com.yahoo.processing.handler.ProcessingHandler; import com.yahoo.search.handler.SearchHandler; +import com.yahoo.search.searchchain.ExecutionFactory; import java.nio.file.Path; @@ -41,7 +42,7 @@ public final class JDisc implements AutoCloseable { @SuppressWarnings("unused") private final StandaloneContainerApplication application; - private final Container container = Container.get(); // TODO: This is indeed temporary ... *3 years later* Indeed. + private final Container container = Container.get(); // TODO: This is indeed temporary ... *3 years later* indeed. private final Path path; private final boolean deletePathWhenClosing; @@ -55,7 +56,7 @@ public final class JDisc implements AutoCloseable { application = (StandaloneContainerApplication) testDriver.application(); } - private Module bindings(final Path path, final ConfigModelRepo configModelRepo, final Networking networking) { + private Module bindings(Path path, ConfigModelRepo configModelRepo, Networking networking) { return new AbstractModule() { @Override protected void configure() { diff --git a/application/src/main/java/com/yahoo/application/container/Search.java b/application/src/main/java/com/yahoo/application/container/Search.java index f0a61bc6c10..0e241c27949 100644 --- a/application/src/main/java/com/yahoo/application/container/Search.java +++ b/application/src/main/java/com/yahoo/application/container/Search.java @@ -41,7 +41,6 @@ public final class Search extends ProcessingBase<Query, Result, Searcher> { } @Override - @SuppressWarnings("deprecation") protected ListenableFuture<Boolean> doProcessAndRender(ComponentSpecification chainSpec, Query request, Renderer<Result> renderer, @@ -51,7 +50,6 @@ public final class Search extends ProcessingBase<Query, Result, Searcher> { } @Override - @SuppressWarnings("deprecation") protected Renderer<Result> doGetRenderer(ComponentSpecification spec) { return handler.getRendererCopy(spec); } |