diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-12-07 13:37:24 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-12-07 13:37:24 +0100 |
commit | bdb102917700d9f698423b5a1d62ead8a06f5b5a (patch) | |
tree | 1daacf13716d072b1a5578ae03fb35ae2e61a81f /container-disc/src/main | |
parent | c7548568b93ac5552667ca34a754bf6b36b5033e (diff) |
Always deconstruct in reverse creation order, including Provider objects
Diffstat (limited to 'container-disc/src/main')
-rw-r--r-- | container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java index e60e8d407cd..ec7d255aa0a 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java @@ -2,10 +2,13 @@ package com.yahoo.container.jdisc.component; import com.yahoo.component.AbstractComponent; +import com.yahoo.component.Deconstructable; import com.yahoo.concurrent.ThreadFactoryFactory; import com.yahoo.container.di.ComponentDeconstructor; import com.yahoo.container.di.componentgraph.Provider; import com.yahoo.jdisc.SharedResource; + +import java.util.List; import java.util.logging.Level; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -42,8 +45,8 @@ public class Deconstructor implements ComponentDeconstructor { } @Override - public void deconstruct(Collection<Object> components, Collection<Bundle> bundles) { - Collection<AbstractComponent> destructibleComponents = new ArrayList<>(); + public void deconstruct(List<Object> components, Collection<Bundle> bundles) { + Collection<Deconstructable> destructibleComponents = new ArrayList<>(); for (var component : components) { if (component instanceof AbstractComponent) { AbstractComponent abstractComponent = (AbstractComponent) component; @@ -51,10 +54,7 @@ public class Deconstructor implements ComponentDeconstructor { destructibleComponents.add(abstractComponent); } } else if (component instanceof Provider) { - // TODO Providers should most likely be deconstructed similarly to AbstractComponent - log.log(FINE, () -> "Starting deconstruction of provider " + component); - ((Provider<?>) component).deconstruct(); - log.log(FINE, () -> "Finished deconstruction of provider " + component); + destructibleComponents.add((Deconstructable) component); } else if (component instanceof SharedResource) { log.log(FINE, () -> "Releasing container reference to resource " + component); // No need to delay release, as jdisc does ref-counting @@ -69,10 +69,10 @@ public class Deconstructor implements ComponentDeconstructor { private static class DestructComponentTask implements Runnable { private final Random random = new Random(System.nanoTime()); - private final Collection<AbstractComponent> components; + private final Collection<Deconstructable> components; private final Collection<Bundle> bundles; - DestructComponentTask(Collection<AbstractComponent> components, Collection<Bundle> bundles) { + DestructComponentTask(Collection<Deconstructable> components, Collection<Bundle> bundles) { this.components = components; this.bundles = bundles; } @@ -89,10 +89,10 @@ public class Deconstructor implements ComponentDeconstructor { @Override public void run() { for (var component : components) { - log.log(FINE, () -> "Starting deconstruction of component " + component); + log.log(FINE, () -> "Starting deconstruction of " + component); try { component.deconstruct(); - log.log(FINE, () -> "Finished deconstructing of component " + component); + log.log(FINE, () -> "Finished deconstructing of " + component); } catch (Exception | NoClassDefFoundError e) { // May get class not found due to it being already unloaded log.log(WARNING, "Exception thrown when deconstructing component " + component, e); } catch (Error e) { |