aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2019-10-26 21:13:52 +0200
committergjoranv <gv@verizonmedia.com>2019-10-26 21:36:50 +0200
commit40395ff12dd52300db74ccf6503156eee45a262a (patch)
treeeed4b0212509f598febfccec42ebe7a42846a843 /container-disc
parent935cf534c4e775ec17feff0c62d0f587c064257b (diff)
Schedule deconstruct of all components with one call.
Diffstat (limited to 'container-disc')
-rw-r--r--container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java31
-rw-r--r--container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java9
2 files changed, 23 insertions, 17 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 4fe7a07e281..4920051cbee 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
@@ -9,6 +9,7 @@ import com.yahoo.jdisc.SharedResource;
import com.yahoo.log.LogLevel;
import java.time.Duration;
+import java.util.Collection;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -36,21 +37,23 @@ public class Deconstructor implements ComponentDeconstructor {
@Override
- public void deconstruct(Object component) {
- if (component instanceof AbstractComponent) {
- AbstractComponent abstractComponent = (AbstractComponent) component;
- if (abstractComponent.isDeconstructable()) {
- executor.schedule(new DestructComponentTask(abstractComponent), delay.getSeconds(), TimeUnit.SECONDS);
+ public void deconstruct(Collection<Object> components) {
+ for (var component : components) {
+ if (component instanceof AbstractComponent) {
+ AbstractComponent abstractComponent = (AbstractComponent) component;
+ if (abstractComponent.isDeconstructable()) {
+ executor.schedule(new DestructComponentTask(abstractComponent), delay.getSeconds(), TimeUnit.SECONDS);
+ }
+ } else if (component instanceof Provider) {
+ // TODO Providers should most likely be deconstructed similarily to AbstractComponent
+ log.info("Starting deconstruction of provider " + component);
+ ((Provider<?>) component).deconstruct();
+ log.info("Finished deconstruction of provider " + component);
+ } else if (component instanceof SharedResource) {
+ log.info("Releasing container reference to resource " + component);
+ // No need to delay release, as jdisc does ref-counting
+ ((SharedResource) component).release();
}
- } else if (component instanceof Provider) {
- // TODO Providers should most likely be deconstructed similarily to AbstractComponent
- log.info("Starting deconstruction of provider " + component);
- ((Provider<?>)component).deconstruct();
- log.info("Finished deconstruction of provider " + component);
- } else if (component instanceof SharedResource) {
- log.info("Releasing container reference to resource " + component);
- // No need to delay release, as jdisc does ref-counting
- ((SharedResource)component).release();
}
}
diff --git a/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java b/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
index ff61127f617..395b1aa7c44 100644
--- a/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
+++ b/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
@@ -8,6 +8,9 @@ import com.yahoo.jdisc.SharedResource;
import org.junit.Before;
import org.junit.Test;
+import java.util.Collections;
+
+import static java.util.Collections.singleton;
import static org.junit.Assert.assertTrue;
/**
@@ -25,7 +28,7 @@ public class DeconstructorTest {
public void require_abstract_component_destructed() throws InterruptedException {
TestAbstractComponent abstractComponent = new TestAbstractComponent();
// Done by executor, so it takes some time even with a 0 delay.
- deconstructor.deconstruct(abstractComponent);
+ deconstructor.deconstruct(singleton(abstractComponent));
int cnt = 0;
while (! abstractComponent.destructed && (cnt++ < 12000)) {
Thread.sleep(10);
@@ -36,14 +39,14 @@ public class DeconstructorTest {
@Test
public void require_provider_destructed() {
TestProvider provider = new TestProvider();
- deconstructor.deconstruct(provider);
+ deconstructor.deconstruct(singleton(provider));
assertTrue(provider.destructed);
}
@Test
public void require_shared_resource_released() {
TestSharedResource sharedResource = new TestSharedResource();
- deconstructor.deconstruct(sharedResource);
+ deconstructor.deconstruct(singleton(sharedResource));
assertTrue(sharedResource.released);
}