summaryrefslogtreecommitdiffstats
path: root/container-di
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-07-06 22:22:17 +0200
committergjoranv <gv@verizonmedia.com>2020-07-08 12:23:33 +0200
commit3b7a09a474730eb24a9b26bf29a46b8778c95f7d (patch)
tree8da6b9f60fe5a79918db1c1a99c6379250514036 /container-di
parent5be1a06e462a1689cfdca61baffa7a58efe033c4 (diff)
Rearrange methods, no functional changes.
Diffstat (limited to 'container-di')
-rw-r--r--container-di/src/main/java/com/yahoo/container/di/Container.java95
1 files changed, 47 insertions, 48 deletions
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 027c9cdd354..3b75dc14fdb 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
@@ -82,50 +82,12 @@ public class Container {
}
}
- private void deconstructObsoleteComponents(ComponentGraph oldGraph,
- ComponentGraph newGraph,
- Collection<Bundle> 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 static String newGraphErrorMessage(long generation, Throwable cause) {
- String failedFirstMessage = "Failed to set up first component graph";
- String failedNewMessage = "Failed to set up new component graph";
- String constructMessage = " due to error when constructing one of the components";
- String retainMessage = ". Retaining previous component generation.";
-
- if (generation == 0) {
- if (cause instanceof ComponentNode.ComponentConstructorException) {
- return failedFirstMessage + constructMessage;
- } else {
- return failedFirstMessage;
- }
- } else {
- if (cause instanceof ComponentNode.ComponentConstructorException) {
- return failedNewMessage + constructMessage + retainMessage;
- } else {
- return failedNewMessage + retainMessage;
- }
- }
- }
-
- private void invalidateGeneration(long generation, Throwable cause) {
- leastGeneration = Math.max(configurer.getComponentsGeneration(), configurer.getBootstrapGeneration()) + 1;
- if (!(cause instanceof InterruptedException) && !(cause instanceof ConfigInterruptedException)) {
- log.log(Level.WARNING, newGraphErrorMessage(generation, cause), cause);
- }
- }
-
private ComponentGraph getConfigAndCreateGraph(ComponentGraph graph,
Injector fallbackInjector,
boolean restartOnRedeploy,
Collection<Bundle> obsoleteBundles) // NOTE: Return value
{
ConfigSnapshot snapshot;
-
while (true) {
snapshot = configurer.getConfigs(graph.configKeys(), leastGeneration, restartOnRedeploy);
@@ -178,15 +140,17 @@ public class Container {
return componentGraph;
}
- private void injectNodes(ComponentsConfig config, ComponentGraph graph) {
- for (ComponentsConfig.Components component : config.components()) {
- Node componentNode = ComponentGraph.getNode(graph, component.id());
+ private void constructComponents(ComponentGraph graph) {
+ graph.nodes().forEach(Node::constructInstance);
+ }
- for (ComponentsConfig.Components.Inject inject : component.inject()) {
- //TODO: Support inject.name()
- componentNode.inject(ComponentGraph.getNode(graph, inject.id()));
- }
- }
+ private void deconstructObsoleteComponents(ComponentGraph oldGraph,
+ ComponentGraph newGraph,
+ Collection<Bundle> 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> installBundles(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configsIncludingBootstrapConfigs) {
@@ -228,8 +192,43 @@ public class Container {
}
}
- private void constructComponents(ComponentGraph graph) {
- graph.nodes().forEach(Node::constructInstance);
+ private void injectNodes(ComponentsConfig config, ComponentGraph graph) {
+ for (ComponentsConfig.Components component : config.components()) {
+ Node componentNode = ComponentGraph.getNode(graph, component.id());
+
+ for (ComponentsConfig.Components.Inject inject : component.inject()) {
+ //TODO: Support inject.name()
+ componentNode.inject(ComponentGraph.getNode(graph, inject.id()));
+ }
+ }
+ }
+
+ private void invalidateGeneration(long generation, Throwable cause) {
+ leastGeneration = Math.max(configurer.getComponentsGeneration(), configurer.getBootstrapGeneration()) + 1;
+ if (!(cause instanceof InterruptedException) && !(cause instanceof ConfigInterruptedException)) {
+ log.log(Level.WARNING, newGraphErrorMessage(generation, cause), cause);
+ }
+ }
+
+ private static String newGraphErrorMessage(long generation, Throwable cause) {
+ String failedFirstMessage = "Failed to set up first component graph";
+ String failedNewMessage = "Failed to set up new component graph";
+ String constructMessage = " due to error when constructing one of the components";
+ String retainMessage = ". Retaining previous component generation.";
+
+ if (generation == 0) {
+ if (cause instanceof ComponentNode.ComponentConstructorException) {
+ return failedFirstMessage + constructMessage;
+ } else {
+ return failedFirstMessage;
+ }
+ } else {
+ if (cause instanceof ComponentNode.ComponentConstructorException) {
+ return failedNewMessage + constructMessage + retainMessage;
+ } else {
+ return failedNewMessage + retainMessage;
+ }
+ }
}
public void shutdown(ComponentGraph graph, ComponentDeconstructor deconstructor) {