diff options
Diffstat (limited to 'container-core')
6 files changed, 37 insertions, 32 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java b/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java index d61df4310f0..926c67df0ba 100644 --- a/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java +++ b/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java @@ -14,6 +14,8 @@ import com.yahoo.component.ComponentSpecification; */ public final class BundleInstantiationSpecification { + public static final String CONTAINER_SEARCH_AND_DOCPROC = "container-search-and-docproc"; + public final ComponentId id; public final ComponentSpecification classId; public final ComponentSpecification bundle; @@ -31,34 +33,21 @@ public final class BundleInstantiationSpecification { assert (classId!= null); } - private static final String defaultInternalBundle = "container-search-and-docproc"; - - private static BundleInstantiationSpecification getInternalSpecificationFromString(String idSpec, String classSpec) { - return new BundleInstantiationSpecification( - new ComponentSpecification(idSpec), - (classSpec == null || classSpec.isEmpty())? null : new ComponentSpecification(classSpec), - new ComponentSpecification(defaultInternalBundle)); - } - - public static BundleInstantiationSpecification getInternalSearcherSpecification(ComponentSpecification idSpec, - ComponentSpecification classSpec) { - return new BundleInstantiationSpecification(idSpec, classSpec, new ComponentSpecification(defaultInternalBundle)); - } - - // TODO: These are the same for now because they are in the same bundle. - public static BundleInstantiationSpecification getInternalHandlerSpecificationFromStrings(String idSpec, String classSpec) { - return getInternalSpecificationFromString(idSpec, classSpec); - } - - public static BundleInstantiationSpecification getInternalProcessingSpecificationFromStrings(String idSpec, String classSpec) { - return getInternalSpecificationFromString(idSpec, classSpec); + /** + * Create spec for a component from the container-search-and-docproc bundle with the given class name as id. + */ + public static BundleInstantiationSpecification fromSearchAndDocproc(String className) { + return fromSearchAndDocproc(new ComponentSpecification(className), null); } - public static BundleInstantiationSpecification getInternalSearcherSpecificationFromStrings(String idSpec, String classSpec) { - return getInternalSpecificationFromString(idSpec, classSpec); + /** + * Create spec for a component from the container-search-and-docproc bundle with the given id and classId. + */ + public static BundleInstantiationSpecification fromSearchAndDocproc(ComponentSpecification id, ComponentSpecification classId) { + return new BundleInstantiationSpecification(id, classId, new ComponentSpecification(CONTAINER_SEARCH_AND_DOCPROC)); } - public static BundleInstantiationSpecification getFromStrings(String idSpec, String classSpec, String bundleSpec) { + public static BundleInstantiationSpecification fromStrings(String idSpec, String classSpec, String bundleSpec) { return new BundleInstantiationSpecification( new ComponentSpecification(idSpec), (classSpec == null || classSpec.isEmpty())? null : new ComponentSpecification(classSpec), diff --git a/container-core/src/main/java/com/yahoo/container/di/Container.java b/container-core/src/main/java/com/yahoo/container/di/Container.java index 68dda5fbc4c..1baf217da6b 100644 --- a/container-core/src/main/java/com/yahoo/container/di/Container.java +++ b/container-core/src/main/java/com/yahoo/container/di/Container.java @@ -299,7 +299,7 @@ public class Container { } private static BundleInstantiationSpecification bundleInstantiationSpecification(ComponentsConfig.Components config) { - return BundleInstantiationSpecification.getFromStrings(config.id(), config.classId(), config.bundle()); + return BundleInstantiationSpecification.fromStrings(config.id(), config.classId(), config.bundle()); } public static class ComponentGraphResult { diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java index 11355dee24f..fb7ba1ab39e 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java @@ -50,7 +50,7 @@ public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler this(executor, metric, false); } - // TODO: move Inject annotation here! + // TODO: deprecate this and the Context class. The context component set up in the model does not get a dedicated thread pool. public ThreadedHttpRequestHandler(Context context) { this(context.executor, context.metric); } diff --git a/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java b/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java index 5bed6fbca9f..84d52bb01c3 100644 --- a/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java +++ b/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java @@ -26,7 +26,7 @@ public class ComponentModel { } public ComponentModel(String idSpec, String classSpec, String bundleSpec, String configId) { - this(BundleInstantiationSpecification.getFromStrings(idSpec, classSpec, bundleSpec), configId); + this(BundleInstantiationSpecification.fromStrings(idSpec, classSpec, bundleSpec), configId); } // For vespamodel @@ -36,7 +36,7 @@ public class ComponentModel { // For vespamodel public ComponentModel(String idSpec, String classSpec, String bundleSpec) { - this(BundleInstantiationSpecification.getFromStrings(idSpec, classSpec, bundleSpec)); + this(BundleInstantiationSpecification.fromStrings(idSpec, classSpec, bundleSpec)); } public ComponentId getComponentId() { diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java index f8f567e1890..5abb96527bd 100644 --- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java +++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java @@ -102,7 +102,7 @@ public class ComponentGraphTest { } @Test - public void component_can_be_injected_into_another_component() { + public void component_can_be_explicitly_injected_into_another_component() { Node injectedComponent = mockComponentNode(SimpleComponent.class); Node targetComponent = mockComponentNode(ComponentTakingComponent.class); targetComponent.inject(injectedComponent); @@ -117,6 +117,22 @@ public class ComponentGraphTest { ComponentTakingComponent instance = componentGraph.getInstance(ComponentTakingComponent.class); assertNotNull(instance); + assertSame(injectedComponent.instance.get(), instance.injectedComponent); + } + + @Test + public void explicitly_injected_components_may_be_unused() { + Node notUsingInjected = mockComponentNode(SimpleComponent.class); + Node injectedComponent = mockComponentNode(SimpleComponent2.class); + notUsingInjected.inject(injectedComponent); + + ComponentGraph componentGraph = new ComponentGraph(); + componentGraph.add(injectedComponent); + componentGraph.add(notUsingInjected); + componentGraph.complete(); + + SimpleComponent instanceNotUsingInjected = componentGraph.getInstance(SimpleComponent.class); + assertNotNull(instanceNotUsingInjected); } @Test @@ -514,7 +530,7 @@ public class ComponentGraphTest { } public static class ComponentTakingComponent extends AbstractComponent { - private final SimpleComponent injectedComponent; + final SimpleComponent injectedComponent; public ComponentTakingComponent(SimpleComponent injectedComponent) { assertNotNull(injectedComponent); diff --git a/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java b/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java index 4433b78c807..a1e533158b5 100644 --- a/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java +++ b/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java @@ -14,7 +14,7 @@ public class ComponentModelTest { @Test public void create_from_instantiation_spec() { ComponentModel model = new ComponentModel( - BundleInstantiationSpecification.getFromStrings("id", "class", "bundle")); + BundleInstantiationSpecification.fromStrings("id", "class", "bundle")); verifyBundleSpec(model); } @@ -26,7 +26,7 @@ public class ComponentModelTest { @Test public void create_from_instantiation_spec_and_config_id() throws Exception { ComponentModel model = new ComponentModel( - BundleInstantiationSpecification.getFromStrings("id", "class", "bundle"), "configId"); + BundleInstantiationSpecification.fromStrings("id", "class", "bundle"), "configId"); verifyBundleSpec(model); assertEquals("configId", model.configId); } |