diff options
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/di/Container.java')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/di/Container.java | 14 |
1 files changed, 13 insertions, 1 deletions
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 b8bc5fc6c99..d800851c728 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 @@ -22,6 +22,7 @@ import org.osgi.framework.Bundle; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.List; @@ -81,7 +82,7 @@ public class Container { log.log(Level.WARNING, String.format( "Failed to construct graph for generation '%d' - scheduling partial graph for deconstruction", newGraph.generation()), e); - scheduleGraphForDeconstruction(newGraph); + deconstructFailedGraph(oldGraph, newGraph); throw e; } Runnable cleanupTask = createPreviousGraphDeconstructionTask(oldGraph, newGraph, obsoleteBundles); @@ -166,6 +167,17 @@ public class Container { }); } + private void deconstructFailedGraph(ComponentGraph currentGraph, ComponentGraph failedGraph) { + Set<Object> currentComponents = Collections.newSetFromMap(new IdentityHashMap<>(currentGraph.size())); + currentComponents.addAll(currentGraph.allConstructedComponentsAndProviders()); + + List<Object> unusedComponents = new ArrayList<>(); + for (Object component : failedGraph.allConstructedComponentsAndProviders()) { + if (!currentComponents.contains(component)) unusedComponents.add(component); + } + destructor.deconstruct(failedGraph.generation(), unusedComponents, List.of()); + } + private Runnable createPreviousGraphDeconstructionTask(ComponentGraph oldGraph, ComponentGraph newGraph, Collection<Bundle> obsoleteBundles) { |