diff options
author | Arnstein Ressem <aressem@gmail.com> | 2020-12-07 15:31:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 15:31:41 +0100 |
commit | 623ad7595b4d0685d969b4585bb73c272d7da033 (patch) | |
tree | ac2d6eb70cb4bc9b4423569538e5a164ec05d54e /container-di | |
parent | d27544dd87c1c3d2798a10c04f22b8ff91d3185d (diff) |
Revert "Always deconstruct in reverse creation order, including Provider objects"
Diffstat (limited to 'container-di')
6 files changed, 11 insertions, 24 deletions
diff --git a/container-di/abi-spec.json b/container-di/abi-spec.json index 02cc29cd07f..a9dda2ae224 100644 --- a/container-di/abi-spec.json +++ b/container-di/abi-spec.json @@ -1,16 +1,15 @@ { "com.yahoo.container.di.componentgraph.Provider": { "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.component.Deconstructable" - ], + "interfaces": [], "attributes": [ "public", "interface", "abstract" ], "methods": [ - "public abstract java.lang.Object get()" + "public abstract java.lang.Object get()", + "public abstract void deconstruct()" ], "fields": [] } 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 4e3881a6fe6..61497cf71bc 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 @@ -4,7 +4,6 @@ package com.yahoo.container.di; import org.osgi.framework.Bundle; import java.util.Collection; -import java.util.List; /** * @author gjoranv @@ -12,7 +11,6 @@ import java.util.List; */ public interface ComponentDeconstructor { - /** Deconstructs the given components in order, then the given bundles. */ - void deconstruct(List<Object> components, Collection<Bundle> bundles); + void deconstruct(Collection<Object> components, Collection<Bundle> bundles); } 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 7fc2f2e55bc..af580767a17 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 @@ -21,7 +21,6 @@ import com.yahoo.container.di.config.SubscriberFactory; import com.yahoo.vespa.config.ConfigKey; import org.osgi.framework.Bundle; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -160,16 +159,10 @@ public class Container { private void deconstructObsoleteComponents(ComponentGraph oldGraph, ComponentGraph newGraph, Collection<Bundle> obsoleteBundles) { - Map<Object, ?> newComponents = new IdentityHashMap<>(newGraph.size()); - for (Object component : newGraph.allConstructedComponentsAndProviders()) - newComponents.put(component, null); - - List<Object> obsoleteComponents = new ArrayList<>(); - for (Object component : oldGraph.allConstructedComponentsAndProviders()) - if ( ! newComponents.containsKey(component)) - obsoleteComponents.add(component); - - componentDeconstructor.deconstruct(obsoleteComponents, obsoleteBundles); + IdentityHashMap<Object, Object> oldComponents = new IdentityHashMap<>(); + oldGraph.allConstructedComponentsAndProviders().forEach(c -> oldComponents.put(c, null)); + newGraph.allConstructedComponentsAndProviders().forEach(oldComponents::remove); + componentDeconstructor.deconstruct(oldComponents.keySet(), obsoleteBundles); } private Set<Bundle> installApplicationBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) { diff --git a/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java b/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java index 3fd3195e5dd..a2d193654ea 100644 --- a/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java +++ b/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java @@ -1,8 +1,6 @@ // 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.componentgraph; -import com.yahoo.component.Deconstructable; - /** * <p>Provides a component of the parameter type T. * If (and only if) dependency injection does not have a component of type T, @@ -19,8 +17,9 @@ import com.yahoo.component.Deconstructable; * @author Tony Vaagenes * @author gjoranv */ -public interface Provider<T> extends Deconstructable { +public interface Provider<T> { T get(); + void deconstruct(); } 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 fef2809f236..256c965052a 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 @@ -166,7 +166,6 @@ public class ComponentGraph { } } - /** All constructed components and providers of this, in reverse creation order, i.e., suited for ordered deconstruction. */ public List<Object> allConstructedComponentsAndProviders() { List<Node> orderedNodes = topologicalSort(nodes()); Collections.reverse(orderedNodes); 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 d39e8a36aed..19f277ff8fb 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 @@ -19,7 +19,6 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import java.util.Collection; -import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -381,7 +380,7 @@ public class ContainerTest extends ContainerTestBase { public static class TestDeconstructor implements ComponentDeconstructor { @Override - public void deconstruct(List<Object> components, Collection<Bundle> bundles) { + public void deconstruct(Collection<Object> components, Collection<Bundle> bundles) { components.forEach(component -> { if (component instanceof DestructableComponent) { DestructableComponent vespaComponent = (DestructableComponent) component; |