aboutsummaryrefslogtreecommitdiffstats
path: root/container-di
diff options
context:
space:
mode:
Diffstat (limited to 'container-di')
-rw-r--r--container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java4
-rw-r--r--container-di/src/main/java/com/yahoo/container/di/Container.java12
-rw-r--r--container-di/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java6
-rw-r--r--container-di/src/test/java/com/yahoo/container/di/ContainerTest.java29
4 files changed, 26 insertions, 25 deletions
diff --git a/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java b/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java
index dbfb842204d..09f72c9d86d 100644
--- a/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java
+++ b/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java
@@ -1,10 +1,12 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.di;
+import java.util.Collection;
+
/**
* @author gjoranv
* @author Tony Vaagenes
*/
public interface ComponentDeconstructor {
- void deconstruct(Object component);
+ void deconstruct(Collection<Object> components);
}
diff --git a/container-di/src/main/java/com/yahoo/container/di/Container.java b/container-di/src/main/java/com/yahoo/container/di/Container.java
index 0c534b0673c..f82fd22f40d 100644
--- a/container-di/src/main/java/com/yahoo/container/di/Container.java
+++ b/container-di/src/main/java/com/yahoo/container/di/Container.java
@@ -69,7 +69,7 @@ public class Container {
IdentityHashMap<Object, Object> oldComponents = new IdentityHashMap<>();
oldGraph.allConstructedComponentsAndProviders().forEach(c -> oldComponents.put(c, null));
newGraph.allConstructedComponentsAndProviders().forEach(oldComponents::remove);
- oldComponents.keySet().forEach(componentDeconstructor::deconstruct);
+ componentDeconstructor.deconstruct(oldComponents.keySet());
}
public ComponentGraph getNewComponentGraph(ComponentGraph oldGraph, Injector fallbackInjector, boolean restartOnRedeploy) {
@@ -184,7 +184,7 @@ public class Container {
}
}
- public void installBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) {
+ private void installBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) {
BundlesConfig bundlesConfig = getConfig(bundlesConfigKey, configsIncludingBootstrapConfigs);
osgi.useBundles(bundlesConfig.bundle());
}
@@ -209,7 +209,7 @@ public class Container {
private void addNodes(ComponentsConfig componentsConfig, ComponentGraph graph) {
for (ComponentsConfig.Components config : componentsConfig.components()) {
- BundleInstantiationSpecification specification = bundleInstatiationSpecification(config);
+ BundleInstantiationSpecification specification = bundleInstantiationSpecification(config);
Class<?> componentClass = osgi.resolveClass(specification);
Node componentNode;
@@ -234,7 +234,7 @@ public class Container {
}
}
- public void shutdownConfigurer() {
+ void shutdownConfigurer() {
configurer.shutdown();
}
@@ -244,7 +244,7 @@ public class Container {
}
private void deconstructAllComponents(ComponentGraph graph, ComponentDeconstructor deconstructor) {
- graph.allConstructedComponentsAndProviders().forEach(deconstructor::deconstruct);
+ deconstructor.deconstruct(graph.allConstructedComponentsAndProviders());
}
public static <T extends ConfigInstance> T getConfig(ConfigKey<T> key,
@@ -258,7 +258,7 @@ public class Container {
return key.getConfigClass().cast(inst);
}
- public static BundleInstantiationSpecification bundleInstatiationSpecification(ComponentsConfig.Components config) {
+ private static BundleInstantiationSpecification bundleInstantiationSpecification(ComponentsConfig.Components config) {
return BundleInstantiationSpecification.getFromStrings(config.id(), config.classId(), config.bundle());
}
diff --git a/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java b/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java
index f55d68ad708..d07aefef75b 100644
--- a/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java
+++ b/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java
@@ -158,14 +158,14 @@ public class ComponentGraph {
// reset instances with modified dependencies
for (Node node : topologicalSort(nodes())) {
for (Node usedComponent : node.usedComponents()) {
- if (!usedComponent.instance.isPresent()) {
+ if (usedComponent.instance.isEmpty()) {
node.instance = Optional.empty();
}
}
}
}
- public Collection<?> allConstructedComponentsAndProviders() {
+ public Collection<Object> allConstructedComponentsAndProviders() {
return nodes().stream().map(node -> node.constructedInstance().get()).collect(Collectors.toList());
}
@@ -252,7 +252,7 @@ public class ComponentGraph {
private Node lookupOrCreateGlobalComponent(Node node, Injector fallbackInjector, Class<?> clazz, Key<?> key) {
Optional<Node> component = lookupGlobalComponent(key);
- if (!component.isPresent()) {
+ if (component.isEmpty()) {
Object instance;
try {
log.log(LogLevel.DEBUG, "Trying the fallback injector to create" + messageForNoGlobalComponent(clazz, node));
diff --git a/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java b/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java
index 3996dff2811..9c4891c7db2 100644
--- a/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java
+++ b/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java
@@ -15,6 +15,7 @@ import com.yahoo.container.di.config.RestApiContext;
import org.junit.Ignore;
import org.junit.Test;
+import java.util.Collection;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -282,17 +283,13 @@ public class ContainerTest extends ContainerTestBase {
public void providers_are_destructed() {
writeBootstrapConfigs("id1", DestructableProvider.class);
- ComponentDeconstructor deconstructor = new ComponentDeconstructor() {
- @Override
- public void deconstruct(Object component) {
- if (component instanceof AbstractComponent) {
- ((AbstractComponent) component).deconstruct();
- ;
- } else if (component instanceof Provider) {
- ((Provider<?>) component).deconstruct();
- }
+ ComponentDeconstructor deconstructor = components -> components.forEach(component -> {
+ if (component instanceof AbstractComponent) {
+ ((AbstractComponent) component).deconstruct();
+ } else if (component instanceof Provider) {
+ ((Provider<?>) component).deconstruct();
}
- };
+ });
Container container = newContainer(dirConfigSource, deconstructor);
@@ -376,11 +373,13 @@ public class ContainerTest extends ContainerTestBase {
public static class TestDeconstructor implements ComponentDeconstructor {
@Override
- public void deconstruct(Object component) {
- if (component instanceof DestructableComponent) {
- DestructableComponent vespaComponent = (DestructableComponent) component;
- vespaComponent.deconstruct();
- }
+ public void deconstruct(Collection<Object> components) {
+ components.forEach(component -> {
+ if (component instanceof DestructableComponent) {
+ DestructableComponent vespaComponent = (DestructableComponent) component;
+ vespaComponent.deconstruct();
+ }
+ });
}
}