summaryrefslogtreecommitdiffstats
path: root/jdisc_core
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-04-16 16:10:04 +0200
committerBjørn Christian Seime <bjorncs@oath.com>2018-04-16 16:12:11 +0200
commit072311cef68f7749e14bf424b350f8b555372cfe (patch)
tree416b0b396ca78f6329fef9ec638788c8e0aa75c3 /jdisc_core
parent80bf8ce667fe63af8c6034aa50a1a72b3c51ea02 (diff)
Remove finalizer() from ActiveContainer
Diffstat (limited to 'jdisc_core')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java53
1 files changed, 5 insertions, 48 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java
index 38fa91b4831..f1232259ced 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainer.java
@@ -1,4 +1,4 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;
import com.google.inject.AbstractModule;
@@ -17,8 +17,6 @@ import com.yahoo.jdisc.service.ServerProvider;
import java.net.URI;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.logging.Logger;
/**
* @author Simon Thoresen
@@ -26,8 +24,6 @@ import java.util.logging.Logger;
*/
public class ActiveContainer extends AbstractResource implements CurrentContainer {
- private static final Logger log = Logger.getLogger(ActiveContainer.class.getName());
-
private final ContainerTermination termination;
private final Injector guiceInjector;
private final Iterable<ServerProvider> serverProviders;
@@ -36,7 +32,6 @@ public class ActiveContainer extends AbstractResource implements CurrentContaine
private final Map<String, BindingSet<RequestHandler>> clientBindings;
private final BindingSetSelector bindingSetSelector;
private final TimeoutManagerImpl timeoutMgr;
- private final Destructor destructor;
public ActiveContainer(ContainerBuilder builder) {
serverProviders = builder.serverProviders().activate();
@@ -61,16 +56,14 @@ public class ActiveContainer extends AbstractResource implements CurrentContaine
});
guiceInjector = builder.guiceModules().activate();
termination = new ContainerTermination(builder.appContext());
- destructor = new Destructor(resourceReferences, timeoutMgr, termination);
}
@Override
protected void destroy() {
- boolean alreadyDestructed = destructor.destruct();
- if (alreadyDestructed) {
- throw new IllegalStateException(
- "Already destructed! This should not occur unless destroy have been called directly!");
- }
+ resourceReferences.release();
+ timeoutMgr.shutdown();
+ termination.run();
+ super.destroy();
}
/**
@@ -126,40 +119,4 @@ public class ActiveContainer extends AbstractResource implements CurrentContaine
return new ContainerSnapshot(this, serverBindings, clientBindings);
}
- // TODO Rewrite to use cleaners after Java 9 migration
- @Override
- protected void finalize() throws Throwable {
- boolean alreadyDestructed = destructor.destruct();
- if (!alreadyDestructed) {
- log.severe(toString() + " was not correctly cleaned up " +
- "because of a resource leak or invalid use of reference counting.");
- }
- super.finalize();
- }
-
- // NOTE: An instance of this class must never contain a reference to the outer class (ActiveContainer).
- private static class Destructor {
- private final ResourcePool resourceReferences;
- private final TimeoutManagerImpl timeoutMgr;
- private final ContainerTermination termination;
- private final AtomicBoolean done = new AtomicBoolean();
-
- private Destructor(ResourcePool resourceReferences,
- TimeoutManagerImpl timeoutMgr,
- ContainerTermination termination) {
- this.resourceReferences = resourceReferences;
- this.timeoutMgr = timeoutMgr;
- this.termination = termination;
- }
-
- boolean destruct() {
- boolean alreadyDestructed = this.done.getAndSet(true);
- if (!alreadyDestructed) {
- resourceReferences.release();
- timeoutMgr.shutdown();
- termination.run();
- }
- return alreadyDestructed;
- }
- }
}